A data query method, device, equipment and medium

CN117807113BActive Publication Date: 2026-10-13NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410029113.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-08
Publication Date
2026-10-13
Estimated Expiration
2044-01-08

AI Technical Summary

Technical Problem

[0004]有鉴于此,本申请的目的在于提供一种数据查询方法、装置、设备及介质,以解决现有技术中,数据查询效率低的问题

Benefits of technology

[0029]本申请实施例提供的一种数据查询方法、装置、设备及介质,能够将一条数据库查询语句拆分为多个查询子语句,并构造每个查询子语句对应的字符串组,通过字符串组的匹配确定未被查询过的数据,通过重新生成的重组查询语句从数据库中查询出未被查询过的数据,并将未被查询过的数据存储在缓存中,将未被查询过的数据转换为已查询数据,以便于下次查询时可直接使用缓存中存储的已查询数据,提高数据查询效率,与现有技术中的数据查询方法相比,解决了数据查询效率低的问题。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117807113B_ABST
    Figure CN117807113B_ABST
Patent Text Reader

Abstract

The application provides a data query method, device, equipment and medium. The method comprises the following steps: splitting a database query statement according to a field dimension to obtain a plurality of query sub-statements; for each query sub-statement, constructing a corresponding string group of the query sub-statement according to a table name, a query condition and a query field of the query sub-statement, and determining whether a target string group completely matching the string group exists in a cache; if not, recombining all query sub-statements without completely matching target strings to generate a recombined query statement, obtaining a database query result corresponding to the recombined query statement from a database, and storing the database query result and the string group in the cache in association; and obtaining a final data query result of the database query statement according to the database query result. The above data query method, device, equipment and medium solve the problem of low data query efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and more specifically, to a data query method, apparatus, device, and medium. Background Technology

[0002] When performing data queries on a database, a persistent connection needs to be established. However, database resources are limited, including the number of connections, CPU, and memory. Frequent data queries increase the processing pressure on the database. Storing the retrieved data in a cache and prioritizing its use during business operations can improve response speed and reduce database processing load. This is especially true for exact match queries, where high-frequency cache hits can deliver significant performance improvements. Traditional exact match queries typically operate on a method-by-method basis, storing the retrieved data in the cache.

[0003] However, in traditional data query methods, different database query statements cannot reuse existing data in the cache. For example, data query statement A performs an exact query on the data with ID 1 in the "Name" field to obtain query result 'a', and puts query result 'a' into the cache. When data query statement B queries the data with the same ID 1 in both the "Name" and "Age" fields, although query result 'a' already exists in the cache, it cannot be reused. Data query statement B needs to be used to perform a complete re-query of the database, resulting in low data query efficiency. Summary of the Invention

[0004] In view of this, the purpose of this application is to provide a data query method, apparatus, device and medium to solve the problem of low data query efficiency in the prior art.

[0005] In a first aspect, embodiments of this application provide a data query method, including:

[0006] The database query statement is split according to the field dimension to obtain multiple query sub-statements. Each query sub-statement includes the table name, query conditions and query fields.

[0007] For each query sub-statement, construct a string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, and determine whether there is a target string group in the cache that completely matches the string group;

[0008] If it does not exist, reorganize all query sub-statements that do not have a complete match for the target string to generate a reorganized query statement, retrieve the database query results corresponding to the reorganized query statement from the database, and store the database query results in the cache in association with the string group;

[0009] Based on the database query results, obtain the final data query results of the database query statement.

[0010] Optionally, constructing a string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement includes: determining whether the string length of the query conditions is greater than a set length threshold; if the string length is greater than the set length threshold, converting the query conditions into encrypted values ​​of a preset length; and concatenating the table name, query fields, and encrypted values ​​together using a preset separator symbol to obtain a string group.

[0011] Optionally, after constructing the string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, the method further includes: for each string group, determining whether there is a character index in the cache that matches the string group; if there is no character index that matches the string group, constructing a character index for the string group using the table name corresponding to the string group as the first-level index, the query conditions corresponding to the string group as the second-level index, and the query fields corresponding to the string group as the third-level index.

[0012] Optionally, the query conditions include multiple subquery conditions, and there are logical operation relationships between the multiple subquery conditions. Constructing a character index for the string group includes: determining the logical operation relationships between the multiple subquery conditions; if it is a logical OR, then creating a second-level index for the multiple subquery conditions in the form of different branches; if it is a logical AND, then creating a second-level index for the multiple subquery conditions in the form of different sub-levels under the same branch according to the field name order.

[0013] Optionally, the method further includes: parsing the database operation log during database updates to obtain update information of the updated data, including update type, first update information, and second update information, wherein the first update information is the update information when the updated data is modified, and the second update information is the update information when the updated data is deleted; if the update type is modification, determining the target string group when the updated data is modified based on the first update information; if the update type is deletion, determining the target string group when the updated data is deleted based on the second update information; and deleting the target string group, the cached value corresponding to the target string group, and the character index corresponding to the target string group from the cache.

[0014] Optionally, the first update information includes the first table name, the first target field, the data to be updated, the updated data of the data to be updated, and the value of the first field. The value of the first field is the updated value of all fields in the row containing the data to be updated, excluding the field containing the data to be updated. The first target field is the field containing the data to be updated. Based on the first update information, the target string group when modifying the data to be updated is determined, including: using the combination of the first target field and the data to be updated, the combination of the first target field and the updated data, and the value of the first field as the first update conditions respectively; determining whether there is a target first-level index in the cache that matches the first table name; if there is a matching target first-level index, under the target first-level index, for each first update condition, determining whether there is a target second-level index in the cache that matches the first update condition; if there is a matching target second-level index, under the target second-level index, determining whether there is a target third-level index in the cache that matches the first target field; if there is a matching target third-level index, using the string group corresponding to the target third-level index as the target string group.

[0015] Optionally, the second update information includes the name of the second table and the value of the second field, where the value of the second field is the value of all fields in the row containing the deleted data. Based on the second update information, the target string group for deleting the updated data is determined, including: treating each second field value as a second update condition; determining whether a target first-level index matching the name of the second table exists in the cache; if a matching target first-level index exists, under the target first-level index, for each second update condition, determining whether a target second-level index matching that second update condition exists in the cache; if a matching target second-level index exists, under the target second-level index, determining whether a target third-level index matching the second target field exists in the cache; if a matching target third-level index exists, the string group corresponding to the target third-level index is taken as the target string group.

[0016] Optionally, all query sub-statements that do not have a completely matching target string are reorganized to generate a reorganized query statement, including: taking the query sub-statements that do not have a completely matching target string as query sub-statements to be reorganized; for each query sub-statement to be reorganized, extracting the table name, query conditions, and query fields from the query sub-statement to be reorganized; reorganizing the table names, query conditions, and query fields corresponding to multiple query sub-statements to be reorganized, and obtaining a reorganized query statement based on the reorganized table names, query conditions, and query fields.

[0017] Optionally, the database query result includes multiple database query sub-results, each database query sub-result corresponding to a query sub-statement, and the database query result is associated with a string group and stored in the cache, including: for each database query sub-result, storing the string group corresponding to the database query sub-result and the database query sub-result in the form of key-value pairs in the cache.

[0018] Optionally, after determining whether a target string group that completely matches the string group exists in the cache, the method further includes: if a target string group that completely matches the string group exists, using the cached value corresponding to the target string group as the cache query result.

[0019] Optionally, based on the database query results, the final data query result of the database query statement can be obtained, including: combining the database query result with the cached query result to obtain the final data query result.

[0020] Optionally, after determining whether the string length of the query condition is greater than the set length threshold, the method further includes: if the string length is less than or equal to the set length threshold, then the table name, query field and query condition are directly concatenated together using a preset separator symbol to obtain a string group.

[0021] Secondly, embodiments of this application also provide a data query device, the device comprising:

[0022] The statement splitting module is used to split database query statements according to field dimensions to obtain multiple query sub-statements. Each query sub-statement includes the table name, query conditions, and query fields.

[0023] The string group construction module is used to construct a string group corresponding to each query sub-statement based on the table name, query conditions and query fields of the query sub-statement, and to determine whether there is a target string group in the cache that completely matches the string group.

[0024] The database query module is used to reorganize all query sub-statements that do not have a complete match for the target string if it does not exist, generate a reorganized query statement, retrieve the database query results corresponding to the reorganized query statement from the database, and store the database query results in the cache along with the string group.

[0025] The result determination module is used to obtain the final data query result of the database query statement based on the database query results.

[0026] Thirdly, embodiments of this application also provide an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, the steps of the data query method described above are performed.

[0027] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the data query method described above.

[0028] The embodiments of this application bring the following beneficial effects:

[0029] This application provides a data query method, apparatus, device, and medium that can split a database query statement into multiple query sub-statements, construct a string group corresponding to each query sub-statement, determine unqueried data by matching the string groups, retrieve the unqueried data from the database by regenerating and recombining the query statement, store the unqueried data in a cache, and convert the unqueried data into queried data so that the queried data stored in the cache can be directly used in the next query, thereby improving data query efficiency. Compared with the data query methods in the prior art, this solves the problem of low data query efficiency.

[0030] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0031] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0032] Figure 1 A flowchart of the data query method provided in an embodiment of this application is shown;

[0033] Figure 2 A schematic diagram of the target string group search process provided in an embodiment of this application is shown;

[0034] Figure 3 A schematic diagram of the data query device provided in an embodiment of this application is shown;

[0035] Figure 4 A schematic diagram of the structure of the electronic device provided in the embodiments of this application is shown. Detailed Implementation

[0036] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. Based on the embodiments of this application, every other embodiment obtained by those skilled in the art without inventive effort falls within the scope of protection of this application.

[0037] To facilitate understanding of this application, the following explanations are provided for some of the terms used in this application:

[0038] Exact Query: Database query methods are divided into exact query and fuzzy query. Exact query refers to using the WHERE statement to accurately query data that meets the conditions. For example, an exact query statement can be SELECT * FROM customers WHERE customer_id=12345. This query statement will return all rows in the customers table where customer_id is equal to 12345.

[0039] It is worth noting that prior to this application, in precise queries, traditional methods of caching database query data, such as the @Cacheable annotation in the Spring framework, typically store the queried data in the cache as key-value pairs on a method-by-method basis. The key is a unique string determined by the attributes related to the query method (such as the method name, method parameters, etc.), and the value is the serialized result of the queried data (which is usually also a string).

[0040] To facilitate understanding, let's take a traditional data query method as an example (using MySQL, the most commonly used database in development). Suppose there's a table in the database named "Car," with four locations: id, name, price, and brand. Currently, there's no cached data. If we want to query and cache the data in the name and price fields of the "Car" table based on the id, the traditional data query method requires defining a query method first. In Java, this query method could be defined as `Car findCarNamePriceById(Long id)`, with caching functionality added (e.g., using the `@Cacheable` annotation in the Spring framework). When this method is called, it first generates the key "Car:findCarNamePriceById:{id}", checks if the data already exists in the cache, and if not, generates a new query to retrieve the data from the database. After obtaining the corresponding query data, cached data ("Car:findCarNamePriceById:{id}","{car}") will be generated. When the query method is called again with the same id parameter, the cache will be checked first. If the corresponding cached data is found, "{car}" will be retrieved and converted into the data "car".

[0041] If you want to query and cache the name, price, and brand fields in Car based on the id, you need to define another query method, such as Car findCarNamePriceBrandById(Long id), and add caching functionality to this query method. When this new query method is called, since it is a different method from findCarNamePriceById, the generated key is also different, which makes it impossible to reuse the cached data generated by the findCarNamePriceById method.

[0042] Furthermore, when deleting cached data, traditional data query methods based on exact queries require defining a cache deletion method. These cache deletion methods typically correspond one-to-one with the data query methods that used the cache; that is, there is as many cache deletion methods as there are data query methods. After each data query, a cache deletion method still needs to be defined to remove the cached data, which also leads to low data query efficiency.

[0043] Based on this, embodiments of this application provide a data query method to improve data query efficiency.

[0044] Please see Figure 1 , Figure 1 This is a flowchart illustrating a data query method provided in an embodiment of this application. Figure 1 As shown in the embodiments of this application, the data query method includes:

[0045] Step S101: Split the database query statement according to the field dimension to obtain multiple query sub-statements. Each query sub-statement includes the table name, query conditions, and query fields.

[0046] Step S102: For each query sub-statement, construct a string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, and determine whether there is a target string group in the cache that completely matches the string group.

[0047] Step S103: If no match exists, reorganize all query sub-statements that do not have a complete match for the target string to generate a reorganized query statement, retrieve the database query result corresponding to the reorganized query statement from the database, and associate the database query result with the string group and store it in the cache.

[0048] Step S104: Obtain the final data query result of the database query statement based on the database query result.

[0049] In step S101, the database query statement is a program statement that queries the stored data in the database. For example, the database query statement can be an SQL statement. The database being queried can be a relational database or a non-relational database.

[0050] A database query statement includes the table name, query fields, and query conditions. The table name is the name of the data table containing the data being queried; the query fields are the names of the fields containing the data being queried; and the query conditions are the filtering conditions used to select the data being queried from the query fields.

[0051] In this embodiment, after receiving a data query request, a database query statement is generated. The database query statement is then parsed to obtain the table name, query conditions, and query fields. The database query statement can contain one or more query fields. For example, the database query statement `select name,price from Car where id=1` has two query fields: `name` and `price`. The query result can be considered a combination of the results of two sub-queries: `select name from Car where id=1` and `select price from Car where id=1`. Therefore, to reuse data already stored in the cache, the database query statement can be split according to the field dimension before data querying, resulting in two sub-queries: `select name from Car where id=1` and `select price from Car where id=1`.

[0052] The query sub-statement `select name from Car where id=1` includes the table name `car`, the query condition `id=1`, and the query field `name`; the query sub-statement `select price from Car where id=1` includes the table name `car`, the query condition `id=1`, and the query field `price`.

[0053] If a database query statement contains only one field, such as "name", then there is no need to split the query statement; subsequent steps can be performed directly using the query statement. If a database query statement contains three fields, then three sub-queries can be obtained, and so on, with the number of sub-queries corresponding to the number of fields.

[0054] In step S102, the cache may refer to a storage device used to cache existing query results. For example, the cache may be a computer cache or a distributed cache.

[0055] To improve data query efficiency, a string group can be constructed for each query sub-statement, serving as the identifier for that sub-statement. A mapping between cached data and this string group can then be established. Since the cached data represents the results of previous queries, this effectively establishes a correspondence between existing query results and query sub-statements in the cache. This allows for the direct retrieval of existing query results from the cache during subsequent queries, enabling result reuse and improving overall data query efficiency.

[0056] A string group can refer to a combination of multiple strings. The string group is constructed based on the table name, query conditions and query fields in the query substatement. For example, if the table name is Car, the query condition is id=1 and the query field is name, the constructed string group can be "Car:name:id=1".

[0057] For ease of explanation, let's call the query sub-statement `select name from Car where id=1` query sub-statement A, and the query sub-statement `select price from Car where id=1` query sub-statement B. We can construct string group `a` for query sub-statement A as "Car:name:id=1" and string group `b` for query sub-statement B as "Car:price:id=1". As you can see, in these different query sub-statements, only the query fields in the string groups differ; all other characters are the same. The string groups also reflect the result of the field-dimensional splitting.

[0058] After constructing the string group corresponding to each query sub-statement, it is necessary to determine whether there are target string groups in the cache that completely match string group a and string group b respectively.

[0059] Since the cache stores existing query results and establishes a one-to-one correspondence between existing query results and the string groups of query substatements that retrieve those results, when a target string group that completely matches string group a exists, it means that the cache already contains the query result for string group a, which can be directly reused. Similarly, when a target string group that completely matches string group b exists, it means that the cache already contains the query result for string group b, which can also be directly reused, thereby improving data query efficiency.

[0060] In an optional embodiment, step S102 includes: step a1, step a2, and step a3.

[0061] Step a1: Determine whether the string length of the query condition is greater than the set length threshold.

[0062] Here, the string length varies depending on the query condition. When the query condition is more complex, the string length is longer, and when the query condition is simpler, the string length is shorter.

[0063] Taking a length threshold of 20 characters as an example, if the query condition is "where name='sent via SF Express with separate charges' and price=100000 and id=10", since the query condition is longer than 20 characters, the corresponding string group will also be long, making string group queries inconvenient and reducing query efficiency. Therefore, it is necessary to process the query condition to shorten the length of the string group.

[0064] Step a2: If the string length is greater than the set length threshold, convert the query condition into an encrypted value of the preset length.

[0065] If the query condition is longer than 20 characters, the query condition will be converted into a hash value or MD5 code of 10 characters, which will result in an encrypted value of 10 characters.

[0066] The conversion methods include, but are not limited to: MD5, hash, symmetric encryption, and asymmetric encryption. Those skilled in the art can choose the conversion method for the query conditions according to the actual situation; this application does not impose any limitations on this.

[0067] Step a3: Connect the table name, query field, and encrypted value together using a preset separator to obtain a string group.

[0068] The preset separator symbol is used to distinguish table names, query fields, and encrypted values. For example, the preset separator symbol can be ":", " / ", "-", "*", etc., and is not limited here.

[0069] Taking the encrypted value as “9D5CE6EA8F”, the table name as “Car”, the query field as “name”, and the preset separator as “:” as an example, the above content, when concatenated together, can be used to obtain the string group “Car:name:9D5CE6EA8F”.

[0070] In an alternative embodiment, after step a1, step a4 is further included.

[0071] Step a4: If the string length is less than or equal to the set length threshold, the table name, query fields, and query conditions are directly concatenated together using a preset separator to obtain a string group.

[0072] If the query condition is less than or equal to 20 characters, taking the query condition as "id=1", the table name as "Car", the query field as "name", and the default separator as ":" as an example, the above content, when concatenated together, will result in the string group "Car:name:id=1".

[0073] In an optional embodiment, after step S102, the method further includes steps b1 and b2.

[0074] Step b1: For each string group, determine whether there is a character index in the cache that matches that string group.

[0075] After each string group is constructed, the first step is to check if a character index corresponding to that string group exists in the cache. The character index is a three-level index, meaning it checks if a third-level index exists that completely matches the string group. If a third-level index exists that completely matches the string group, it means that the character index corresponding to that string group has already been created in the cache, and there is no need to create it again.

[0076] To determine if a character index corresponding to a string group exists in the cache, the string group needs to be parsed to obtain its table name, query fields, and query conditions. Then, the three-level indexes are queried level by level to check for a character index that matches the table name, query fields, and query conditions. Specifically, the first-level index of all character indexes in the cache is traversed. If a table name exactly matches in the first-level index, the query fields are checked in all second-level indexes under that first-level index. If a query field exactly matches in a second-level index, the query conditions are checked in all third-level indexes under that second-level index. If a query condition exactly matches, then a character index corresponding to the string group exists.

[0077] Step b2: If no character index matches the string group, construct a character index for the string group using the table name corresponding to the string group as the first-level index, the query conditions corresponding to the string group as the second-level index, and the query fields corresponding to the string group as the third-level index.

[0078] If the cache does not contain a character index corresponding to the string group, then a character index corresponding to the string group needs to be created. This character index is a three-level index: the first-level index is the table name index, the second-level index is the query condition index, and the third-level index is the query field index. The second-level index is a variable-level index, meaning that the second-level index may itself include multiple sub-level indexes.

[0079] Taking the string group "Car:name:id=1" as an example, first create a first-level index Car, then create a second-level index id=1 under this first-level index, and finally create a third-level index name under this second-level index.

[0080] In an optional embodiment, the query conditions include multiple sub-query conditions, and there are logical operation relationships between the multiple sub-query conditions. Step b2 includes: step b21, step b22 and step b23.

[0081] Step b21: Determine the logical operation relationships between multiple subquery conditions.

[0082] For example, the query condition is "where id=1 or price=100". This query condition includes two sub-query conditions: id=1 and price=100. The logical operation relationship between the two sub-query conditions is logical OR.

[0083] For example, the query condition is "where id=1and name=A". This query condition includes two sub-query conditions: id=1 and name=A. The logical operation relationship between the two sub-query conditions is logical AND.

[0084] In step b22, if it is a logical OR, then the multiple subquery conditions are used to create a second-level index in the form of different branches.

[0085] If multiple subquery conditions are logically ORed, then multiple branches are created for each subquery. Taking the example above, if the first-level index is Car, then second-level indexes Car→id=1 and Car→price=100 are created, which is equivalent to having two branches under the first-level index Car.

[0086] Step b23: If it is a logical AND operation, then according to the field name order, create a second-level index for multiple subquery conditions in the form of different sub-levels under the same branch.

[0087] If multiple subquery conditions are logically ANDed, a multi-level branch is created. Taking the example above, if the first-level index is `Car`, then a second-level index `Car→id=1→name=A` is created. Here, `id=1→name=A` is a second-level index containing two sub-levels, equivalent to a multi-level branch under the first-level index `Car`. It should be noted that when creating a second-level index with multiple sub-levels, the subquery conditions can be ranked according to their alphabetical order. For example, the "i" in `id=1` comes before the "n" in `name=A`, therefore, `id=1` is the first sub-level in the second-level index. If the first letters are the same, the order is based on the second letter.

[0088] In step S103, the database query result may refer to the result obtained directly from the database.

[0089] In this embodiment, there may be one or more query substatements that do not contain a target string group. If there is only one, the query substatement is directly used as the reconstructed query statement; if there are multiple, the table name, query conditions, and query fields of each query substatement need to be extracted, and the extracted information is used to reconstruct the query statement.

[0090] Taking query substatement A as select name from Car where id=1, query substatement B as select price from Car where id=1, and query substatement C as select age from Car where id=1 as examples, the string group corresponding to query substatement A is string group a, the string group corresponding to query substatement B is string group b, and the string group corresponding to query substatement C is string group c.

[0091] If the cache only contains a target string group that matches string group a, and no target string groups that match string groups b and c, then query substatements B and C are recombined. The recombined query statements are then used to query the database, and the database query results are stored in the cache, associated with the string groups.

[0092] In an optional embodiment, step S103 involves reorganizing all query sub-statements that do not have a complete match for the target string to generate a reorganized query statement, including steps c1, c2, and c3.

[0093] Step c1: Select query sub-statements that do not have a complete match for the target string as query sub-statements to be reorganized.

[0094] In the example above, if there is no target string group that matches string group b and string group c, then query substatement B and query substatement C are both query substatements to be reorganized.

[0095] Step c2: For each query sub-statement to be restructured, extract the table name, query conditions, and query fields from that sub-statement.

[0096] Extract the table name Car, the query condition id=1, and the query field price from query substatement B. Extract the table name Car, the query condition id=1, and the query field age from query substatement C.

[0097] Step c3 involves reorganizing the table names, query conditions, and query fields corresponding to multiple query sub-statements to be reorganized, and obtaining the reorganized query statement based on the reorganized table names, query conditions, and query fields.

[0098] By combining the table name Car, the query condition id=1, the query field price, the query field age, and the corresponding keywords, we obtain the reorganized query statement "select age,price from Car where id=1".

[0099] In an optional embodiment, the database query result includes multiple database query sub-results, each database query sub-result corresponding to a query sub-statement. In step S103, the database query result is associated with the string group and stored in the cache, including step d1.

[0100] Step d1: For each database query sub-result, store the string group corresponding to the database query sub-result and the database query sub-result in the cache as key-value pairs.

[0101] Taking the above example, suppose we use a reorganized query statement to query the database and obtain the database query sub-results age=20 and price=100. Then, we can store the database query sub-result age=20 and the string group c as key-value pairs in the cache, and store the database query sub-result price=100 and the string group b as key-value pairs in the cache.

[0102] In addition, since the data in the database is frequently updated, the data in the cache also needs to be updated when the database is updated.

[0103] In an optional embodiment, the method further includes steps e1 and e2.

[0104] Step e1: When updating the database, parse the database operation log to obtain the update information of the data being updated.

[0105] Here, it is necessary to monitor the database operation log in real time. When changes are detected in the operation log, the operation log needs to be parsed to obtain the update information.

[0106] Step e2: Update the string group, cache value, and character index corresponding to the string group stored in the cache according to the update information.

[0107] Using the update information, the string group corresponding to the updated data, the cached value, and the character index corresponding to the string group are removed from the cache.

[0108] In an optional embodiment, step e2 includes: step e21, step e22, and step e23.

[0109] Here, the update information includes an update type, first update information, and second update information. The update type includes modification and deletion, the first update information is the update information when modifying the to-be-updated data, and the second update information is the update information when deleting the to-be-updated data;

[0110] In step e21, if the update type is modification, a target string group for modifying the to-be-updated data is determined according to the first update information.

[0111] If the data in the database is to be modified, the first update information is acquired to determine the target string group according to the first update information. The first update information includes a first table name, a first target field, the to-be-updated data, updated data of the to-be-updated data, and a first field value.

[0112] The first table name is the table name of the data table where the to-be-updated data is located when data modification is performed. The first target field is the field where the to-be-updated data is located. The first field value is the updated value of the remaining fields in the row where the to-be-updated data is located except the field where the to-be-updated data is located, and the first field value includes a field name and a specific value.

[0113] For example: the table where the to-be-updated data is located is Car, the data table Car has four fields: id, name, price, and branch, the field where the to-be-updated data is located is name, the pre-update data is A, data A is in the row with id=1, in this row, price=10000, branch=Jiji, the post-update data is B, then the first table name is Car, the first target field is name, the to-be-updated data is A, the updated data is B, and the first field values are id=1, price=10000, branch=Jiji.

[0114] In step e22, if the update type is deletion, a target string group for deleting the to-be-updated data is determined according to the second update information.

[0115] If the data in the database is to be deleted, the second update information is acquired to determine the target string group according to the second update information. The second update information includes a second table name and a second field value, and the second field value is the value of all fields in the row where the to-be-deleted data is located. The second field value includes a field name and a specific value, and the deletion operation is to delete the entire piece of data in the row where the to-be-updated data is located.

[0116] For example: If the table containing the updated data is Car, and the Car table has four fields: id, name, price, and branch, and the updated data is in the row with id=2, where name=C, price=20000, and branch=some odd, then the second table name is Car, and the second field value is id=2, name=C, price=20000, and branch=some odd.

[0117] Step e23: Delete the target string group, the cached value corresponding to the target string group, and the character index corresponding to the target string group from the cache.

[0118] After determining the target string group, determine the corresponding cached value and character index, and then delete the target string group, cached value, and character index from the cache. If the target string group and cached value are stored in the cache as key-value pairs, then the target string group is the key.

[0119] In an optional embodiment, step e21 includes: step e211, step e212, step e213, step e214, and step e215.

[0120] e211, the combination of the first target field and the data to be updated, the combination of the first target field and the updated data, and the value of the first field are respectively used as the first update conditions.

[0121] Taking the above example, the first table is named Car, the first target field is name, the data to be updated is A, the updated data is B, and the first field value is id=1, price=10000, branch=mouji. The first update condition can be obtained as: name=A, name=B, id=1, price=10000, branch=mouji.

[0122] Step e212: Determine whether a target first-level index matching the name of the first table exists in the cache.

[0123] Iterate through each first-level index in the cache to determine if there is a first-level index in the cache that exactly matches Car.

[0124] Step e213: If a matching target first-level index exists, under the target first-level index, for each first update condition, determine whether there is a target second-level index in the cache that matches the first update condition.

[0125] If a first-level index exists that perfectly matches Car, then that first-level index is the target first-level index.

[0126] The following reference Figure 2 This section will introduce the process of searching for a target string group. Figure 2shows a schematic diagram of the target string group lookup process provided by the embodiments of the present application.

[0127] As Figure 2 shown, there are two branches under the first-level index Car, the first main branch is id=1, the second main branch is branch=Mouji, the second main branch includes three sub-branches, the first sub-branch is branch=Mouji→id=1→name, the second sub-branch is branch=Mouji→id=2→price, and the third sub-branch is branch=Mouji→name=A→id. The second-level indexes under the second main branch include id=1, branch=Mouji→id=1, branch=Mouji→id=2, and branch=Mouji→name=A. The third-level indexes under the second main branch include name, price, and id.

[0128] After the target first-level index is determined, under the target first-level index Car, it is determined whether there are second-level indexes that are completely matched with name=A, name=B, id=1, price=10000, and branch=Mouji respectively.

[0129] Since id=1 exists under the first main branch and completely matches id=1 in the first update condition, the lookup may continue downward for the third-level index.

[0130] Since branch=Mouji exists under the second branch and completely matches branch=Mouji in the first update condition, the matching may continue along the three sub-branches. When matching the sub-branches, since id=1 exists under the first sub-branch and matches id=1 in the first update condition, the lookup may continue downward along the first sub-branch for the third-level index; since id=2 exists under the second sub-branch and does not match any of the first update conditions, the downward lookup cannot be performed, this sub-branch ends, and the end of the lookup is represented by a dashed line; since name=A exists under the third sub-branch and completely matches name=A in the first update condition, the lookup may continue downward along the third sub-branch for the third-level index.

[0131] That is to say, if the second-level index includes multiple sub-branches, and some sub-branches include multiple sub-levels, it is required that all the first update conditions in all sub-levels under the sub-branch have matching conditions in the first update condition, so that the sub-branch can be used as the target second-level index.

[0132] Step e214: If a matched target second-level index exists, under the target second-level index, it is determined whether a target third-level index matching the first target field exists in the cache.

[0133] Under the first main branch, since the third-level index is name, which completely matches the first target field, the third-level index is taken as the target tertiary index.

[0134] Under the second main branch, since the third-level index under the first sub-branch is name, which completely matches the first target field, the third-level index under the first sub-branch is taken as the target tertiary index; since the third-level index under the second sub-branch is price, which does not match the first target field, the third-level index under the second sub-branch cannot be taken as the target tertiary index; since the third-level index under the third sub-branch is id, which does not match the first target field, the third-level index under the third sub-branch cannot be taken as the target tertiary index.

[0135] Step e215: if a matching target tertiary index exists, the string set corresponding to the target tertiary index is taken as the target string set.

[0136] A corresponding string set is stored under each third-level index, and the string set under the target tertiary index is taken as the target string set. The third-level index under the first main branch is the target tertiary index, so Car:name:id=1 under the target tertiary index is taken as the target string set, and similarly, Car:name:id=1&branch=Mouji is also taken as the target string set.

[0137] In an optional embodiment, step e22 includes: step e221, step e222, step e223, step e224, and step e225.

[0138] Step e221: each second field value is taken as one second update condition.

[0139] Taking the above example as an instance, the second table name is Car, and the second field values are id=1, name=A, price=10000, and branch=Mouji, so the obtained second update conditions are: id=1, name=A, price=10000, and branch=Mouji.

[0140] Step e222: determine whether there is a target primary index matching the second table name in the cache.

[0141] Traverse each first-level index in the cache, and determine whether there is a first-level index that completely matches Car in the cache.

[0142] Step e223: if a matching target primary index exists, under the target primary index, for each second update condition, determine whether there is a target secondary index matching the second update condition in the cache.

[0143] Take Figure 2For example, the entire process is the same as that of the modification operation, which will not be repeated here.

[0144] Step e224: If a matching target secondary index exists, under the target secondary index, it is determined whether a target tertiary index matching the second target field exists in the cache.

[0145] Here, the second target field is all fields in the data table corresponding to the second table name.

[0146] During the deletion operation, the search results of the first main branch, the first sub-branch and the second sub-branch are the same as the search results during the modification operation, but the third sub-branch is different. Under the second main branch, since the tertiary index under the third sub-branch is id, and the second target field is all fields, that is, the second target field includes the id field, the tertiary index under the third sub-branch completely matches the id field in the second target field, so the tertiary index under the third sub-branch is taken as the target tertiary index.

[0147] Step e225: If a matching target tertiary index exists, the string set corresponding to the target tertiary index is taken as the target string set.

[0148] Similarly, a corresponding string set is stored under each tertiary index, and the string set under the determined target tertiary index is taken as the target string set.

[0149] If the tertiary index under the first main branch is the target tertiary index, Car:name:id=1 under the target tertiary index is taken as the target string set, and at the same time, Car:name:id=1&branch=Xxxji and Car:id:branch=Xxxji&name=A indicated by the first sub-branch and the third sub-branch under the second main branch are both taken as the target string set.

[0150] In step S104, the final data query result is the query result corresponding to the database query statement. Taking the above example as an example, it is the final query result of the database query statement "select name,price from Car where id=1".

[0151] The database query result is obtained only when there is no completely matching target string set in the cache. If a completely matching target string set exists in the cache, the corresponding query result will also be obtained from the cache, and the database query result and the cache query result need to be combined to obtain the final data query result.

[0152] In an optional embodiment, after step S102, the method further includes: step f1.

[0153] Step f1: If there is a target string group that completely matches the string group, the cache value corresponding to the target string group is used as the cache query result.

[0154] If the string group "Car:name:id=1" exists in the cache, it is determined that there is a target string group that completely matches the string group a in the cache, the string group "Car:name:id=1" is the target string group of the string group a, and the cache value corresponding to the target string group "Car:name:id=1" in the cache is used as the cache query result of the query sub-statement A. For example, if the cache value is "Car A", the cache query result of the query sub-statement A is "Car A". Similarly, if the string group "Car:price:id=1" exists in the cache, it is determined that there is a target string group that completely matches the string group b in the cache, the string group "Car:price:id=1" is the target string group of the string group b, and the cache value corresponding to the target string group "Car:price:id=1" in the cache is used as the cache query result of the query sub-statement B. For example, if the cache value is "90000", the cache query result of the query sub-statement B is "90000".

[0155] In an optional embodiment, step S104 includes step f2.

[0156] Step f2: Combine the database query result and the cache query result to obtain the final data query result.

[0157] The cache query result is acquired, and the cache query result and the database query result are combined together to serve as the final data query result.

[0158] Compared with the data query methods in the prior art, the present application can split one database query statement into a plurality of query sub-statements, construct a string group corresponding to each query sub-statement, determine unqueried data through matching of the string groups, query the unqueried data from the database through a regenerated reconstructed query statement, store the unqueried data in the cache, convert the unqueried data into queried data, so that the queried data stored in the cache can be directly used in the next query, which improves the data query efficiency and solves the problem of low data query efficiency.

[0159] Based on the same inventive concept, the embodiments of the present application further provide a data query apparatus corresponding to the data query method. Since the principle of the apparatus in the embodiments of the present application for solving problems is similar to that of the aforementioned data query method in the embodiments of the present application, the implementation of the apparatus may refer to the implementation of the method, and repeated parts will not be described again.

[0160] Please refer to Figure 3 , Figure 3This is a schematic diagram of the structure of a data query device provided in an embodiment of this application. Figure 3 As shown, the data query device 200 includes:

[0161] The statement splitting module 201 is used to split the database query statement according to the field dimension to obtain multiple query sub-statements. Each query sub-statement includes the table name, query conditions and query fields.

[0162] The string group construction module 202 is used to construct a string group corresponding to each query sub-statement based on the table name, query conditions and query fields of the query sub-statement, and to determine whether there is a target string group in the cache that completely matches the string group.

[0163] The database query module 203 is used to reorganize all query sub-statements that do not have a complete match for the target string if it does not exist, generate a reorganized query statement, retrieve the database query result corresponding to the reorganized query statement from the database, and store the database query result in the cache along with the string group.

[0164] The result determination module 204 is used to obtain the final data query result of the database query statement based on the database query result.

[0165] In a feasible implementation, the string group construction module 202 includes a length comparison module, a conversion module, and a first combination module. The length comparison module is used to: determine whether the string length of the query condition is greater than a set length threshold; the conversion module is used to: convert the query condition into an encrypted value of a preset length if the string length is greater than the set length threshold; the first combination module is used to: concatenate the table name, query field, and encrypted value together using a preset interval symbol to obtain a string group.

[0166] In a feasible implementation, the string group construction module 202 is further specifically used for: for each string group, determining whether there is a character index in the cache that matches the string group; if there is no character index that matches the string group, constructing a character index for the string group using the table name corresponding to the string group as the first-level index, the query conditions corresponding to the string group as the second-level index, and the query fields corresponding to the string group as the third-level index.

[0167] In a feasible implementation, the query conditions include multiple sub-query conditions, and there are logical operation relationships between the multiple sub-query conditions. The string group construction module 202 is also specifically used to: determine the logical operation relationships between the multiple sub-query conditions; if it is a logical OR, then build a second-level index for the multiple sub-query conditions in the form of different branches; if it is a logical AND, then build a second-level index for the multiple sub-query conditions in the form of different sub-levels under the same branch according to the field name order.

[0168] In a feasible implementation, the data query device 200 further includes a data update module (not shown in the figure). The data update module includes a parsing module, a first update submodule, and a second update submodule. The parsing module is used to: parse the database operation log during database updates to obtain update information of the updated data. The update information includes update type, first update information, and second update information. The first update information is the update information when the updated data is modified, and the second update information is the update information when the updated data is deleted. The first update submodule is used to: if the update type is modification, determine the target string group when the updated data is modified based on the first update information. The second update submodule is used to: if the update type is deletion, determine the target string group when the updated data is deleted based on the second update information; and delete the target string group, the cached value corresponding to the target string group, and the character index corresponding to the target string group from the cache.

[0169] In a feasible implementation, the first update information includes a first table name, a first target field, the data to be updated, the updated data of the data to be updated, and a first field value. The first field value is the updated value of all fields in the row containing the updated data, excluding the field containing the updated data. The first target field is the field containing the data to be updated. The first update submodule is specifically used for: taking the combination of the first target field and the data to be updated, the combination of the first target field and the updated data, and the first field value as first update conditions; determining whether there is a target first-level index in the cache that matches the first table name; if there is a matching target first-level index, under the target first-level index, for each first update condition, determining whether there is a target second-level index in the cache that matches the first update condition; if there is a matching target second-level index, under the target second-level index, determining whether there is a target third-level index in the cache that matches the first target field; if there is a matching target third-level index, taking the string group corresponding to the target third-level index as the target string group.

[0170] In a feasible implementation, the second update information includes a second table name and a second field value, where the second field value is the value of all fields in the row containing the deleted data. The second update submodule is specifically used for: treating each second field value as a second update condition; determining whether a target first-level index matching the second table name exists in the cache; if a matching target first-level index exists, determining whether a target second-level index matching the second update condition exists in the cache for each second update condition under the target first-level index; if a matching target second-level index exists, determining whether a target third-level index matching the second target field exists in the cache under the target second-level index; and if a matching target third-level index exists, using the string group corresponding to the target third-level index as the target string group.

[0171] In one feasible implementation, the database query module 203 includes a statement reorganization module, which is used to: take query sub-statements that do not have a completely matching target string as query sub-statements to be reorganized; for each query sub-statement to be reorganized, extract the table name, query conditions, and query fields from the query sub-statement to be reorganized; reorganize the table names, query conditions, and query fields corresponding to multiple query sub-statements to be reorganized, and obtain the reorganized query statement based on the reorganized table names, query conditions, and query fields.

[0172] In one feasible implementation, the database query result includes multiple database query sub-results, each database query sub-result corresponding to a query sub-statement. The database query module 203 also includes a result storage module, which is used to: for each database query sub-result, store the string group corresponding to the database query sub-result and the database query sub-result in the form of key-value pairs in the cache.

[0173] In one feasible implementation, the data query device 200 further includes a cache query module (not shown in the figure), which is used to: if there is a target string group that completely matches the string group, use the cached value corresponding to the target string group as the cache query result.

[0174] In one feasible implementation, the result determination module 204 is specifically used to: combine the database query result with the cached query result to obtain the final data query result.

[0175] In one feasible implementation, the string group construction module 202 further includes a second combination module, which is used to: if the string length is less than or equal to a set length threshold, directly connect the table name, query fields and query conditions together using a preset interval symbol to obtain a string group.

[0176] By using the above method, this application can split a database query statement into multiple query sub-statements and construct a string group corresponding to each query sub-statement. By matching the string groups, it can identify data that has not been queried. The regenerated and recombined query statement retrieves the data that has not been queried from the database and stores it in the cache. The data that has not been queried is converted into queried data so that the queried data stored in the cache can be used directly in the next query, thereby improving data query efficiency and solving the problem of low data query efficiency.

[0177] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 4As shown, the electronic device 300 includes a processor 310, a memory 320, and a bus 330.

[0178] The memory 320 stores machine-readable instructions executable by the processor 310. When the electronic device 300 is running, the processor 310 communicates with the memory 320 via a bus 330. The processor 310 executes the machine-readable instructions, specifically the preamble of the method item, to perform the following steps:

[0179] The database query statement is split according to the field dimension to obtain multiple query sub-statements. Each query sub-statement includes the table name, query conditions and query fields.

[0180] For each query sub-statement, construct a string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, and determine whether there is a target string group in the cache that completely matches the string group;

[0181] If it does not exist, reorganize all query sub-statements that do not have a complete match for the target string to generate a reorganized query statement, retrieve the database query results corresponding to the reorganized query statement from the database, and store the database query results in the cache in association with the string group;

[0182] Based on the database query results, obtain the final data query results of the database query statement.

[0183] In a feasible implementation, when the processor 310 executes the process of constructing a string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, it specifically performs the following steps: determining whether the string length of the query conditions is greater than a set length threshold; if the string length is greater than the set length threshold, converting the query conditions into encrypted values ​​of a preset length; and concatenating the table name, query fields, and encrypted values ​​together using a preset interval symbol to obtain a string group.

[0184] In one feasible implementation, after the processor 310 executes the construction of the string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, it is further specifically used to: for each string group, determine whether there is a character index in the cache that matches the string group; if there is no character index that matches the string group, construct a character index for the string group using the table name corresponding to the string group as the first-level index, the query conditions corresponding to the string group as the second-level index, and the query fields corresponding to the string group as the third-level index.

[0185] In one feasible implementation, the query conditions include multiple sub-query conditions, and there are logical operation relationships between the multiple sub-query conditions. When the processor 310 executes the construction of the character index of the string group, it is specifically used to: determine the logical operation relationship between the multiple sub-query conditions; if it is logical OR, then build a second-level index for the multiple sub-query conditions in the form of different branches; if it is logical AND, then build a second-level index for the multiple sub-query conditions in the form of different sub-levels under the same branch according to the field name order.

[0186] In a feasible implementation, the processor 310 is further configured to: parse the database operation log during database updates to obtain update information of the updated data, the update information including update type, first update information, and second update information, the first update information being the update information when the updated data is modified, and the second update information being the update information when the updated data is deleted; if the update type is modification, determine the target string group when the updated data is modified based on the first update information; if the update type is deletion, determine the target string group when the updated data is deleted based on the second update information; and delete the target string group, the cached value corresponding to the target string group, and the character index corresponding to the target string group from the cache.

[0187] In a feasible implementation, the first update information includes a first table name, a first target field, updated data, updated data of the updated data, and a first field value. The first field value is the updated value of all fields in the row containing the updated data, excluding the field containing the updated data. The first target field is the field containing the updated data. When the processor 310 executes the process of determining the target string group for modifying the updated data based on the first update information, it specifically performs the following steps: using the combination of the first target field and the updated data, the combination of the first target field and the updated data, and the first field value as first update conditions; determining whether a target first-level index matching the first table name exists in the cache; if a matching target first-level index exists, under the target first-level index, for each first update condition, determining whether a target second-level index matching the first update condition exists in the cache; if a matching target second-level index exists, under the target second-level index, determining whether a target third-level index matching the first target field exists in the cache; if a matching target third-level index exists, using the string group corresponding to the target third-level index as the target string group.

[0188] In one feasible implementation, the second update information includes a second table name and a second field value, wherein the second field value is the value of all fields in the row containing the deleted data; when the processor 310 executes the determination of the target string group for deleting the updated data based on the second update information, it specifically performs the following: treating each second field value as a second update condition; determining whether a target first-level index matching the second table name exists in the cache; if a matching target first-level index exists, determining whether a target second-level index matching the second update condition exists in the cache for each second update condition under the target first-level index; if a matching target second-level index exists, determining whether a target third-level index matching the second target field exists in the cache under the target second-level index; if a matching target third-level index exists, using the string group corresponding to the target third-level index as the target string group.

[0189] In a feasible implementation, when the processor 310 reassembles all query sub-statements that do not have a complete match for the target string to generate a reassembled query statement, it specifically performs the following steps: taking query sub-statements that do not have a complete match for the target string as query sub-statements to be reassembled; for each query sub-statement to be reassembled, extracting the table name, query conditions, and query fields from the query sub-statement to be reassembled; reassembling the table names, query conditions, and query fields corresponding to multiple query sub-statements to be reassembled, and obtaining a reassembled query statement based on the reassembled table names, query conditions, and query fields.

[0190] In one feasible implementation, the database query result includes multiple database query sub-results, each database query sub-result corresponding to a query sub-statement. When the processor 310 executes and associates the database query result with the string group and stores it in the cache, it specifically performs the following: for each database query sub-result, it stores the string group corresponding to the database query sub-result and the database query sub-result in the cache in the form of a key-value pair.

[0191] In one feasible implementation, after determining whether a target string group that completely matches the string group exists in the cache, the processor 310 is further configured to: if a target string group that completely matches the string group exists, use the cache value corresponding to the target string group as the cache query result.

[0192] In one feasible implementation, when the processor 310 executes the final data query result of the database query statement based on the database query result, it is specifically used to: combine the database query result with the cached query result to obtain the final data query result.

[0193] In one feasible implementation, after the processor 310 determines whether the string length of the query condition is greater than a set length threshold, it is further specifically used to: if the string length is less than or equal to the set length threshold, directly connect the table name, query field and query condition together using a preset interval symbol to obtain a string group.

[0194] By using the above method, this application can split a database query statement into multiple query sub-statements and construct a string group corresponding to each query sub-statement. By matching the string groups, it can identify data that has not been queried. The regenerated and recombined query statement retrieves the data that has not been queried from the database and stores it in the cache. The data that has not been queried is converted into queried data so that the queried data stored in the cache can be used directly in the next query, thereby improving data query efficiency and solving the problem of low data query efficiency.

[0195] This application embodiment also provides a computer-readable storage medium storing a computer program, which is executed by a processor, wherein the processor performs the following steps:

[0196] The database query statement is split according to the field dimension to obtain multiple query sub-statements. Each query sub-statement includes the table name, query conditions and query fields.

[0197] For each query sub-statement, construct a string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, and determine whether there is a target string group in the cache that completely matches the string group;

[0198] If it does not exist, reorganize all query sub-statements that do not have a complete match for the target string to generate a reorganized query statement, retrieve the database query results corresponding to the reorganized query statement from the database, and store the database query results in the cache in association with the string group;

[0199] Based on the database query results, obtain the final data query results of the database query statement.

[0200] In one feasible implementation, when the processor executes the process of constructing a string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, it specifically performs the following steps: determining whether the string length of the query conditions is greater than a set length threshold; if the string length is greater than the set length threshold, converting the query conditions into encrypted values ​​of a preset length; and concatenating the table name, query fields, and encrypted values ​​together using a preset separator symbol to obtain a string group.

[0201] In one feasible implementation, after the processor constructs the string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, it is further specifically used to: for each string group, determine whether there is a character index in the cache that matches the string group; if there is no character index that matches the string group, construct a character index for the string group using the table name corresponding to the string group as the first-level index, the query conditions corresponding to the string group as the second-level index, and the query fields corresponding to the string group as the third-level index.

[0202] In one feasible implementation, the query conditions include multiple sub-query conditions, and there are logical operation relationships between the multiple sub-query conditions. When the processor executes the construction of the character index of the string group, it is specifically used to: determine the logical operation relationship between the multiple sub-query conditions; if it is logical OR, then build a second-level index for the multiple sub-query conditions in the form of different branches; if it is logical AND, then build a second-level index for the multiple sub-query conditions in the form of different sub-levels under the same branch according to the field name order.

[0203] In a feasible implementation, the processor is further configured to: parse the database operation log during database updates to obtain update information of the updated data, the update information including update type, first update information, and second update information, the first update information being the update information when the updated data is modified, and the second update information being the update information when the updated data is deleted; if the update type is modification, determine the target string group when the updated data is modified based on the first update information; if the update type is deletion, determine the target string group when the updated data is deleted based on the second update information; and delete the target string group, the cached value corresponding to the target string group, and the character index corresponding to the target string group from the cache.

[0204] In a feasible implementation, the first update information includes a first table name, a first target field, updated data, updated data of the updated data, and a first field value. The first field value is the updated value of all fields in the row containing the updated data, excluding the field containing the updated data. The first target field is the field containing the updated data. When the processor executes the process of determining the target string group for modifying the updated data based on the first update information, it specifically performs the following steps: using the combination of the first target field and the updated data, the combination of the first target field and the updated data, and the first field value as first update conditions; determining whether a target first-level index matching the first table name exists in the cache; if a matching target first-level index exists, under the target first-level index, for each first update condition, determining whether a target second-level index matching the first update condition exists in the cache; if a matching target second-level index exists, under the target second-level index, determining whether a target third-level index matching the first target field exists in the cache; if a matching target third-level index exists, using the string group corresponding to the target third-level index as the target string group.

[0205] In one feasible implementation, the second update information includes a second table name and a second field value, wherein the second field value is the value of all fields in the row containing the deleted data; when the processor executes the process of determining the target string group for deleting the updated data based on the second update information, it specifically performs the following steps: treating each second field value as a second update condition; determining whether a target first-level index matching the second table name exists in the cache; if a matching target first-level index exists, determining whether a target second-level index matching the second update condition exists in the cache for each second update condition under the target first-level index; if a matching target second-level index exists, determining whether a target third-level index matching the second target field exists in the cache under the target second-level index; and if a matching target third-level index exists, using the string group corresponding to the target third-level index as the target string group.

[0206] In one feasible implementation, when the processor reassembles all query sub-statements that do not have a complete match for the target string to generate a reassembled query statement, it specifically performs the following steps: taking query sub-statements that do not have a complete match for the target string as query sub-statements to be reassembled; for each query sub-statement to be reassembled, extracting the table name, query conditions, and query fields from the query sub-statement to be reassembled; reassembling the table names, query conditions, and query fields corresponding to multiple query sub-statements to be reassembled, and obtaining a reassembled query statement based on the reassembled table names, query conditions, and query fields.

[0207] In one feasible implementation, the database query result includes multiple database query sub-results, each database query sub-result corresponding to a query sub-statement. When the processor executes and associates the database query result with a string group in the cache, it specifically performs the following: for each database query sub-result, it stores the string group corresponding to the database query sub-result and the database query sub-result in the cache as a key-value pair.

[0208] In one feasible implementation, after the processor performs the operation of determining whether there is a target string group in the cache that completely matches the string group, it is further specifically used to: if there is a target string group that completely matches the string group, use the cache value corresponding to the target string group as the cache query result.

[0209] In one feasible implementation, when the processor executes the final data query result of the database query statement based on the database query result, it is specifically used to: combine the database query result with the cached query result to obtain the final data query result.

[0210] In one feasible implementation, after the processor determines whether the string length of the query condition is greater than a set length threshold, it is further specifically used to: if the string length is less than or equal to the set length threshold, directly connect the table name, query field and query condition together using a preset interval symbol to obtain a string group.

[0211] By using the above method, this application can split a database query statement into multiple query sub-statements and construct a string group corresponding to each query sub-statement. By matching the string groups, it can identify data that has not been queried. The regenerated and recombined query statement retrieves the data that has not been queried from the database and stores it in the cache. The data that has not been queried is converted into queried data so that the queried data stored in the cache can be used directly in the next query, thereby improving data query efficiency and solving the problem of low data query efficiency.

[0212] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0213] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the shown or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.

[0214] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0215] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0216] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0217] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The scope of protection of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this application. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A data query method, characterized in that, include: The database query statement is split according to the field dimension to obtain multiple query sub-statements. Each query sub-statement includes the table name, query conditions and query fields. For each query sub-statement, construct a string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, and determine whether there is a target string group in the cache that completely matches the string group; If not, reorganize all query sub-statements that do not have a complete match for the target string to generate a reorganized query statement, retrieve the database query result corresponding to the reorganized query statement from the database, and store the database query result in the cache in association with the string group; Based on the database query results, the final data query result of the database query statement is obtained; After constructing the string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement, the following is also included: For each string group, determine whether there is a character index in the cache that matches that string group; If no character index exists that matches the string group, construct a character index for the string group using the table name corresponding to the string group as the first-level index, the query conditions corresponding to the string group as the second-level index, and the query fields corresponding to the string group as the third-level index.

2. The method according to claim 1, characterized in that, The step of constructing the string group corresponding to the query sub-statement based on the table name, query conditions, and query fields of the query sub-statement includes: Determine whether the string length of the query condition is greater than a set length threshold; If the string length is greater than a set length threshold, the query condition is converted into an encrypted value of a preset length; By using a preset separator, the table name, the query field, and the encrypted value are concatenated together to obtain a string group.

3. The method according to claim 1, characterized in that, The query conditions include multiple sub-query conditions, and there are logical operation relationships between the multiple sub-query conditions. Constructing the character index for the string group includes: Determine the logical operation relationships between multiple subquery conditions; If it is a logical OR, then multiple subquery conditions will be used to create a second-level index in the form of different branches; If it is a logical AND operation, then the second-level index will be created by combining multiple subquery conditions in the same branch at different sub-levels, according to the field name order.

4. The method according to claim 1, characterized in that, The method further includes: When the database is updated, the operation log of the database is parsed to obtain the update information of the updated data. The update information includes update type, first update information and second update information. The first update information is the update information when the updated data is modified, and the second update information is the update information when the updated data is deleted. If the update type is modification, the target string group when the updated data is modified is determined based on the first update information; If the update type is deletion, the target string group for deleting the updated data is determined according to the second update information; Remove the target string group, the cached value corresponding to the target string group, and the character index corresponding to the target string group from the cache.

5. The method according to claim 4, characterized in that, The first update information includes a first table name, a first target field, the data to be updated, the updated data of the data to be updated, and a first field value. The first field value is the updated value of the remaining fields in the row where the updated data is located, excluding the field where the updated data is located. The first target field is the field where the updated data is located. The step of determining the target string group for modifying the updated data based on the first update information includes: The combination of the first target field and the updated data, the combination of the first target field and the updated data, and the value of the first field are respectively used as the first update conditions; Determine whether a target first-level index matching the name of the first table exists in the cache; If a matching target first-level index exists, under the target first-level index, for each first update condition, determine whether there is a target second-level index in the cache that matches the first update condition; If a matching target secondary index exists, determine whether a target tertiary index matching the first target field exists in the cache under the target secondary index; If a matching target third-level index exists, the string group corresponding to the target third-level index is taken as the target string group.

6. The method according to claim 4, characterized in that, The second update information includes the name of the second table and the value of the second field, wherein the value of the second field is the value of all fields in the row where the deleted data is located; The step of determining the target string group for deleting updated data based on the second update information includes: Use each value of the second field as a second update condition; Determine if a target first-level index matching the name of the second table exists in the cache; If a matching target first-level index exists, under the target first-level index, for each second update condition, determine whether there is a target second-level index in the cache that matches the second update condition; If a matching target secondary index exists, determine whether a target tertiary index matching the second target field exists in the cache under the target secondary index; If a matching target third-level index exists, the string group corresponding to the target third-level index is taken as the target string group.

7. The method according to claim 1, characterized in that, The process of reorganizing all query sub-statements that do not have a complete match for the target string to generate a reorganized query statement includes: Query sub-statements that do not have a complete match for the target string are treated as query sub-statements to be restructured; For each query sub-statement to be restructured, extract the table name, query conditions, and query fields from that query sub-statement. The table names, query conditions, and query fields corresponding to multiple query sub-statements to be reorganized are reorganized, and the reorganized query statement is obtained based on the reorganized table names, query conditions, and query fields.

8. The method according to claim 1, characterized in that, The database query result includes multiple database query sub-results, each corresponding to a query sub-statement. The process of associating the database query result with a string group and storing it in a cache includes: For each database query sub-result, the string group corresponding to the database query sub-result and the database query sub-result are stored in the cache as key-value pairs.

9. The method according to claim 1, characterized in that, After determining whether a target string group that completely matches the string group exists in the cache, the method further includes: If a target string group exists that completely matches the string group, the cached value corresponding to the target string group is used as the cached query result.

10. The method according to claim 9, characterized in that, Obtaining the final data query result of the database query statement based on the database query result includes: The database query results are combined with the cached query results to obtain the final data query results.

11. The method according to claim 2, characterized in that, After determining whether the string length of the query condition is greater than a set length threshold, the method further includes: If the string length is less than or equal to the set length threshold, the table name, the query field, and the query conditions are directly concatenated together using a preset separator symbol to obtain a string group.

12. A data query device, characterized in that, include: The statement splitting module is used to split database query statements according to field dimensions to obtain multiple query sub-statements. Each query sub-statement includes the table name, query conditions, and query fields. The string group construction module is used to construct a string group corresponding to each query sub-statement based on the table name, query conditions and query fields of the query sub-statement, and to determine whether there is a target string group in the cache that completely matches the string group. The database query module is used to reorganize all query sub-statements that do not have a complete match for the target string if the target string does not exist, generate a reorganized query statement, retrieve the database query result corresponding to the reorganized query statement from the database, and store the database query result in the cache in association with the string group. The result determination module is used to obtain the final data query result of the database query statement based on the database query result. The data query device is also used for: For each string group, determine whether there is a character index in the cache that matches that string group; If no character index exists that matches the string group, construct a character index for the string group using the table name corresponding to the string group as the first-level index, the query conditions corresponding to the string group as the second-level index, and the query fields corresponding to the string group as the third-level index.

13. An electronic device, characterized in that, include: The device includes a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is in operation, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the data query method as described in any one of claims 1 to 11.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the data query method as described in any one of claims 1 to 11.

Citation Information

Patent Citations

  • Method and apparatus for a context based cache infrastructure to enable subset query over a cached object

    US20060230024A1