Data query method, device and storage medium of distributed database

By establishing a mapping index between non-primary key fields and primary key fields in the Hbase database, the problem of inefficiency of traditional databases inability to implement multi-dimensional query and non-primary key field query is solved, and fast and efficient non-primary key field query is achieved.

CN111797134BActive Publication Date: 2025-02-18BEIJING XIAOMI PINECONE ELECTRONICS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010583096.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-23
Publication Date
2025-02-18
Estimated Expiration
2040-06-23

AI Technical Summary

Technical Problem

Traditional Hbase databases can only query based on primary key fields, and cannot implement multi-dimensional query. Querying non-primary key fields is low efficiency, wasting computing resources and resulting in delays.

Method used

When the data is written to a distributed database, a target index including the mapping relationship between the non-primary key fields and the primary key fields is established, and the non-primary key fields are quickly queried through the index.

Benefits of technology

It realizes the rapid query of non-primary key fields in a distributed database, improves query efficiency and reduces the waste of computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111797134B_ABST
    Figure CN111797134B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a data query method, device and storage medium of a distributed database, and relates to the field of electronic information technology. The method comprises: obtaining a query request, wherein the query request includes at least one query field and a query condition corresponding to each query field. If a target query field exists in the query request, according to a pre-established target index, a target key value of a primary key field matching the query condition corresponding to the target query field is queried, wherein the target query field is a designated non-primary key field, and the target index is an index established when data is written to the distributed database, and includes a mapping relationship between the designated non-primary key field and the primary key field. Target data whose primary key field is the target key value is retrieved from the distributed database, and the target data is used as a query result corresponding to the query request. The present disclosure can quickly query non-primary key fields in a distributed database through a pre-established target index, thereby improving query efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of electronic information technology, and in particular to a data query method, device and storage medium for a distributed database. Background Art

[0002] With the development of electronic information technologies such as the Internet and cloud computing, the amount of data has also exploded, and traditional databases can no longer meet the storage needs of massive data. Therefore, distributed databases (English: Distributed Data Base, abbreviated: DDB) are usually used to store massive data. For example, the Hbase database is a distributed, column-oriented open source database suitable for storing unstructured data. The way to read a row of data in the Hbase database is to use the primary key field (i.e., row key, English: Rowkey) that can uniquely identify a row of data.

[0003] In the related technology, the Hbase database only provides queries based on primary key fields. The primary key field has a single index and cannot implement multi-dimensional queries. For queries on non-primary key fields, they can only be performed through Filter or offline tasks, which not only wastes computing resources, but also causes delays and low query efficiency. Summary of the invention

[0004] In order to overcome the problems existing in the related art, the present disclosure provides a data query method, device and storage medium for a distributed database.

[0005] According to a first aspect of an embodiment of the present disclosure, a data query method for a distributed database is provided, the method comprising:

[0006] Obtaining a query request, wherein the query request includes at least one query field and a query condition corresponding to each query field;

[0007] If there is a target query field in the query request, query the target key value of the primary key field that matches the query condition corresponding to the target query field according to the pre-established target index; the target query field is a specified non-primary key field, and the target index is an index established when data is written into the distributed database, including the mapping relationship between the specified non-primary key field and the primary key field;

[0008] Target data whose primary key field is the target key value is retrieved from the distributed database, and the target data is used as a query result corresponding to the query request.

[0009] Optionally, the method further comprises:

[0010] Writing the first data into the distributed database;

[0011] If a target establishment field exists in the first data, obtaining a value of the target establishment field in the first data and a key value of a primary key field in the first data, wherein the target establishment field is a designated non-primary key field;

[0012] The value of the target establishment field in the first data and the key value of the primary key field in the first data are used as a mapping between the target establishment field and the primary key field, and are stored in the target index.

[0013] Optionally, the distributed database is an Hbase database, and writing the first data into the distributed database includes:

[0014] Writing the first data into the write-ahead log of the Hbase database;

[0015] If the target establishment field exists in the first data, obtaining the value of the target establishment field in the first data and the key value of the primary key field in the first data includes:

[0016] By means of the Replication mechanism, determining whether the target establishment field exists in the first data;

[0017] If a target establishment field exists in the first data, the value of the target establishment field in the first data and the key value of the primary key field in the first data are read from the write-ahead log.

[0018] Optionally, the using the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping of the target establishment field and the primary key field, and storing the mapping in the target index includes:

[0019] The value of the target establishment field in the first data and the key value of the primary key field in the first data are sent to the search server, so that the search server uses the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and stores them in the target index in the search server.

[0020] Optionally, querying a target key value of a primary key field that matches a query condition corresponding to the target query field according to a pre-established target index includes:

[0021] Sending the target query field and the query condition corresponding to the target query field to a search server storing the target index, so that the search server searches the target index for a target mapping that matches the query condition corresponding to the target query field;

[0022] The key value of the primary key field in the target mapping is obtained from the search server, and the key value of the primary key field in the target mapping is used as the target key value.

[0023] According to a second aspect of an embodiment of the present disclosure, a data query device for a distributed database is provided, the device comprising:

[0024] A first acquisition module is configured to acquire a query request, wherein the query request includes at least one query field and a query condition corresponding to each query field;

[0025] The query module is configured to query the target key value of the primary key field that matches the query condition corresponding to the target query field according to a pre-established target index if there is a target query field in the query request; the target query field is a specified non-primary key field, and the target index is an index established when data is written into the distributed database, including a mapping relationship between the specified non-primary key field and the primary key field;

[0026] The determination module is configured to retrieve target data whose primary key field is the target key value from the distributed database, and use the target data as the query result corresponding to the query request.

[0027] Optionally, the device further comprises:

[0028] A writing module, configured to write the first data into the distributed database;

[0029] A second acquisition module is configured to acquire a value of a target establishment field in the first data and a key value of a primary key field in the first data if there is a target establishment field in the first data, wherein the target establishment field is a designated non-primary key field;

[0030] The establishment module is configured to use the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and store them in the target index.

[0031] Optionally, the writing module is configured to:

[0032] Writing the first data into the write-ahead log of the Hbase database;

[0033] The second acquisition module includes:

[0034] A determination submodule is configured to determine whether the target establishment field exists in the first data through a Replication mechanism;

[0035] The acquisition submodule is configured to read the value of the target establishment field in the first data and the key value of the primary key field in the first data from the write-ahead log if the target establishment field exists in the first data.

[0036] Optionally, the establishing module is configured to:

[0037] The value of the target establishment field in the first data and the key value of the primary key field in the first data are sent to the search server, so that the search server uses the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and stores them in the target index in the search server.

[0038] Optionally, the query module includes:

[0039] a sending submodule configured to send the target query field and the query condition corresponding to the target query field to a search server storing the target index, so that the search server searches the target index for a target mapping that matches the query condition corresponding to the target query field;

[0040] The query submodule is configured to obtain the key value of the primary key field in the target mapping from the search server, and use the key value of the primary key field in the target mapping as the target key value.

[0041] According to a third aspect of an embodiment of the present disclosure, a data query device for a distributed database is provided, comprising:

[0042] processor;

[0043] a memory for storing processor-executable instructions;

[0044] Wherein, the processor is configured to:

[0045] Obtaining a query request, wherein the query request includes at least one query field and a query condition corresponding to each query field;

[0046] If there is a target query field in the query request, query the target key value of the primary key field that matches the query condition corresponding to the target query field according to the pre-established target index; the target query field is a specified non-primary key field, and the target index is an index established when data is written into the distributed database, including the mapping relationship between the specified non-primary key field and the primary key field;

[0047] Target data whose primary key field is the target key value is retrieved from the distributed database, and the target data is used as a query result corresponding to the query request.

[0048] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of the distributed database data query method provided in the first aspect of the present disclosure are implemented.

[0049] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:

[0050] The present disclosure first obtains a query request including at least one query field and query conditions corresponding to each query field. When a target query field exists in the query request, the target key value of the primary key field matching the query condition corresponding to the target query field is queried according to a pre-established target index, wherein the target query field is a specified non-primary key field, and the target index is an index established when data is written to a distributed database, including a mapping relationship between the specified non-primary key field and the primary key field. Finally, the target data with the primary key field as the target key value is determined from the distributed database, and is used as the query result corresponding to the query request. The present disclosure can quickly query non-primary key fields in a distributed database by pre-establishing a target index including a mapping relationship between non-primary key fields and primary key fields, thereby improving query efficiency.

[0051] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0053] Figure 1 is a flow chart of a data query method for a distributed database according to an exemplary embodiment;

[0054] Figure 2 is a flow chart showing another distributed database data query method according to an exemplary embodiment;

[0055] Figure 3 is a flow chart showing another distributed database data query method according to an exemplary embodiment;

[0056] Figure 4 is a flow chart showing another distributed database data query method according to an exemplary embodiment;

[0057] Figure 5 is a block diagram of a data query device for a distributed database according to an exemplary embodiment;

[0058] Figure 6 is a block diagram of another distributed database data query device according to an exemplary embodiment;

[0059] Figure 7 is a block diagram of another distributed database data query device according to an exemplary embodiment;

[0060] Figure 8 is a block diagram of another distributed database data query device according to an exemplary embodiment;

[0061] Fig. 9 The invention is a block diagram of a data query device for a distributed database according to an exemplary embodiment. DETAILED DESCRIPTION

[0062] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0063] Before introducing the data query method, device and storage medium of the distributed database provided by the present disclosure, the application scenarios involved in each embodiment of the present disclosure are first introduced. The application scenario may include a server and a terminal, and the terminal can communicate with the server through a wired network or a wireless network. A distributed database (for example, an Hbase database) is deployed on the server, which can receive a query request sent by the terminal and return the corresponding query result to the terminal. Among them, the server can be a local server, or a cloud server or a server cluster, and the present disclosure does not make specific restrictions on this. The terminal can be, for example, a mobile terminal such as a smart phone, a tablet computer, a smart TV, a smart watch, a PDA (English: Personal Digital Assistant, Chinese: Personal Digital Assistant), a portable computer, or a fixed terminal such as a desktop computer. It should be noted that the execution subject of each embodiment in the present disclosure can be the above-mentioned server.

[0064] Figure 1 is a flow chart of a data query method for a distributed database according to an exemplary embodiment. Figure 1 As shown, the method comprises the following steps:

[0065] In step 101, a query request is obtained, wherein the query request includes at least one query field and a query condition corresponding to each query field.

[0066] For example, when a user needs to search for data in a distributed database, a query request can be sent to a server through a terminal. The query request may include at least one query field that the user wants to query and the query conditions corresponding to each query field. For example, if a user needs to search for data in a distributed database whose gender is female and whose age is less than 35 years old, a query request can be sent to a server through a terminal. The query request includes two query fields: "gender" and "age". The query condition corresponding to "gender" is "female", and the query condition corresponding to "age" is "less than 35 years old". After receiving the query request, the server can first parse the query request to obtain each query field and the query conditions corresponding to each query field.

[0067] In step 102, if there is a target query field in the query request, the target key value of the primary key field that matches the query condition corresponding to the target query field is queried according to the pre-established target index. The target query field is a specified non-primary key field, and the target index is an index established when data is written to the distributed database, including the mapping relationship between the specified non-primary key field and the primary key field.

[0068] For example, it can be determined whether there is a non-primary key field in at least one query field included in the query request. Among them, in a distributed database, the primary key field is the row key (Rowkey), and the non-primary key field can be understood as other fields except the row key. If a query field in the query request is a primary key field, you can directly query in the distributed database according to the query condition corresponding to the query field, that is, query according to the primary key field to obtain the key value (which can be one or more) of the primary key field that matches the query condition corresponding to the query field, which can be recorded as the initial key value.

[0069] If there is a target query field in the query request, where the target query field is a specified non-primary key field, then the target key value of the primary key field that matches the query condition corresponding to the target query field can be queried based on the pre-established target index. The target key value can be one or more. The mapping relationship between the specified non-primary key field and the primary key field is stored in the target index. It can be understood that a large number of mappings are stored in the target index, and each mapping contains a specified non-primary key field, the value of the specified non-primary key field, and the key value corresponding to the primary key field corresponding to the specified non-primary key field. Therefore, the mapping containing the target query field in the target index can be queried first, and then the mapping that matches the query condition corresponding to the target query field can be filtered out from the mapping containing the target query field (that is, the value of the target query field contained in the mapping satisfies the corresponding query condition), and the key value corresponding to the primary key field contained in the filtered mapping is used as the target key value.

[0070] It should be noted that the designated non-primary key field can be one or more. For example, the designated non-primary key field can be pre-designated by the user when creating or modifying a table in a distributed database. There are 100 fields in a certain table, among which field A is the primary key field. The user believes that in addition to the primary key field, field B and field C will also be frequently queried, so field B and field C can be set as designated non-primary key fields. It is also possible to perform statistical analysis on the user's query behavior and use the fields that the user frequently queries as designated non-primary key fields, and the present disclosure does not make specific limitations on this. The target index can be understood as, whenever data is written to a distributed database, if the data to be written includes the designated non-primary key field, then the mapping relationship between the designated non-primary key field and the primary key field in the data to be written can be stored in the target index to establish the target index, which can also be understood as updating the existing target index, so that the mapping relationship between the designated non-primary key field and the primary key field is stored in the target index.

[0071] In step 103, target data whose primary key field is a target key value is retrieved from the distributed database, and the target data is used as a query result corresponding to the query request.

[0072] For example, according to the target key value, the data whose primary key field is the target key value can be taken out from the distributed database as the target data, and then the target data can be used as the query result corresponding to the query request. It should be noted that, when the query request includes only one query field, and the query field is the target query field (i.e., the specified non-primary key field), the target data whose primary key field is the target key value can be directly used as the query result. When the query request includes multiple query fields, and the multiple query fields are all target query fields, then in step 102, the target key value corresponding to each target query field can be determined, and then the target key value corresponding to each target query field can be intersected, that is, the repeated target key value (which can be one or more) in the target key value corresponding to each target query field is determined, and then according to the repeated target key value, the target data whose primary key field is the repeated target key value is taken out from the distributed database and used as the query result. In the case where a query request includes multiple query fields, and one of the multiple query fields is a primary key field, and the other query fields are target query fields, you can first query in the distributed database according to the query conditions corresponding to the primary key field to obtain the key value of the primary key field that matches the corresponding query conditions, that is, the initial key value mentioned above. Then, determine the target key values ​​corresponding to the other target query fields through step 102, and then take the intersection of the target key value corresponding to each target query field and the initial key value, that is, determine the target key value corresponding to each target query field and the repeated key value (which can be one or more) in the initial key value. Then, based on the repeated key value, take out the data with the repeated key value of the primary key field from the distributed database and use it as the query result.

[0073] In summary, the present disclosure first obtains a query request including at least one query field and query conditions corresponding to each query field. When a target query field exists in the query request, the target key value of the primary key field that matches the query condition corresponding to the target query field is queried according to a pre-established target index, wherein the target query field is a specified non-primary key field, and the target index is an index established when data is written to a distributed database, including a mapping relationship between the specified non-primary key field and the primary key field. Finally, the target data with the primary key field as the target key value is determined from the distributed database, and is used as the query result corresponding to the query request. The present disclosure can quickly query non-primary key fields in a distributed database through a pre-established target index including a mapping relationship between non-primary key fields and primary key fields, thereby improving query efficiency.

[0074] Figure 2 FIG. 1 is a flow chart showing another distributed database data query method according to an exemplary embodiment. Figure 2 As shown, the method may also include the following steps:

[0075] In step 104, the first data is written into the distributed database.

[0076] In step 105, if the target establishment field exists in the first data, the value of the target establishment field in the first data and the key value of the primary key field in the first data are obtained, and the target establishment field is a designated non-primary key field.

[0077] In step 106, the value of the target creation field in the first data and the key value of the primary key field in the first data are used as a mapping between the target creation field and the primary key field, and are stored in the target index.

[0078] In one implementation, the target index may be established when new data to be written is written into a distributed database. Taking the new data to be written as the first data as an example, the first data is first written into the distributed database, for example, it can be written into the write ahead log (WAL) of the distributed database. At the same time, it is determined whether there is a target establishment field in the first data, wherein the target establishment field is a field in the first data that belongs to a specified non-primary key field. If there is a target establishment field in the first data, then the value of the target establishment field in the first data and the key value of the primary key field in the first data are obtained, and then the value of the target establishment field in the first data and the key value of the primary key field in the first data are used as a mapping of the target establishment field and the primary key field, and stored in the target index to establish the target index, which can also be understood as updating the existing target index.

[0079] Figure 3 FIG. 1 is a flow chart showing another method for querying data in a distributed database according to an exemplary embodiment. Figure 3 As shown, the distributed database may be an Hbase database.

[0080] Step 104 may be implemented as follows:

[0081] The first data is written into the write-ahead log of the Hbase database.

[0082] Accordingly, step 105 can be implemented in the following manner:

[0083] In step 1051, a determination is made through the Replication mechanism whether a target establishment field exists in the first data.

[0084] In step 1052, if the target establishment field exists in the first data, the value of the target establishment field in the first data and the key value of the primary key field in the first data are read from the write-ahead log.

[0085] For example, for the Hbase database, two mechanisms can be used to establish a target index (or update an existing target index): the Corprocessor mechanism and the Replication mechanism. Taking the Corprocessor mechanism as an example, before writing the first data to the write-ahead log of the Hbase database, first determine whether there is a target establishment field in the first data. If there is a target establishment field in the first data, obtain the value of the target establishment field in the first data and the key value of the primary key field in the first data, thereby establishing the target index and writing the first data to the write-ahead log. It can be understood that in the Corprocessor mechanism, establishing the target index and writing the first data to the write-ahead log are synchronized. Both operations must return success to complete the establishment of the target index and the writing of the first data. If any of the operations (establishing the target index or writing the first data to the write-ahead log) returns failure, then the update of the target index and the writing of the first data cannot be completed.

[0086] If the Replication mechanism is used, the first data can be first written into the pre-write log of the Hbase database, and then the first data can be read from the pre-write log through the Replication mechanism to determine whether there is a target establishment field in the first data. For example, a filter condition can be added to the Replication configuration to determine whether there is a target establishment field in the first data. If there is a target establishment field in the first data, the value of the target establishment field in the first data is read from the pre-write log through the Replication mechanism, and the key value of the primary key field in the first data is used to establish the target index. It can be understood that in the Replication mechanism, the establishment of the target index and the writing of the first data into the pre-write log are asynchronous, and whether the target index is successfully established will not affect the writing of the first data, thereby ensuring the reliability of the Hbase database.

[0087] In one implementation, step 106 may be implemented as follows:

[0088] The value of the target establishment field in the first data and the key value of the primary key field in the first data are sent to the search server, so that the search server uses the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and stores them in the target index in the search server.

[0089] For example, a specific implementation method for establishing a target index may be that a server deploying a distributed database first sends the value of a target establishment field in the first data and the key value of a primary key field in the first data to a search server, so that the search server uses the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping of the target establishment field and the primary key field, and stores the mapping in the target index stored in the search server. The search server may be understood as any search engine capable of establishing an inverted index, such as ApacheSolr, ElasticSearch, IndexTank, Katta, Compass, Summa, and other open source search engines, which are not specifically limited in this disclosure.

[0090] Figure 4 FIG. 1 is a flow chart showing another distributed database data query method according to an exemplary embodiment. Figure 4 As shown, the implementation of step 102 may include:

[0091] In step 1021, the target query field and the query condition corresponding to the target query field are sent to a search server storing a target index, so that the search server searches the target index for a target mapping that matches the query condition corresponding to the target query field.

[0092] In step 1022, the key value of the primary key field in the target mapping is obtained from the search server, and the key value of the primary key field in the target mapping is used as the target key value.

[0093] In one implementation, according to the target index, the target key value can be searched by a server that deploys a distributed database, and the target query field and the query condition corresponding to the target query field can be first sent to the search server that stores the target index. Then the search server completes the operation of searching for the target key value. Taking the search server as ElasticSearch (hereinafter referred to as ES) as an example, first, ES queries the mapping containing the target query field in the target index. Then, from the mapping containing the target query field, the target mapping that matches the query condition corresponding to the target query field is screened out, that is, the value of the target query field contained in the target mapping satisfies the corresponding query condition. Finally, ES can actively send the key value of the primary key field in the target mapping to the server that deploys the distributed database, or the server can actively obtain the key value of the primary key field in the target mapping from ES. After obtaining the key value of the primary key field in the target mapping, the server uses the key value of the primary key field in the target mapping as the target key value.

[0094] In summary, the present disclosure first obtains a query request including at least one query field and query conditions corresponding to each query field. When a target query field exists in the query request, the target key value of the primary key field that matches the query condition corresponding to the target query field is queried according to a pre-established target index, wherein the target query field is a specified non-primary key field, and the target index is an index established when data is written to a distributed database, including a mapping relationship between the specified non-primary key field and the primary key field. Finally, the target data with the primary key field as the target key value is determined from the distributed database, and is used as the query result corresponding to the query request. The present disclosure can quickly query non-primary key fields in a distributed database through a pre-established target index including a mapping relationship between non-primary key fields and primary key fields, thereby improving query efficiency.

[0095] Figure 5 is a block diagram of a data query device for a distributed database according to an exemplary embodiment. Figure 5 As shown, the device 200 includes:

[0096] The first acquisition module 201 is configured to acquire a query request, where the query request includes at least one query field and a query condition corresponding to each query field.

[0097] The query module 202 is configured to query the target key value of the primary key field that matches the query condition corresponding to the target query field according to the pre-established target index if there is a target query field in the query request. The target query field is a specified non-primary key field, and the target index is an index established when data is written to the distributed database, including the mapping relationship between the specified non-primary key field and the primary key field.

[0098] The determination module 203 is configured to retrieve target data whose primary key field is a target key value from the distributed database, and use the target data as a query result corresponding to the query request.

[0099] Figure 6 is a block diagram of another distributed database data query device according to an exemplary embodiment. Figure 6 As shown, the device 200 also includes:

[0100] The writing module 204 is configured to write the first data into the distributed database.

[0101] The second acquisition module 205 is configured to obtain the value of the target establishment field in the first data and the key value of the primary key field in the first data if the target establishment field exists in the first data, and the target establishment field is a specified non-primary key field.

[0102] The establishment module 206 is configured to use the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and store them in the target index.

[0103] Figure 7 is a block diagram of another distributed database data query device according to an exemplary embodiment. Figure 7 As shown, the writing module 204 is configured as follows:

[0104] The first data is written into the write-ahead log of the Hbase database.

[0105] The second acquisition module 205 includes:

[0106] The determination submodule 2051 is configured to determine whether there is a target establishment field in the first data through the Replication mechanism.

[0107] The acquisition submodule 2052 is configured to read the value of the target establishment field in the first data and the key value of the primary key field in the first data from the write-ahead log if the target establishment field exists in the first data.

[0108] In one implementation, the establishing module 206 is configured to:

[0109] The value of the target establishment field in the first data and the key value of the primary key field in the first data are sent to the search server, so that the search server uses the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and stores them in the target index in the search server.

[0110] Figure 8 is a block diagram of another distributed database data query device according to an exemplary embodiment. Figure 8 As shown, the query module 202 includes:

[0111] The sending submodule 2021 is configured to send the target query field and the query condition corresponding to the target query field to a search server storing a target index, so that the search server searches the target index for a target mapping that matches the query condition corresponding to the target query field.

[0112] The query submodule 2022 is configured to obtain the key value of the primary key field in the target mapping from the search server, and use the key value of the primary key field in the target mapping as the target key value.

[0113] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0114] In summary, the present disclosure first obtains a query request including at least one query field and query conditions corresponding to each query field. When a target query field exists in the query request, the target key value of the primary key field that matches the query condition corresponding to the target query field is queried according to a pre-established target index, wherein the target query field is a specified non-primary key field, and the target index is an index established when data is written to a distributed database, including a mapping relationship between the specified non-primary key field and the primary key field. Finally, the target data with the primary key field as the target key value is determined from the distributed database, and is used as the query result corresponding to the query request. The present disclosure can quickly query non-primary key fields in a distributed database through a pre-established target index including a mapping relationship between non-primary key fields and primary key fields, thereby improving query efficiency.

[0115] The present disclosure also provides a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, implements the steps of the distributed database data query method provided by the present disclosure.

[0116] Fig. 9 1 is a block diagram of a data query device 1900 for a distributed database according to an exemplary embodiment. For example, the device 1900 may be provided as a server. Fig. 9 , the device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above-mentioned distributed database data query method.

[0117] The device 1900 may also include a power supply component 1926 configured to perform power management of the device 1900, a wired or wireless network interface 1950 configured to connect the device 1900 to a network, and an input / output (I / O) interface 1958. The device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server 2000. TM , MacOS X TM , Unix TM , Linux TM , FreeBSD TM or similar.

[0118] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program that can be executed by a programmable device. The computer program has a code portion for executing the above-mentioned distributed database data query method when executed by the programmable device.

[0119] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the present disclosure. This application is intended to cover any variations, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0120] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A data query method for a distributed database, characterized in that: The method comprises: Obtaining a query request, wherein the query request includes at least one query field and a query condition corresponding to each query field; If there is a target query field in the query request, query the target key value of the primary key field that matches the query condition corresponding to the target query field according to the pre-established target index; the target query field is a specified non-primary key field, and the target index is an index established when data is written into the distributed database, including the mapping relationship between the specified non-primary key field and the primary key field; fetching target data whose primary key field is the target key value from the distributed database, and using the target data as the query result corresponding to the query request; The method further comprises: Writing the first data into the distributed database; If a target establishment field exists in the first data, obtaining a value of the target establishment field in the first data and a key value of a primary key field in the first data, wherein the target establishment field is a designated non-primary key field; Using the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and storing the mapping in the target index; The distributed database is an Hbase database, and writing the first data into the distributed database includes: Writing the first data into the write-ahead log of the Hbase database; If the target establishment field exists in the first data, obtaining the value of the target establishment field in the first data and the key value of the primary key field in the first data includes: By means of the Replication mechanism, determining whether the target establishment field exists in the first data; If a target establishment field exists in the first data, read the value of the target establishment field in the first data and the key value of the primary key field in the first data from the write-ahead log; The step of using the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and storing the mapping in the target index includes: The value of the target establishment field in the first data and the key value of the primary key field in the first data are sent to the search server, so that the search server uses the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and stores them in the target index in the search server.

2. The method according to claim 1, characterized in that The step of searching, according to the pre-established target index, for a target key value of a primary key field that matches a query condition corresponding to the target query field comprises: Sending the target query field and the query condition corresponding to the target query field to a search server storing the target index, so that the search server searches the target index for a target mapping that matches the query condition corresponding to the target query field; The key value of the primary key field in the target mapping is obtained from the search server, and the key value of the primary key field in the target mapping is used as the target key value.

3. A data query device for a distributed database, characterized in that: The device comprises: A first acquisition module is configured to acquire a query request, wherein the query request includes at least one query field and a query condition corresponding to each query field; The query module is configured to query the target key value of the primary key field that matches the query condition corresponding to the target query field according to a pre-established target index if there is a target query field in the query request; the target query field is a specified non-primary key field, and the target index is an index established when data is written into the distributed database, including a mapping relationship between the specified non-primary key field and the primary key field; A determination module is configured to retrieve target data whose primary key field is the target key value from the distributed database, and use the target data as a query result corresponding to the query request; A writing module, configured to write the first data into the distributed database; A second acquisition module is configured to acquire a value of a target establishment field in the first data and a key value of a primary key field in the first data if there is a target establishment field in the first data, wherein the target establishment field is a designated non-primary key field; A creation module, configured to use the value of the target creation field in the first data and the key value of the primary key field in the first data as a mapping between the target creation field and the primary key field, and store the mapping in the target index; The writing module is configured as follows: Writing the first data into the write-ahead log of the Hbase database; The second acquisition module includes: A determination submodule is configured to determine whether the target establishment field exists in the first data through a Replication mechanism; an acquisition submodule, configured to read, if a target establishment field exists in the first data, a value of the target establishment field in the first data and a key value of a primary key field in the first data from the write-ahead log; The establishment module is configured to send the value of the target establishment field in the first data and the key value of the primary key field in the first data to the search server, so that the search server uses the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and stores them in the target index in the search server.

4. A data query device for a distributed database, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to: Obtaining a query request, wherein the query request includes at least one query field and a query condition corresponding to each query field; If there is a target query field in the query request, query the target key value of the primary key field that matches the query condition corresponding to the target query field according to the pre-established target index; the target query field is a specified non-primary key field, and the target index is an index established when data is written into the distributed database, including the mapping relationship between the specified non-primary key field and the primary key field; fetching target data whose primary key field is the target key value from the distributed database, and using the target data as the query result corresponding to the query request; Writing the first data into the distributed database; If a target establishment field exists in the first data, obtaining a value of the target establishment field in the first data and a key value of a primary key field in the first data, wherein the target establishment field is a designated non-primary key field; Using the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and storing the mapping in the target index; The distributed database is an Hbase database, and writing the first data into the distributed database includes: Writing the first data into the write-ahead log of the Hbase database; If the target establishment field exists in the first data, obtaining the value of the target establishment field in the first data and the key value of the primary key field in the first data includes: By means of the Replication mechanism, determining whether the target establishment field exists in the first data; If a target establishment field exists in the first data, read the value of the target establishment field in the first data and the key value of the primary key field in the first data from the write-ahead log; The step of using the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and storing the mapping in the target index includes: The value of the target establishment field in the first data and the key value of the primary key field in the first data are sent to the search server, so that the search server uses the value of the target establishment field in the first data and the key value of the primary key field in the first data as a mapping between the target establishment field and the primary key field, and stores them in the target index in the search server.

5. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the steps of the method according to claim 1 or 2 are implemented.

Citation Information

Patent Citations

  • Methods for establishing and inquiring index of distributed column storage database, device and system thereof

    CN101727465A