[go: up one dir, main page]

CN117807113A - Data query method, device, equipment and medium - Google Patents

Data query method, device, equipment and medium Download PDF

Info

Publication number
CN117807113A
CN117807113A CN202410029113.8A CN202410029113A CN117807113A CN 117807113 A CN117807113 A CN 117807113A CN 202410029113 A CN202410029113 A CN 202410029113A CN 117807113 A CN117807113 A CN 117807113A
Authority
CN
China
Prior art keywords
query
character string
target
sub
string group
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410029113.8A
Other languages
Chinese (zh)
Inventor
葛明曦
柴俊东
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN202410029113.8A priority Critical patent/CN117807113A/en
Publication of CN117807113A publication Critical patent/CN117807113A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • G06F16/90344Query processing by using string matching techniques
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Fuzzy Systems (AREA)
  • Mathematical Physics (AREA)
  • Probability & Statistics with Applications (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a data query method, a device, equipment and a medium, wherein the method comprises the following steps: splitting the database query statement according to the field dimension to obtain a plurality of query sub-statements; constructing a character string group corresponding to each query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, and determining whether a target character string group completely matched with the character string group exists in a cache; if not, reorganizing all query sub-sentences without completely matched target character strings to generate reorganized query sentences, acquiring database query results corresponding to the reorganized query sentences from a database, and storing the database query results and character string groups in a cache in an associated manner; and obtaining a final data query result of the database query statement according to the database query result. By adopting the data query method, the device, the equipment and the medium, the problem of low data query efficiency is solved.

Description

Data query method, device, equipment and medium
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a data query method, device, equipment, and medium.
Background
When a data query operation is performed on a database, a long connection with the database needs to be established, but the resources of the database are limited, namely, the number of connections, the CPU, the memory and the like of the database are limited, and the processing pressure of the database is increased by high-frequency data query. If the data queried by the database is put into the cache for storage, the data in the cache is preferentially used when the service is used, so that the service response speed can be improved, the processing pressure of the database is reduced, and particularly in the aspect of accurate query, the high-frequency cache hit can bring about huge performance improvement. In precision querying, conventional data querying methods are usually performed in units of methods, and then queried data is stored in a cache.
However, in the conventional data query method, different database query sentences cannot multiplex existing data in the cache, for example: the data query statement a is to accurately query the data with the ID of 1 in the "name" field to obtain a query result a, and put the query result a into the cache, and when the data query statement B queries the data with the same ID of 1 in the "name" and "age" fields, the query result a cannot be multiplexed although the query result a already exists in the cache, and all the data databases need to be queried again by using the data query statement B, so that the problem of low data query efficiency is caused.
Disclosure of Invention
In view of this, an object of the present application is to provide a data query method, device, apparatus and medium, so as to solve the problem of low data query efficiency in the prior art.
In a first aspect, an embodiment of the present application provides a data query method, including:
splitting a database query statement according to a field dimension to obtain a plurality of query sub-statements, wherein each query sub-statement comprises a table name, a query condition and a query field;
constructing a character string group corresponding to each query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, and determining whether a target character string group completely matched with the character string group exists in a cache;
if not, reorganizing all query sub-sentences without completely matched target character strings to generate reorganized query sentences, acquiring database query results corresponding to the reorganized query sentences from a database, and storing the database query results and character string groups in a cache in an associated manner;
and obtaining a final data query result of the database query statement according to the database query result.
Optionally, constructing a character string group corresponding to the query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, including: determining whether the character string length of the query condition is greater than a set length threshold; if the length of the character string is greater than the set length threshold, converting the query condition into an encryption value with a preset length; and connecting the table name, the query field and the encryption value together through a preset interval symbol to obtain a character string group.
Optionally, after constructing the character string group corresponding to the query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, the method further includes: for each character string group, determining whether a character index matched with the character string group exists in a cache; if the character index matched with the character string group does not exist, the character index of the character string group is constructed by taking the table name corresponding to the character string group as a first-level index, taking the query condition corresponding to the character string group as a second-level index and taking the query field corresponding to the character string group as a third-level index.
Optionally, the query condition includes a plurality of sub-query conditions, and a logical operation relationship exists among the plurality of sub-query conditions, so as to construct a character index of the character string group, including: determining a logical operation relation among a plurality of sub-query conditions; if the sub-query conditions are logical OR, establishing a second-level index in the form of different branches; if the sub-query conditions are logically AND, a second-level index is built in the form of different sub-levels under the same branch according to the field name sequence.
Optionally, the method further comprises: when the database is updated, analyzing an operation log of the database to obtain update information of updated data, wherein the update information comprises an update type, first update information and second update information, the first update information is update information when the updated data is modified, and the second update information is update information when the updated data is deleted; if the update type is modification, determining a target character string group when the updated data is modified according to the first update information; if the update type is deleting, determining a target character string group when the updated data is deleted according to the second update information; and deleting the target character string group, the cache value corresponding to the target character string group and the character index corresponding to the target character string group from the cache.
Optionally, the first update information includes a first table name, a first target field, updated data of the updated data, and a first field value, where the first field value is a value of the updated data in the row after the other fields except the field where the updated data is located are updated, and the first target field is a field where the updated data is located; according to the first updating information, determining a target character string group when the updated data is modified, including: respectively taking 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 updating conditions; determining whether a target primary index matched with the first table name exists in the cache; if a matched target primary index exists, determining whether a target secondary index matched with the first updating condition exists in a cache or not according to each first updating condition under the target primary index; if the matched target secondary index exists, determining whether a target tertiary index matched with the first target field exists in the cache under the target secondary index; and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
Optionally, the second update information includes a second table name and a second field value, where the second field value is a value of all fields in the row where the deleted data is located; according to the second updating information, determining a target character string group when the updated data is deleted, including: taking each second field value as a second updating condition; determining whether a target primary index matched with the second table name exists in the cache; if a matched target primary index exists, determining whether a target secondary index matched with each second updating condition exists in the cache or not according to each second updating condition under the target primary index; if the matched target secondary index exists, determining whether a target tertiary index matched with a second target field exists in the cache under the target secondary index; and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
Optionally, reorganizing all query sub-sentences without completely matched target character strings to generate reorganized query sentences, including: taking the query sub-statement without the completely matched target character string as the query sub-statement to be recombined; extracting a table name, a query condition and a query field in each query sub-statement to be recombined aiming at each query sub-statement to be recombined; and reorganizing table names, query conditions and query fields corresponding to the plurality of sub-sentences to be reorganized, and obtaining reorganized query sentences based on the reorganized table names, query conditions and query fields.
Optionally, the database query result includes a plurality of database query sub-results, each corresponding to a query sub-sentence, and storing the database query result in the cache in association with the string group, including: and storing the character string group corresponding to each database query sub-result and the database query sub-result in a buffer memory in the form of key value pairs aiming at each database query sub-result.
Optionally, after determining whether the target string group that is completely matched with the string group exists in the cache, the method further includes: if the target character string group which is completely matched with the character string group exists, the cache value corresponding to the target character string group is used as a cache query result.
Optionally, obtaining a final data query result of the database query statement according to the database query result includes: and combining the database query result with the cache query result to obtain a final data query result.
Optionally, after determining whether the string length of the query condition is greater than the set length threshold, further comprising: if the length of the character string is smaller than or equal to the set length threshold, directly connecting the table name, the query field and the query condition together through a preset interval symbol to obtain the character string group.
In a second aspect, an embodiment of the present application further provides a data query apparatus, where the apparatus includes:
the statement splitting module is used for splitting the database query statement according to the field dimension to obtain a plurality of query sub-statements, wherein each query sub-statement comprises a table name, a query condition and a query field;
the character string group construction module is used for constructing a character string group corresponding to each query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, and determining whether a target character string group which is completely matched with the character string group exists in the cache;
the database query module is used for reorganizing all query sub-sentences without completely matched target character strings if the query sub-sentences do not exist, generating reorganized query sentences, acquiring database query results corresponding to the reorganized query sentences from a database, and storing the database query results and character string groups in a cache in an associated manner;
and the result determining module is used for obtaining the final data query result of the database query statement according to the database query result.
In a third aspect, embodiments of the present application further provide an electronic device, including: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory in communication via the bus when the electronic device is running, the machine-readable instructions when executed by the processor performing the steps of the data querying method as described above.
In a fourth aspect, embodiments of the present application also provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the data querying method as described above.
The embodiment of the application brings the following beneficial effects:
according to the data query method, device, equipment and medium, a database query statement can be split into a plurality of query sub-statements, the character string group corresponding to each query sub-statement is constructed, the data which are not queried is determined through matching of the character string groups, the data which are not queried are queried from the database through the regenerated recombinant query statement, the data which are not queried are stored in the cache, the data which are not queried are converted into queried data, so that the queried data stored in the cache can be directly used in next query, data query efficiency is improved, and compared with the data query method in the prior art, the problem of low data query efficiency is solved.
In order to make the above objects, features and advantages of the present application more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered limiting the scope, and that other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 shows a flowchart of a data query method provided by an embodiment of the present application;
FIG. 2 is a schematic diagram of a target string group search process according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of a data query device according to an embodiment of the present application;
fig. 4 shows a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, which are generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, as provided in the accompanying drawings, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. Based on the embodiments of the present application, every other embodiment that a person skilled in the art would obtain without making any inventive effort is within the scope of protection of the present application.
To facilitate an understanding of the present application, some terms referred to herein are explained below:
and (3) accurate query: database query methods are classified into precision query and fuzzy query, the precision query refers to precisely querying data meeting conditions by using a Where statement, and by way of example, the precision query statement may be SELECT FROM customers WHERE customer _id=12345, and the query statement will return all rows in the customers table with customer_id equal to 12345.
It should be noted that, before the present application proposes, in the precision query, the conventional method for caching database query data, such as @ Cacheable annotation in a Spring framework, usually takes a method unit, the queried data is stored in a cache in the form of key-value pairs, a key is a unique string determined according to an attribute related to the query method (such as a method name, a method parameter, etc.), and a value is a serialization result (the result is also usually a string) of the queried data.
For ease of understanding, taking the traditional data query method as an example (taking MySQL as an example most commonly used in development), it is assumed that there is a table in the database, the table name is Car, there are four fields in the Car table, these fields are id, name, price, brand respectively, and there is no cached data in the cache. If it is desired to query and cache data in the name and price fields in the table Car according to the id, a query method needs to be defined first in the conventional data query method. In the java programming language, its query method definition may be Car findCarNamePriceById (Long id) and a cache function is added to it (e.g., using @ Cacheable annotation in Spring framework). When the method is called, a key 'Car: findCArNamePriceById: { id }', whether data exist in a cache is queried according to the key, and if no corresponding cache data are found, a query statement is regenerated to query the database. After obtaining the corresponding query data, the cache data ("Car: findcarNamePriceById: { id }", "{ Car }") is generated, when the query method is called again with the same id parameter, the cache is queried first, and if the corresponding cache data is found, the { Car } is directly taken out and converted into the data Car.
If it is desired to query and cache name, price, brand field data in Car according to id, it is necessary to define a query method such as Car findCarNamePriceBrandById (Long id) and add a cache function to this query method, and when this new query method is called, the generated key (key) is also different since it is a different method from findcarNamePriceById, resulting in the inability to multiplex cache data generated by the findCArNamePriceById method.
In addition, when deleting the cache, the traditional data query method based on the accurate query needs to define a cache deleting method, and the cache deleting method generally needs to be in one-to-one correspondence with the data query method using the cache, namely, how many data query methods exist and how many cache deleting methods exist. After each data query, a cache deletion method is defined to delete cache data, which also causes the problem of low data query efficiency.
Based on the above, the embodiment of the application provides a data query method to improve the data query efficiency.
Referring to fig. 1, fig. 1 is a flowchart of a data query method according to an embodiment of the present application. As shown in fig. 1, the data query method provided in the embodiment of the present application includes:
Step S101, splitting a database query statement according to a field dimension to obtain a plurality of query sub-statements, wherein each query sub-statement comprises a table name, a query condition and a query field.
Step S102, for each query sub-sentence, constructing a character string group corresponding to the query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, and determining whether a target character string group completely matched with the character string group exists in the cache.
Step S103, if not, recombining all query sub-sentences without completely matched target character strings to generate recombined query sentences, acquiring database query results corresponding to the recombined query sentences from a database, and storing the database query results and character string groups in a cache in an associated manner.
Step S104, obtaining the final data query result of the database query statement according to the database query result.
In step S101, the database query term is a program term for querying the stored data in the database, and the database query term may be an SQL term, for example. The database to be queried may be a relational database or a non-relational database.
The database query statement comprises a table name, a query field and a query condition, wherein the table name is the name of a data table where the queried data is located; the query field is the field name of the field where the queried data is located; the query condition is a screening condition for screening the queried data from the query field.
In this embodiment of the present application, after receiving a data query request, a database query statement is generated, and then the database query statement is parsed to obtain a table name, a query condition, and a query field, where the number of query fields in the database query statement may be one or multiple. Taking a selection name of a database query statement, price from Car where id =1 as an example, the database query statement has two query fields, namely name and price, and the query result of the database query statement can be regarded as a combination of two query sub-statement query results, wherein the two query sub-statements are select name from Car where id =1 and select price from Car where id =1. Therefore, in order to multiplex the data stored in the cache, before the data query, the database query statement may be split according to the field dimension, and two query sub-statements are obtained after splitting, where select name from Car where id =1 and select price from Car where id =1 respectively.
Wherein, select name from Car where id =1 the query sub-statement includes a table name car, a query condition id=1, and a query field name; the query sub-statement select price from Car where id =1 includes a table name car, a query condition id=1, and a query field price.
If there is only one query field in the database query statement, for example: only one field is name, so that the database query statement is not required to be split, and the database query statement is directly utilized for the query of the subsequent steps. If there are three query fields in the database query statement, three query sub-statements may be obtained, and so on, how many query fields there are how many query sub-statements.
In step S102, the cache may refer to a storage device for caching the existing query results, and may be, for example, a computer cache or a distributed cache.
In order to improve the data query efficiency, a character string group corresponding to each query sub-sentence can be constructed, the character string group is used as the identifier of the query sub-sentence, and the corresponding relation between the cached data in the cache and the character string group is established. Because the cache data is the query result of the previous data query, the corresponding relation between the existing query result and the query sub-statement is built in the cache, so that the existing query result is directly obtained from the cache by utilizing the character string group when the next data query is carried out, multiplexing of the query result is realized, and the data query efficiency is improved.
The character string group may refer to a combination of a plurality of character strings, and the character string group is constructed according to a table name, a query condition and a query field in a query sub-sentence, and is exemplified by a table name of Car, a query condition of id=1, and when the query field is name, the constructed character string group may be "Car: name: id=1".
For convenience of explanation, the above-mentioned query sub-sentence select name from Car where id =1 is referred to as a query sub-sentence a, the above-mentioned query sub-sentence select price from Car where id =1 is referred to as a query sub-sentence B, and the character string group a of the query sub-sentence a is "Car: name: id=1" and the character string group B of the query sub-sentence B is "Car: price: id=1", respectively. It can be seen that, in different query sub-sentences, the characters at other positions are identical except that the query fields in the character string set are different, and the character string set also reflects the splitting result of the field dimension.
After the string group corresponding to each query sub-sentence is constructed, it is required to determine whether there is a target string group in the cache that is completely matched with the string group a and the string group b, respectively.
Because the existing query results are stored in the cache, and a one-to-one correspondence between the existing query results and the character string groups of the query sub-sentences for obtaining the existing query results is established in the cache, when the target character string group which is completely matched with the character string group a exists, the query results of the existing character string group a in the cache can be directly multiplexed, and similarly, when the target character string group which is completely matched with the character string group b exists, the query results of the existing character string group b in the cache can be directly multiplexed, so that the data query efficiency is improved.
In an alternative embodiment, step S102 includes: step a1, step a2, step a3.
Step a1, determining whether the character string length of the query condition is greater than a set length threshold.
Here, the lengths of the character strings of different query conditions are different, and when the query conditions are complex, the lengths of the character strings of the query conditions are longer, and when the query conditions are simple, the lengths of the character strings of the query conditions are shorter.
Taking the case that the set length threshold is 20 characters as an example, if the query condition is 'where name=' single charging mode is prefect 'and price=100000 and id=10', the length of the corresponding character string group is longer because the query condition is greater than 20 characters, so that the query of the character string group is inconvenient, and the query efficiency is reduced. For this reason, the query condition needs to be processed to shorten the length of the character string group.
And a2, if the length of the character string is larger than the set length threshold value, converting the query condition into an encrypted value with a preset length.
If the query condition is greater than 20 characters, converting the query condition into a hash value or MD5 code with the length of 10 characters, and obtaining the encryption value with the length of 10.
Among them, the conversion modes include, but are not limited to: MD5, hash, symmetric encryption, asymmetric encryption. The conversion mode of the query condition can be selected by a person skilled in the art according to the actual situation, and the application is not limited herein.
Step a3, connecting the table name, the query field and the encryption value together through a preset interval symbol to obtain a character string group.
The preset interval symbol is a separation symbol for distinguishing a table name, a query field, and an encryption value, and may be ": ","/"," - "," x "etc., are not intended to be limiting.
Taking the encryption value of '9D 5CE6EA 8F', the table name of 'Car', the query field of 'name', and the preset interval symbol of ':A' as an example, the character string group of 'Car: name:9D5CE6EA 8F' can be obtained after the above contents are connected together.
In an alternative embodiment, after step a1, further comprising: step a4.
And a4, if the length of the character string is smaller than or equal to the set length threshold, directly connecting the table name, the query field and the query condition together through a preset interval symbol to obtain a character string group.
If the query condition is less than or equal to 20 characters, and the query condition is "id=1", the table name is "Car", the query field is "name", and the preset interval symbol is ":1", the above contents are connected together, and then a character string group "Car: name: id=1" can be obtained.
In an alternative embodiment, after step S102, the method further includes: step b1 and step b2.
Step b1, for each character string group, determining whether a character index matched with the character string group exists in the cache.
After each time a string group is constructed, it is first determined whether there is a character index corresponding to the string group in the cache, where the character index is a three-level index, that is, whether there is a three-level index that is completely matched with the string group. If the three-level index completely matched with the character string group exists, the character index corresponding to the character string group is already established in the description cache, and the character index does not need to be established again.
When determining whether a character index corresponding to the character string group exists in the cache, the character string group needs to be analyzed to obtain the table name, the query field and the query condition of the character string group. And then sequentially inquiring whether character indexes matched with the table names, the inquiry fields and the inquiry conditions exist in the three-level indexes step by step. Specifically, first-level indexes of all character indexes in a cache are traversed, if a completely matched table name exists in the first-level indexes, whether completely matched query fields exist in all second-level indexes under the first-level indexes is queried, if the completely matched query fields exist in the second-level indexes, whether completely matched query conditions exist in all third-level indexes under the second-level indexes is queried, and if the completely matched query conditions exist, the character indexes corresponding to the character string group are determined to exist.
And b2, if the character index matched with the character string group does not exist, constructing the character index of the character string group by taking the table name corresponding to the character string group as a first-level index, taking the query condition corresponding to the character string group as a second-level index and taking the query field corresponding to the character string group as a third-level index.
If the character index corresponding to the character string group does not exist in the cache, the character index corresponding to the character string group needs to be established. The character index is a three-level index, the first-level index is a table name index, the second-level index is a query condition index, and the third-level index is a query field index. Wherein the second level index is a non-fixed level index, i.e., the second level index may itself comprise sub-level indexes of multiple levels.
Taking a character string group of 'Car: name: id=1' as an example, a first-level index Car is established first, a second-level index id=1 is established under the first-level index, and a third-level index name is established under the second-level index.
In an alternative embodiment, the query condition includes a plurality of sub-query conditions, and the plurality of sub-query conditions have a logical operation relationship, and step b2 includes: step b21, step b22 and step b23.
Step b21, determining a logical operation relation among a plurality of sub-query conditions.
Taking a query condition as "where id=1 or price=100" as an example, the query condition includes two sub-query conditions of id=1 and price=100, and the logical operation relationship between the two sub-query conditions is logical or.
Taking a query condition as "where id=1 and name=a" as an example, the query condition includes two sub-query conditions of id=1 and name=a, and the logical operation relationship between the two sub-query conditions is a logical and.
And step b22, if the sub-query conditions are logical OR, establishing a second-level index in the form of different branches.
If the relation among the sub-query conditions is logical OR, a plurality of branches are respectively established. Taking the above example as an example, if the first-level index is Car, a second-level index of car→id=1 and a second-level index of car→price=100 are respectively established, which corresponds to two branches under the first-level index Car.
And b23, if the sub-query conditions are logically ANDed, establishing a second-level index in the form of different sub-levels under the same branch according to the field name sequence.
If the sub-query conditions are logically and, a branch of multiple levels is established. Taking the above example as an example, if the first level index is Car, a second level index of car→id=1→name=a is established. Wherein id=1→name=a is a second level index including two sub-levels, which corresponds to a multi-level branch under the first level index Car. It should be noted that, when the second level index of the multiple sub-levels is established, the sub-query conditions may be graded according to alphabetical order, for example: "i" in id=1 precedes "n" in name=a, and thus id=1 is the first sub-level in the second level index, and if the initials are the same, ordering is performed according to the second letter.
In step S103, the database query result may refer to a result directly queried from the database.
In the embodiment of the application, the query sub-sentence without the target string group may be one or more. If one is available, the query sub-statement is directly used as a recombined query statement; if the number of the query sub-sentences is multiple, extracting the table names, the query conditions and the query fields in each query sub-sentence, and recombining according to the extracted information to obtain a recombined query sentence.
Taking select name from Car where id =1 for the query sub-sentence a, select price from Car where id =1 for the query sub-sentence B, select age from Car where id =1 for the query sub-sentence C as an example, the string group corresponding to the query sub-sentence a is the string group a, the string group corresponding to the query sub-sentence B is the string group B, and the string group corresponding to the query sub-sentence C is the string group C.
And if only the target character string group matched with the character string group a exists in the cache and the target character string group matched with the character string group B and the character string group C does not exist, the query sub-sentence B and the query sub-sentence C are recombined. And then, inquiring the database by utilizing the recombined inquiry statement to obtain a database inquiry result, and storing the database inquiry result and the character string group in a cache in an associated manner.
In an optional embodiment, in step S103, all query sub-sentences without completely matching target strings are recombined to generate a recombined query sentence, including: step c1, step c2 and step c3.
And c1, taking the query sub-sentence without the completely matched target character string as the query sub-sentence to be recombined.
In the above example, if there is no target string group matching the string group B and the string group C, the query sub-sentence B and the query sub-sentence C are both query sub-sentences to be recombined.
Step c2, extracting the table name, the query condition and the query field in each query sub-statement to be recombined aiming at each query sub-statement to be recombined.
The table name Car, the query condition id=1 and the query field price are extracted from the query sub-sentence B, and the table name Car, the query condition id=1 and the query field age are extracted from the query sub-sentence C.
And c3, reorganizing table names, inquiry conditions and inquiry fields corresponding to the plurality of sub-sentences to be reorganized, and obtaining reorganized inquiry sentences based on the reorganized table names, inquiry conditions and inquiry fields.
After combining the table name Car, the query condition id=1, the query field price, the query field age and the corresponding keywords, a reorganized query sentence "select age, price from Car where id =1" is obtained.
In an alternative embodiment, the database query result includes a plurality of database query sub-results, each corresponding to a query sub-sentence, and in step S103, storing the database query result in association with the string group in the cache, including: step d1.
Step d1, for each database query sub-result, storing the character string group corresponding to the database query sub-result and the database query sub-result in a buffer memory in the form of key value pairs.
Taking the above example as an example, assuming that the database is queried by using the reformulated query sentence to obtain the database query sub-result age=20 and the database query sub-result price=100, the database query sub-result age=20 and the character string group c may be stored in the cache in a key pair manner, and the database query sub-result price=100 and the character string group b may be stored in the cache in a key pair manner.
In addition, since the data in the database is frequently updated, the data in the cache needs to be updated when the database is updated.
In an alternative embodiment, the method further comprises: step e1, step e2.
And e1, when the database is updated, analyzing the operation log of the database to obtain the update information of the updated data.
Here, the operation log of the database needs to be monitored in real time, and when the change of the data in the operation log is monitored, the operation log needs to be analyzed to obtain the update information.
And e2, updating the character string group stored in the cache, the cache value and the character index corresponding to the character string group according to the updating information.
And deleting the character string group corresponding to the updated data, the cache value and the character index corresponding to the character string group from the cache by utilizing the updating information.
In an alternative embodiment, step e2 comprises: step e21, step e22, step e23.
Here, the update information includes an update type, first update information, and second update information. The updating type comprises modification and deletion, wherein the first updating information is updating information when the updated data is modified, and the second updating information is updating information when the updated data is deleted;
and e21, if the update type is modification, determining a target character string group when the updated data is modified according to the first update information.
And if the data in the database is modified, acquiring first updating information to determine the target character string group according to the first updating information. The first updating information comprises a first table name, a first target field, updated data of the updated data and a first field value.
When the first table name is used for data modification, the table name of the data table where the updated data is located. The first target field is the field in which the updated data is located. The first field value is the value of the updated data in the row after the other fields except the field where the updated data is located are updated, and the first field value comprises a field name and a specific value.
For example: the table in which the updated data is located is Car, the data table Car has id, name, price, branch fields, the field in which the updated data is located is name, the data before updating is a, the data a is in a row with id=1, the row has price=10000, the branch=a certain Ji, the updated data is B, the first table name is Car, the first target field is name, the updated data is a, the updated data is B, the first field value is id=1, price=10000, and the branch=a certain Ji.
And e22, if the update type is deleting, determining a target character string group when the updated data is deleted according to the second update information.
And if the data in the database is deleted, acquiring second updating information to determine the target character string group according to the second updating information. The second updating information comprises 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 deleted data are located. The second field value includes a field name and a specific value, and the deleting operation is to delete the whole data in the line where the updated data is located.
For example: the table in which the updated data is located is Car, the data table Car has id, name, price, branch fields in total, the updated data is in a row with id=2, and in the row, name= C, price =20000 and branch=odd, then the second table name is Car, and the second field value is id=2, name= C, price =20000 and branch=odd.
And e23, deleting the target character string group, the cache value corresponding to the target character string group and the character index corresponding to the target character string group from the cache.
After the target character string group is determined, a cache value and a character index corresponding to the target character string group are determined, and the target character string group, the cache value and the character index are deleted from the cache. If the target string set and the cached value are stored in the cache in the form of key-value pairs, the target string set is a key.
In an alternative embodiment, step e21 includes: step e211, step e212, step e213, step e214, step e215.
e211, respectively taking 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 a first updating condition.
Taking the above example as an example, the first table name is Car, the first target field is name, the updated data is a, the updated data is B, the first field value is id=1, price=10000, and branch=some Ji, and the first update condition is that: name= A, name = B, id =1, price=10000, branch=some gimbals.
Step e212, determining whether there is a target primary index in the cache that matches the first table name.
Each first level index in the cache is traversed to determine if there is a first level index in the cache that exactly matches Car.
If there is a matching target primary index, step e213 determines, for each first update condition, whether there is a target secondary index matching the first update condition in the cache under the target primary index.
If there is a first level index that exactly matches Car, then the first level index is the target level index.
The process of finding the target string group is described below with reference to fig. 2. Fig. 2 is a schematic diagram of a target string group search procedure according to an embodiment of the present application.
As shown in fig. 2, there are two branches under the first level index Car, the first main branch is id=1, the second main branch is branch=a certain gide, the second main branch includes three sub-branches, the first sub-branch is branch=a certain gide→id=1→name, the second sub-branch is branch=a certain gide→id=2→price, and the third sub-branch is branch=a certain gide→name=a→id. The second level index under the second main branch includes id=1, branch=some giddy→id=1, branch=some giddy→id=2, branch=some giddy→name=a. The third level index under the second main branch includes name, price, id.
After determining the target primary index, under the target primary index Car, it is determined whether there is a second-level index that exactly matches each of name= A, name = B, id =1, price=10000, and branch=some Ji.
Since there is an id=1 under the first main branch that matches exactly with id=1 in the first update condition, the third level index can continue to be looked up down.
Since there is a branch=some Ji under the second branch, a perfect match with the branch=some Ji in the first update condition can continue matching along the three sub-branches. When the sub-branches are matched, as id=1 exists under the first sub-branch and is matched with id=1 in the first updating condition, the third-level index can be continuously searched downwards along the first sub-branch; since id=2 exists under the second sub-branch, and is not matched with any one of the first updating conditions, the search cannot be performed downwards, and the sub-branch is ended, and the search is ended by a dotted line; since there is a name=a under the third sub-branch that matches exactly with name=a in the first update condition, the third level index may continue to be looked up down along the third sub-branch.
That is, if the second level index includes a plurality of sub-branches, and some sub-branches include a plurality of sub-levels, it is necessary that the first update conditions in all sub-levels under the sub-branches have conditions that match in the first update conditions to treat the sub-branch as the target second level index.
Step e214, if there is a matching target secondary index, determining whether there is a target tertiary index matching the first target field in the cache under the target secondary index.
Under the first main branch, since the third level index is name, and is completely matched with the first target field, the third level index is taken as the target third level index.
Under the second main branch, as the third-level index under the first sub-branch is name and is completely matched with the first target field, the third-level index under the first sub-branch is taken as the target third-level index; because the third-level index under the second sub-branch is the price and is not matched with the first target field, the third-level index under the second sub-branch cannot be used as the target third-level index; since the third level index under the third sub-branch is id, and does not match the first target field, the third level index under the third sub-branch cannot be used as the target level index.
And e215, if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
And storing a corresponding character string group under each third-level index, and taking the character string group under the target third-level index as a target character string group. Since the third level index under the first main branch is the target three level index, car: name: id=1 under the target three level index is set as the target string group, and Car: name: id=1 & branch=some Ji is set as the target string group.
In an alternative embodiment, step e22 includes: step e221, step e222, step e223, step e224, step e225.
Step e221, taking each second field value as a second updating condition.
Taking the above example as an example, the second table name is Car, the second field value is id=1, name= A, price =10000, branch=some Ji, and the second update condition is obtained: id=1, name= A, price =10000, branch=some gimbals.
Step e222, determining whether there is a target primary index in the cache that matches the second table name.
Each first level index in the cache is traversed and a determination is made as to whether there is a first level index in the cache that exactly matches Car.
If there is a matching target primary index, step e223, determining, for each second update condition, whether there is a target secondary index matching the second update condition in the cache under the target primary index.
Taking fig. 2 as an example, the whole process is the same as the modification operation, and will not be described here again.
If there is a matching target secondary index, step e224 determines, under the target secondary index, whether there is a target tertiary index matching the second target field in the cache.
Here, the second target field is all the fields in the data table corresponding to the second table name.
The search results under the first main branch, the first sub-branch, and the second sub-branch are the same as the search results at the time of the modifying operation, but are different for the third sub-branch. Under the second main branch, since the third level index under the third sub-branch is id and the second target field is all fields, that is, the second target field includes id fields, the third level index under the third sub-branch is completely matched with the id fields in the second target field, and then the third level index under the third sub-branch is taken as the target third level index.
And e225, if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
Similarly, each third-level index stores a corresponding string group, and the determined string group under the target third-level index is used as a target string group.
And taking the third-level index under the first main branch as a target three-level index, taking the car:name:id=1 under the target three-level index as a target character string group, and taking the car:name:id=1 & branch=a certain Ji and car:id:branch=a certain Ji & name=A indicated by the first sub branch and the third sub branch under the second main branch as the target character string group.
In step S104, the final data query result is a query result corresponding to the database query term, which is exemplified by the above example, i.e., the final query result of the database query term "select name, price from Car where id =1".
The database query result is obtained only under the condition that the completely matched target character string group does not exist in the cache, if the completely matched target character string group exists in the cache, the corresponding query result is obtained from the cache, and the database query result and the cache query result are required to be combined together to obtain the final data query result.
In an alternative embodiment, after step S102, the method further includes: step f1.
And f1, if a target character string group which is completely matched with the character string group exists, taking a cache value corresponding to the target character string group as a cache query result.
If the string group "Car: name: id=1" exists in the cache, it is determined that there exists a target string group that is completely matched with the string group a in the cache, where 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-sentence a, for example: and 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 exists a target string group that is completely matched with the string group B, where "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-sentence B, for example: and if the cache value is 90000, the cache query result of the query sub-statement B is 90000.
In an alternative embodiment, step S104 includes: step f2.
And f2, combining the database query result with the cache query result to obtain a final data query result.
And obtaining a cache query result, combining the cache query result with a database query result, and jointly using the cache query result and the database query result as a final data query result.
Compared with the data query method in the prior art, the method has the advantages that one database query statement can be split into a plurality of query sub-statements, the character string group corresponding to each query sub-statement is constructed, the data which are not queried is determined through matching of the character string groups, the data which are not queried are queried from the database through the regenerated recombinant query statement, the data which are not queried are stored in the cache, the data which are not queried are converted into queried data, so that the queried data stored in the cache can be directly used in the next query, the data query efficiency is improved, and the problem of low data query efficiency is solved.
Based on the same inventive concept, the embodiment of the present application further provides a data query device corresponding to the data query method, and since the principle of the device in the embodiment of the present application for solving the problem is similar to that of the data query method in the embodiment of the present application, the implementation of the device may refer to the implementation of the method, and the repetition is omitted.
Referring to fig. 3, fig. 3 is a schematic structural diagram of a data query device according to an embodiment of the present application. As shown in fig. 3, the data query device 200 includes:
the statement splitting module 201 is configured to split a database query statement according to a field dimension to obtain a plurality of query sub-statements, where each query sub-statement includes a table name, a query condition, and a query field;
the character string group construction module 202 is configured to construct, for each query sub-sentence, a character string group corresponding to the query sub-sentence according to a table name, a query condition and a query field of the query sub-sentence, and determine whether a target character string group that is completely matched with the character string group exists in the cache;
the database query module 203 is configured to reorganize, if not, all query sub-sentences that do not have the completely matched target character string, generate a reorganized query sentence, obtain a database query result corresponding to the reorganized query sentence from a database, and store the database query result and the character string group in a cache in association;
the result determining module 204 is configured to obtain a final data query result of the database query statement according to the database query result.
In a possible embodiment, the string configuration modeling block 202 includes a length comparison module, a conversion module, and a first combination module, where the length comparison module is configured to: determining whether the character string length of the query condition is greater than a set length threshold; the conversion module is used for: the length of the character string is larger than a set length threshold value, and the query condition is converted into an encryption value with a preset length; the first combination module is used for: and connecting the table name, the query field and the encryption value together through a preset interval symbol to obtain a character string group.
In a possible embodiment, the string organization modeling block 202 is further specifically configured to: for each character string group, determining whether a character index matched with the character string group exists in a cache; if the character index matched with the character string group does not exist, the character index of the character string group is constructed by taking the table name corresponding to the character string group as a first-level index, taking the query condition corresponding to the character string group as a second-level index and taking the query field corresponding to the character string group as a third-level index.
In a possible embodiment, the query condition includes a plurality of sub-query conditions, and the plurality of sub-query conditions have a logical operation relationship, and the string configuration modeling block 202 is further specifically configured to: determining a logical operation relation among a plurality of sub-query conditions; if the sub-query conditions are logical OR, establishing a second-level index in the form of different branches; if the sub-query conditions are logically AND, a second-level index is built in the form of different sub-levels under the same branch according to the field name sequence.
In a possible embodiment, the data query device 200 further includes a data update module (not shown in the figure), where the data update module includes a parsing module, a first update sub-module, and a second update sub-module, and the parsing module is configured to: when the database is updated, analyzing an operation log of the database to obtain update information of updated data, wherein the update information comprises an update type, first update information and second update information, the first update information is update information when the updated data is modified, and the second update information is update information when the updated data is deleted; the first update submodule is used for: if the update type is modification, determining a target character string group when the updated data is modified according to the first update information; the second update sub-module is used for: if the update type is deleting, determining a target character string group when the updated data is deleted according to the second update information; and deleting the target character string group, the cache value corresponding to the target character string group and the character index corresponding to the target character string group from the cache.
In a possible implementation manner, the first update information includes a first table name, a first target field, updated data of the updated data, and a first field value, where the first field value is a value of the updated data after updating other fields in the row except the field where the updated data is located, and the first target field is the field where the updated data is located; the first updating sub-module is specifically configured to: respectively taking 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 updating conditions; determining whether a target primary index matched with the first table name exists in the cache; if a matched target primary index exists, determining whether a target secondary index matched with the first updating condition exists in a cache or not according to each first updating condition under the target primary index; if the matched target secondary index exists, determining whether a target tertiary index matched with the first target field exists in the cache under the target secondary index; and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
In a possible implementation manner, 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 where the deleted data is located; the second updating sub-module is specifically configured to: taking each second field value as a second updating condition; determining whether a target primary index matched with the second table name exists in the cache; if a matched target primary index exists, determining whether a target secondary index matched with each second updating condition exists in the cache or not according to each second updating condition under the target primary index; if the matched target secondary index exists, determining whether a target tertiary index matched with a second target field exists in the cache under the target secondary index; and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
In a possible embodiment, the database query module 203 includes a sentence reorganization module for: taking the query sub-statement without the completely matched target character string as the query sub-statement to be recombined; extracting a table name, a query condition and a query field in each query sub-statement to be recombined aiming at each query sub-statement to be recombined; and reorganizing table names, query conditions and query fields corresponding to the plurality of sub-sentences to be reorganized, and obtaining reorganized query sentences based on the reorganized table names, query conditions and query fields.
In a possible embodiment, the database query result includes a plurality of database query sub-results, each corresponding to a query sub-statement, and the database query module 203 further includes a result storage module for: and storing the character string group corresponding to each database query sub-result and the database query sub-result in a buffer memory in the form of key value pairs aiming at each database query sub-result.
In a possible embodiment, the data query device 200 further includes a cache query module (not shown in the figure), where the cache query module is configured to: if the target character string group which is completely matched with the character string group exists, the cache value corresponding to the target character string group is used as a cache query result.
In a possible embodiment, the result determining module 204 is specifically configured to: and combining the database query result with the cache query result to obtain a final data query result.
In a possible embodiment, the string organization modeling block 202 further includes a second combination module for: if the length of the character string is smaller than or equal to the set length threshold, directly connecting the table name, the query field and the query condition together through a preset interval symbol to obtain the character string group.
By means of the method, a database query statement can be split into a plurality of query sub-statements, the character string group corresponding to each query sub-statement is constructed, the data which are not queried is determined through matching of the character string groups, the data which are not queried are queried from the database through the regenerated recombinant query statement, the data which are not queried are stored in the cache, the data which are not queried are converted into queried data, so that the queried data stored in the cache can be directly used in next query, data query efficiency is improved, and the problem of low data query efficiency is solved.
Referring to fig. 4, fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in fig. 4, the electronic device 300 includes a processor 310, a memory 320, and a bus 330.
The memory 320 stores machine readable instructions executable by the processor 310, the processor 310 and the memory 320 in communication via a bus 330 when the electronic device 300 is running, the processor 310 executing the machine readable instructions, the processor 310 method steps being performed by the preamble of the processor 310 method steps of:
Splitting a database query statement according to a field dimension to obtain a plurality of query sub-statements, wherein each query sub-statement comprises a table name, a query condition and a query field;
constructing a character string group corresponding to each query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, and determining whether a target character string group completely matched with the character string group exists in a cache;
if not, reorganizing all query sub-sentences without completely matched target character strings to generate reorganized query sentences, acquiring database query results corresponding to the reorganized query sentences from a database, and storing the database query results and character string groups in a cache in an associated manner;
and obtaining a final data query result of the database query statement according to the database query result.
In a possible embodiment, the processor 310 is specifically configured to, when executing the constructing the string group corresponding to the query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence: determining whether the character string length of the query condition is greater than a set length threshold; if the length of the character string is greater than the set length threshold, converting the query condition into an encryption value with a preset length; and connecting the table name, the query field and the encryption value together through a preset interval symbol to obtain a character string group.
In a possible embodiment, after executing the constructing the string group corresponding to the query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, the processor 310 is further specifically configured to: for each character string group, determining whether a character index matched with the character string group exists in a cache; if the character index matched with the character string group does not exist, the character index of the character string group is constructed by taking the table name corresponding to the character string group as a first-level index, taking the query condition corresponding to the character string group as a second-level index and taking the query field corresponding to the character string group as a third-level index.
In a possible embodiment, the query condition includes a plurality of sub-query conditions, and the plurality of sub-query conditions have a logical operation relationship, and the processor 310 is specifically configured to, when executing the character index for constructing the character string group: determining a logical operation relation among a plurality of sub-query conditions; if the sub-query conditions are logical OR, establishing a second-level index in the form of different branches; if the sub-query conditions are logically AND, a second-level index is built in the form of different sub-levels under the same branch according to the field name sequence.
In a possible embodiment, the processor 310 is further configured to: when the database is updated, analyzing an operation log of the database to obtain update information of updated data, wherein the update information comprises an update type, first update information and second update information, the first update information is update information when the updated data is modified, and the second update information is update information when the updated data is deleted; if the update type is modification, determining a target character string group when the updated data is modified according to the first update information; if the update type is deleting, determining a target character string group when the updated data is deleted according to the second update information; and deleting the target character string group, the cache value corresponding to the target character string group and the character index corresponding to the target character string group from the cache.
In a possible implementation manner, the first update information includes a first table name, a first target field, updated data of the updated data, and a first field value, where the first field value is a value of the updated data after updating other fields in the row except the field where the updated data is located, and the first target field is the field where the updated data is located; the processor 310 is specifically configured to, when executing the target string group when determining that the updated data is modified according to the first update information: respectively taking 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 updating conditions; determining whether a target primary index matched with the first table name exists in the cache; if a matched target primary index exists, determining whether a target secondary index matched with the first updating condition exists in a cache or not according to each first updating condition under the target primary index; if the matched target secondary index exists, determining whether a target tertiary index matched with the first target field exists in the cache under the target secondary index; and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
In a possible implementation manner, 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 where the deleted data is located; the processor 310 is specifically configured to, when executing the determining, according to the second update information, the target string group when the updated data is deleted: taking each second field value as a second updating condition; determining whether a target primary index matched with the second table name exists in the cache; if a matched target primary index exists, determining whether a target secondary index matched with each second updating condition exists in the cache or not according to each second updating condition under the target primary index; if the matched target secondary index exists, determining whether a target tertiary index matched with a second target field exists in the cache under the target secondary index; and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
In a possible implementation, the processor 310 is specifically configured to, when executing the reorganizing of all query sub-sentences that do not have completely matched target strings to generate a reorganized query sentence: taking the query sub-statement without the completely matched target character string as the query sub-statement to be recombined; extracting a table name, a query condition and a query field in each query sub-statement to be recombined aiming at each query sub-statement to be recombined; and reorganizing table names, query conditions and query fields corresponding to the plurality of sub-sentences to be reorganized, and obtaining reorganized query sentences based on the reorganized table names, query conditions and query fields.
In a possible embodiment, the database query result includes a plurality of database query sub-results, each corresponding to a query sub-statement, and the processor 310 is specifically configured, when executing and storing the database query result in the cache in association with the string set: and storing the character string group corresponding to each database query sub-result and the database query sub-result in a buffer memory in the form of key value pairs aiming at each database query sub-result.
In a possible embodiment, the processor 310 is further specifically configured to, after executing the determining whether the target string group that is completely matched with the string group exists in the cache: if the target character string group which is completely matched with the character string group exists, the cache value corresponding to the target character string group is used as a cache query result.
In a possible embodiment, the processor 310 is specifically configured to, when executing the final data query result obtained from the database query result, obtain the final data query result of the database query statement: and combining the database query result with the cache query result to obtain a final data query result.
In a possible embodiment, the processor 310 is further specifically configured to, after executing the determining whether the string length of the query condition is greater than the set length threshold: if the length of the character string is smaller than or equal to the set length threshold, directly connecting the table name, the query field and the query condition together through a preset interval symbol to obtain the character string group.
By means of the method, a database query statement can be split into a plurality of query sub-statements, the character string group corresponding to each query sub-statement is constructed, the data which are not queried is determined through matching of the character string groups, the data which are not queried are queried from the database through the regenerated recombinant query statement, the data which are not queried are stored in the cache, the data which are not queried are converted into queried data, so that the queried data stored in the cache can be directly used in next query, data query efficiency is improved, and the problem of low data query efficiency is solved.
The embodiments of the present application also provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of:
splitting a database query statement according to a field dimension to obtain a plurality of query sub-statements, wherein each query sub-statement comprises a table name, a query condition and a query field;
constructing a character string group corresponding to each query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, and determining whether a target character string group completely matched with the character string group exists in a cache;
If not, reorganizing all query sub-sentences without completely matched target character strings to generate reorganized query sentences, acquiring database query results corresponding to the reorganized query sentences from a database, and storing the database query results and character string groups in a cache in an associated manner;
and obtaining a final data query result of the database query statement according to the database query result.
In a possible implementation manner, the processor is specifically configured to, when executing the constructing the string group corresponding to the query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence: determining whether the character string length of the query condition is greater than a set length threshold; if the length of the character string is greater than the set length threshold, converting the query condition into an encryption value with a preset length; and connecting the table name, the query field and the encryption value together through a preset interval symbol to obtain a character string group.
In a possible implementation manner, after executing the constructing the string group corresponding to the query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, the processor is further specifically configured to: for each character string group, determining whether a character index matched with the character string group exists in a cache; if the character index matched with the character string group does not exist, the character index of the character string group is constructed by taking the table name corresponding to the character string group as a first-level index, taking the query condition corresponding to the character string group as a second-level index and taking the query field corresponding to the character string group as a third-level index.
In a possible embodiment, the query condition includes a plurality of sub-query conditions, and the plurality of sub-query conditions have a logical operation relationship, and the processor is specifically configured to, when executing the character index for constructing the character string group: determining a logical operation relation among a plurality of sub-query conditions; if the sub-query conditions are logical OR, establishing a second-level index in the form of different branches; if the sub-query conditions are logically AND, a second-level index is built in the form of different sub-levels under the same branch according to the field name sequence.
In a possible embodiment, the processor is further configured to: when the database is updated, analyzing an operation log of the database to obtain update information of updated data, wherein the update information comprises an update type, first update information and second update information, the first update information is update information when the updated data is modified, and the second update information is update information when the updated data is deleted; if the update type is modification, determining a target character string group when the updated data is modified according to the first update information; if the update type is deleting, determining a target character string group when the updated data is deleted according to the second update information; and deleting the target character string group, the cache value corresponding to the target character string group and the character index corresponding to the target character string group from the cache.
In a possible implementation manner, the first update information includes a first table name, a first target field, updated data of the updated data, and a first field value, where the first field value is a value of the updated data after updating other fields in the row except the field where the updated data is located, and the first target field is the field where the updated data is located; the processor is specifically configured to, when executing the target string group when determining that the updated data is modified according to the first update information: respectively taking 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 updating conditions; determining whether a target primary index matched with the first table name exists in the cache; if a matched target primary index exists, determining whether a target secondary index matched with the first updating condition exists in a cache or not according to each first updating condition under the target primary index; if the matched target secondary index exists, determining whether a target tertiary index matched with the first target field exists in the cache under the target secondary index; and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
In a possible implementation manner, 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 where the deleted data is located; the processor is specifically configured to, when executing the target string group when determining that the updated data is deleted according to the second update information: taking each second field value as a second updating condition; determining whether a target primary index matched with the second table name exists in the cache; if a matched target primary index exists, determining whether a target secondary index matched with each second updating condition exists in the cache or not according to each second updating condition under the target primary index; if the matched target secondary index exists, determining whether a target tertiary index matched with a second target field exists in the cache under the target secondary index; and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
In a possible implementation manner, the processor is specifically configured to, when executing the reorganizing of all query sub-sentences that do not have completely matched target strings to generate a reorganized query sentence: taking the query sub-statement without the completely matched target character string as the query sub-statement to be recombined; extracting a table name, a query condition and a query field in each query sub-statement to be recombined aiming at each query sub-statement to be recombined; and reorganizing table names, query conditions and query fields corresponding to the plurality of sub-sentences to be reorganized, and obtaining reorganized query sentences based on the reorganized table names, query conditions and query fields.
In a possible implementation, the database query result includes a plurality of database query sub-results, each corresponding to a query sub-statement, and the processor is specifically configured, when executing and storing the database query result in association with the string group in the cache: and storing the character string group corresponding to each database query sub-result and the database query sub-result in a buffer memory in the form of key value pairs aiming at each database query sub-result.
In a possible embodiment, the processor is further specifically configured to, after executing the determining whether the target string group that completely matches the string group exists in the cache: if the target character string group which is completely matched with the character string group exists, the cache value corresponding to the target character string group is used as a cache query result.
In a possible embodiment, the processor is specifically configured to, when executing the final data query result obtained from the database query result, obtain the final data query result of the database query statement: and combining the database query result with the cache query result to obtain a final data query result.
In a possible embodiment, the processor is further specifically configured to, after executing the determining whether the string length of the query condition is greater than the set length threshold: if the length of the character string is smaller than or equal to the set length threshold, directly connecting the table name, the query field and the query condition together through a preset interval symbol to obtain the character string group.
By means of the method, a database query statement can be split into a plurality of query sub-statements, the character string group corresponding to each query sub-statement is constructed, the data which are not queried is determined through matching of the character string groups, the data which are not queried are queried from the database through the regenerated recombinant query statement, the data which are not queried are stored in the cache, the data which are not queried are converted into queried data, so that the queried data stored in the cache can be directly used in next query, data query efficiency is improved, and the problem of low data query efficiency is solved.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, and are not repeated herein.
In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. The above-described apparatus embodiments are merely illustrative, for example, the division of the units is merely a logical function division, and there may be other manners of division in actual implementation, and for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, device or unit indirect coupling or communication connection, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer readable storage medium executable by a processor. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Finally, it should be noted that: the foregoing examples are merely specific embodiments of the present application, and are not intended to limit the scope of the present application, but the present application is not limited thereto, and those skilled in the art will appreciate that while the foregoing examples are described in detail, the present application is not limited thereto. Any person skilled in the art may modify or easily conceive of the technical solution described in the foregoing embodiments, or make equivalent substitutions for some of the technical features within the technical scope of the disclosure of the present application; such modifications, changes or substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (15)

1. A method of querying data, comprising:
splitting a database query statement according to a field dimension to obtain a plurality of query sub-statements, wherein each query sub-statement comprises a table name, a query condition and a query field;
constructing a character string group corresponding to each query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, and determining whether a target character string group which is completely matched with the character string group exists in a cache;
If not, reorganizing all query sub-sentences without completely matched target character strings to generate reorganized query sentences, acquiring database query results corresponding to the reorganized query sentences from a database, and storing the database query results and character string groups in a cache in an associated manner;
and obtaining a final data query result of the database query statement according to the database query result.
2. The method of claim 1, wherein the constructing the string group corresponding to the query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence comprises:
determining whether the character string length of the query condition is greater than a set length threshold;
if the length of the character string is larger than a set length threshold, converting the query condition into an encryption value with a preset length;
and connecting the table name, the query field and the encryption value together through a preset interval symbol to obtain a character string group.
3. The method according to claim 1, further comprising, after constructing the string group corresponding to the query sub-sentence according to the table name, the query condition, and the query field of the query sub-sentence:
For each character string group, determining whether a character index matched with the character string group exists in a cache;
if the character index matched with the character string group does not exist, the character index of the character string group is constructed by taking the table name corresponding to the character string group as a first-level index, taking the query condition corresponding to the character string group as a second-level index and taking the query field corresponding to the character string group as a third-level index.
4. The method of claim 3, wherein the query conditions include a plurality of sub-query conditions, a logical operation relationship exists between the plurality of sub-query conditions, and the constructing the character index of the character string group includes:
determining a logical operation relation among a plurality of sub-query conditions;
if the sub-query conditions are logical OR, establishing a second-level index in the form of different branches;
if the sub-query conditions are logically AND, a second-level index is built in the form of different sub-levels under the same branch according to the field name sequence.
5. The method according to claim 1, wherein the method further comprises:
when the database is updated, analyzing an operation log of the database to obtain update information of updated data, wherein the update information comprises an update type, first update information and second update information, the first update information is update information when the updated data is modified, and the second update information is update information when the updated data is deleted;
If the update type is modification, determining a target character string group when the updated data is modified according to the first update information;
if the update type is deleting, determining a target character string group when the updated data is deleted according to the second update information;
and deleting the target character string group, the cache value corresponding to the target character string group and the character index corresponding to the target character string group from the cache.
6. The method of claim 5, wherein the first update information includes a first table name, a first target field, the updated data, updated data of the updated data, a first field value, the first field value being an updated value of the remaining fields in the row of the updated data except for the field in which the updated data is located, the first target field being the field in which the updated data is located;
the determining, according to the first update information, a target string group when the updated data is modified, including:
taking 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 updating conditions respectively;
Determining whether a target primary index matched with the first table name exists in a cache;
if a matched target primary index exists, determining whether a target secondary index matched with each first updating condition exists in a cache or not according to each first updating condition under the target primary index;
if a matched target secondary index exists, determining whether a target tertiary index matched with the first target field exists in a cache under the target secondary index;
and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
7. The method of claim 5, wherein the second update information includes a second table name, a second field value, the second field value being the value of all fields in the row in which the deleted data is located;
the determining, according to the second update information, the target string group when the updated data is deleted, includes:
taking each second field value as a second updating condition;
determining whether a target primary index matched with the second table name exists in the cache;
if a matched target primary index exists, determining whether a target secondary index matched with each second updating condition exists in the cache or not according to each second updating condition under the target primary index;
If the matched target secondary index exists, determining whether a target tertiary index matched with a second target field exists in the cache under the target secondary index;
and if the matched target three-level index exists, taking the character string group corresponding to the target three-level index as a target character string group.
8. The method of claim 1, wherein reorganizing all query sub-sentences that do not have a perfect match target string to generate reorganized query sentences comprises:
taking the query sub-statement without the completely matched target character string as the query sub-statement to be recombined;
extracting a table name, a query condition and a query field in each query sub-statement to be recombined aiming at each query sub-statement to be recombined;
and reorganizing table names, query conditions and query fields corresponding to the plurality of sub-sentences to be reorganized, and obtaining reorganized query sentences based on the reorganized table names, query conditions and query fields.
9. The method of claim 1, wherein the database query result comprises a plurality of database query sub-results, each corresponding to a query sub-statement, the storing the database query result in association with a string set in a cache, comprising:
And storing the character string group corresponding to each database query sub-result and the database query sub-result in a buffer memory in the form of key value pairs aiming at each database query sub-result.
10. The method of claim 1, further comprising, after said determining if there is a target string set in the cache that exactly matches the string set:
and if the target character string group which is completely matched with the character string group exists, taking the cache value corresponding to the target character string group as a cache query result.
11. The method of claim 10, wherein obtaining a final data query result of the database query statement based on the database query result comprises:
and combining the database query result with the cache query result to obtain a final data query result.
12. The method of claim 2, further comprising, after said determining whether the string length of the query condition is greater than a set length threshold:
if the length of the character string is smaller than or equal to the set length threshold, directly connecting the table name, the query field and the query condition together through a preset interval symbol to obtain a character string group.
13. A data query device, comprising:
the statement splitting module is used for splitting the database query statement according to the field dimension to obtain a plurality of query sub-statements, wherein each query sub-statement comprises a table name, a query condition and a query field;
the character string group construction module is used for constructing a character string group corresponding to each query sub-sentence according to the table name, the query condition and the query field of the query sub-sentence, and determining whether a target character string group which is completely matched with the character string group exists in a cache;
the database query module is used for reorganizing all query sub-sentences without completely matched target character strings if the query sub-sentences do not exist, generating reorganized query sentences, acquiring database query results corresponding to the reorganized query sentences from a database, and storing the database query results and character string groups in a cache in an associated manner;
and the result determining module is used for obtaining the final data query result of the database query statement according to the database query result.
14. An electronic device, comprising: a processor, a storage medium and a bus, the storage medium storing machine-readable instructions executable by the processor, the processor and the storage medium communicating over the bus when the electronic device is running, the processor executing the machine-readable instructions to perform the steps of the data querying method according to any of claims 1 to 12.
15. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps of the data query method of any of claims 1 to 12.
CN202410029113.8A 2024-01-08 2024-01-08 Data query method, device, equipment and medium Pending CN117807113A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410029113.8A CN117807113A (en) 2024-01-08 2024-01-08 Data query method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410029113.8A CN117807113A (en) 2024-01-08 2024-01-08 Data query method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN117807113A true CN117807113A (en) 2024-04-02

Family

ID=90421868

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410029113.8A Pending CN117807113A (en) 2024-01-08 2024-01-08 Data query method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN117807113A (en)

Similar Documents

Publication Publication Date Title
US7827181B2 (en) Click distance determination
US7010522B1 (en) Method of performing approximate substring indexing
JP3849279B2 (en) Index creation method and search method
US7676453B2 (en) Partial query caching
JP3914662B2 (en) Database processing method and apparatus, and medium storing the processing program
TWI549009B (en) Database managing method, database managing system, and database tree structure
US8140546B2 (en) Computer system for performing aggregation of tree-structured data, and method and computer program product therefor
CN111858609B (en) Block chain fuzzy query method and device
US8756246B2 (en) Method and system for caching lexical mappings for RDF data
CN114911826A (en) A method and system for retrieving linked data
CN118170850A (en) Distributed unique index optimization method, system, equipment and storage medium for distributed database system
CN117807113A (en) Data query method, device, equipment and medium
KR101299555B1 (en) Apparatus and method for text search using index based on hash function
JP3859044B2 (en) Index creation method and search method
CN110321346B (en) Method and system for realizing character string hash table
JP2000339332A (en) Medium recording search index, search index updating method, device thereof, and medium recording program thereof
CN113190652B (en) A method, device and storage medium for updating data in a search database
US20230195705A1 (en) Branching for tree structure in database system
KR102013839B1 (en) Method and System for Managing Database, and Tree Structure for Database
JP4319827B2 (en) Document search program
JP4304226B2 (en) Structured document management system, structured document management method and program
KR100319761B1 (en) Frame-partitioned parallel processing method for database retrieval using signature file
JP6764973B1 (en) Related word dictionary creation system, related word dictionary creation method and related word dictionary creation program
CN109002444A (en) Text searching method and full-text search device
CN118535590A (en) A search method, system, device and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination