A data query method and device

By presetting template statements and preprocessing information in the database, generating target execution statements and directly querying, the problem of high computing resources consumption in the database during the analysis and optimization of query statements is solved, and query efficiency is improved.

CN112163000BActive Publication Date: 2025-03-25ALIBABA GROUP HOLDING LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010901686.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-31
Publication Date
2025-03-25
Estimated Expiration
2040-08-31

AI Technical Summary

Technical Problem

In the prior art, the process of lexical and semantic analysis and optimization of query statements consumes a large amount of computing resources, resulting in a long query processing time and reducing database efficiency.

Method used

By presetting the template statement and its corresponding preprocessing information, obtaining the query statement and matching it with the template statement, generating the target execution statement based on the parameter information and preprocessing information, and querying directly from the database to avoid the parsing and optimization process.

Benefits of technology

It improves the database query efficiency, reduces query processing time, and reduces computing resource consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112163000B_ABST
    Figure CN112163000B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a data query method and device, the method comprising: obtaining a query statement; wherein the query statement includes parameter information; searching for a preset template statement matching the query statement, and obtaining preprocessing information corresponding to the template statement; using the preprocessing information and the parameter information to generate a target execution statement; using the target execution statement to query the target data from a preset database. Thus, the query statement sent by the user can be converted into a target execution statement, and the target execution statement can be used to query the target data from the database, so that the database can directly execute the query task without going through the statement parsing optimization process, thereby improving the query efficiency of the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data processing, and in particular to a data query method and a data query device. Background Art

[0002] In the prior art, when a user needs to query data from a database, a query statement can usually be sent to the database. The database can perform lexical and semantic analysis on the query statement, optimize the query statement, formulate an execution plan, and then execute and return the result to the user. The process of the database performing lexical and semantic analysis on the query statement and optimizing the query statement usually consumes certain computing resources and easily leads to a long query statement processing time, thereby reducing the processing efficiency of the database. Summary of the invention

[0003] In view of the above problems, the embodiments of the present application are proposed to provide a data query method and a corresponding data query device that overcome the above problems or at least partially solve the above problems.

[0004] In order to solve the above problems, the present application discloses a data query method, including:

[0005] Obtaining a query statement; wherein the query statement includes parameter information;

[0006] Searching for a preset template statement that matches the query statement, and obtaining preprocessing information corresponding to the template statement;

[0007] Generate a target execution statement using the preprocessing information and the parameter information;

[0008] The target execution statement is used to query the preset database for target data.

[0009] Optionally, the method further comprises:

[0010] If there is no matching template statement for the query statement, generating a template statement according to the query statement;

[0011] Using the template statement, generating a preprocessing statement;

[0012] The prepared statement is sent to the database, and preprocessing information returned by the database is obtained.

[0013] Optionally, the preprocessing information includes preprocessing identification information and parameter type information;

[0014] The method further comprises:

[0015] A mapping relationship between the template statement, the preprocessing identification information, and the parameter type information is generated.

[0016] Optionally, the step of using the preprocessing information and the parameter information to generate a target execution statement includes:

[0017] The target execution statement is generated by using the preprocessing information, the parameter information, and the preset encoding identification information; the encoding identification information is used to indicate that the data returns the target data encoded based on the text protocol.

[0018] Optionally, the step of searching for a preset template statement matching the query statement includes:

[0019] A template statement that is identical to the query statement except for the parameter information is searched as a preset template statement that matches the query statement.

[0020] Optionally, the step of searching for a preset template statement matching the query statement includes:

[0021] Determining whether the query statement conforms to a preset format;

[0022] When the query statement conforms to a preset format, searching for a preset template statement matching the query statement;

[0023] If the query statement does not conform to a preset format, the query statement is forwarded to the database.

[0024] The embodiment of the present application also discloses a data query method, which is applied to a query processing middleware, wherein the query processing middleware communicates with a client and a database at the same time; the method comprises:

[0025] The query processing middleware obtains the query statement sent by the client; wherein the query statement includes parameter information;

[0026] The query processing middleware searches for a preset template statement matching the query statement, and obtains preprocessing information corresponding to the template statement;

[0027] The query processing middleware uses the preprocessing information and the parameter information to generate a target execution statement;

[0028] The query processing middleware sends the target execution statement to the database and obtains the target data returned by the database;

[0029] The query processing middleware returns the target data to the client.

[0030] The present application also discloses a data query device, including:

[0031] A first query statement acquisition module, used to acquire a query statement; wherein the query statement includes parameter information;

[0032] A first target statement search module is used to search for a preset template statement matching the query statement and obtain preprocessing information corresponding to the template statement;

[0033] A first target execution statement generating module, configured to generate a target execution statement using the preprocessing information and the parameter information;

[0034] The first query module is used to use the target execution statement to query the target data from a preset database.

[0035] Optionally, the device further comprises:

[0036] A template generation module, used for generating a template statement according to the query statement when there is no matching template statement for the query statement;

[0037] A prepared statement generation module, used to generate a prepared statement using the template statement;

[0038] The preprocessing information acquisition module is used to send the preprocessing statement to the database and obtain the preprocessing information returned by the database.

[0039] Optionally, the preprocessing information includes preprocessing identification information and parameter type information;

[0040] The device also includes:

[0041] A mapping generation module is used to generate a mapping relationship between the template statement, the preprocessing identification information, and the parameter type information.

[0042] Optionally, the first target execution statement generating module includes:

[0043] The target execution statement generation submodule is used to generate a target execution statement using the preprocessing information, the parameter information, and preset encoding identification information; the encoding identification information is used to indicate that the data returns target data encoded based on a text protocol.

[0044] Optionally, the first target sentence search module includes:

[0045] The first target statement search submodule is used to search for a template statement that is identical to the query statement except for the parameter information, as a preset template statement that matches the query statement.

[0046] Optionally, the first target sentence search module includes:

[0047] A format determination submodule, used to determine whether the query statement conforms to a preset format;

[0048] A second target statement search submodule is used to search for a preset template statement matching the query statement when the query statement conforms to a preset format;

[0049] The forwarding submodule is used to forward the query statement to the database when the query statement does not conform to a preset format.

[0050] In an embodiment of the present application, a data query device is disclosed, which is applied to a query processing middleware, and the query processing middleware communicates with a client and a database at the same time; the device is deployed in the query processing middleware, and the device includes:

[0051] A second query statement acquisition module, used to acquire the query statement sent by the client; wherein the query statement includes parameter information;

[0052] A second target statement search module is used to search for a preset template statement matching the query statement and obtain preprocessing information corresponding to the template statement;

[0053] A second target execution statement generating module, configured to generate a target execution statement using the preprocessing information and the parameter information;

[0054] A second query module, used for sending the target execution statement to the database and obtaining the target data returned by the database;

[0055] A data returning module is used to return the target data to the client.

[0056] The present application also discloses a device, including:

[0057] one or more processors; and

[0058] One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, cause the device to perform one or more methods as described in the embodiments of the present application.

[0059] The embodiments of the present application also disclose one or more machine-readable media on which instructions are stored, which, when executed by one or more processors, enable the processors to execute one or more methods described in the embodiments of the present application.

[0060] The embodiments of the present application include the following advantages:

[0061] Through the data query method of the embodiment of the present application, a query statement is obtained; wherein the query statement includes parameter information; a preset template statement matching the query statement is searched, and preprocessing information corresponding to the template statement is obtained; a target execution statement is generated using the preprocessing information and the parameter information; and the target execution statement is used to query the target data from the preset database. Thus, the query statement sent by the user can be converted into a target execution statement, and the target execution statement is used to query the target data from the database, so that the database can directly execute the query task without going through the statement parsing optimization process, thereby improving the query efficiency of the database. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] Figure 1 It is a flowchart of the steps of an embodiment of a data query method of the present application;

[0063] Figure 2 It is a flowchart of the steps of an embodiment of a data query method of the present application;

[0064] Figure 3 It is a flowchart of the steps of an embodiment of a data query method of the present application;

[0065] Figure 4 is a schematic diagram of an embodiment of a data query method of the present application;

[0066] Figure 5 It is a structural block diagram of an embodiment of a data query device of the present application;

[0067] Figure 6 It is a structural block diagram of an embodiment of a data query device of the present application;. DETAILED DESCRIPTION

[0068] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0069] The embodiment of the present application aims at the situation that the process of optimizing the query statement while performing lexical and semantic analysis on the query statement by the database reduces the efficiency of the database. By presetting the template statement and the preprocessing information corresponding to the template statement, after obtaining the query statement, the query statement can be matched with the template statement, and based on the parameter information of the query statement and the preprocessing information corresponding to the template statement matching the query statement, a target execution statement is generated, and the target execution statement is used to query the database. After obtaining the target execution statement, the database can directly use the target execution statement to execute the data query task and return the data query result without parsing and optimizing the target execution statement, thereby improving the processing efficiency of the database.

[0070] Reference Figure 1 , shows a flowchart of a data query method embodiment of the present application, which may specifically include the following steps:

[0071] Step 101, obtaining a query statement; wherein the query statement includes parameter information;

[0072] In an embodiment of the present application, a query statement sent by a user may be obtained. The query statement may be used to query target data from a preset database. The query statement may include parameter information, and the parameter information may be information of a variable number of parameters in the query statement. For example, in the query statement "select name from a limit 1", 1 may be the parameter information.

[0073] Step 102, searching for a preset template statement matching the query statement, and obtaining preprocessing information corresponding to the template statement;

[0074] In an embodiment of the present application, a plurality of preset template statements and corresponding relationships between the template statements and preprocessing information may be stored. A preset template statement matching the query statement may be searched, and preprocessing information corresponding to the template statement may be obtained according to the corresponding relationship between the template statement and the preprocessing information.

[0075] The preprocessing information may be information obtained by pre-parsing the template statement by the database, so that the database can use the preprocessing information to execute a query task similar to the template statement, without having to parse the obtained statement again, and can directly execute the data query task based on the preprocessing information.

[0076] In a specific implementation, if the template statement is identical to the query statement except for the parameter information, then it can be considered that the query statement matches the template statement.

[0077] Step 103, using the preprocessing information and the parameter information to generate a target execution statement;

[0078] In the embodiment of the present application, the preprocessing information and the parameter information may be used to generate a target execution statement, which may be used to query the same target data as the query statement.

[0079] Step 104: Use the target execution statement to query the preset database for target data.

[0080] In an embodiment of the present application, the target execution statement can be used to query the target data from a preset database. Since the target execution statement includes the preprocessing information, the database does not need to parse the target execution statement again, but can directly use the preprocessing information and the parameter information included in the target execution statement to execute the query task and query the target data.

[0081] Therefore, for the query statement sent by the user, if there is an existing template statement, the query statement can be converted into a target execution statement, and the target execution statement is used to query the preset data for the target data. Therefore, the database can directly execute the query task without re-analyzing the obtained target execution statement, and query to obtain the target data, thereby improving the query processing efficiency.

[0082] As an example of the present application, the query statement is "select*from a limit 1". After finding a template statement matching the query statement, the preprocessing information corresponding to the template statement can be obtained, and the target execution statement can be generated by using the preprocessing information and the parameter information. The database can use the preprocessing information and the parameter information contained in the target execution statement to know that the user wants to query "select*from a limit1", and execute the query task to return the target data.

[0083] In a specific implementation, a middleware can be preset, and the middleware can communicate with the user and the database at the same time. The middleware stores a number of preset template statements and the corresponding relationship between the template statements and the preprocessing information. After obtaining the query statement sent by the user, the middleware can search for the preset template statement that matches the query statement, and obtain the preprocessing information corresponding to the template statement, and use the preprocessing information and the parameter information to generate a target execution statement, and use the target execution statement to query the preset database for target data. After the middleware obtains the target data, it can return the target data to the user. Therefore, the middleware can assist the user in converting the query statement into the target execution statement and improve the query efficiency. And the user does not need to modify its client or client interface to use the target execution statement to query the target data.

[0084] Through the data query method of the embodiment of the present application, a query statement is obtained; wherein the query statement includes parameter information; a preset template statement matching the query statement is searched, and preprocessing information corresponding to the template statement is obtained; a target execution statement is generated using the preprocessing information and the parameter information; and the target execution statement is used to query the target data from the preset database. Thus, the query statement sent by the user can be converted into a target execution statement, and the target execution statement is used to query the target data from the database, so that the database can directly execute the query task without going through the statement parsing optimization process, thereby improving the query efficiency of the database.

[0085] Reference Figure 2 , shows a flowchart of a data query method embodiment of the present application, which may specifically include the following steps:

[0086] Step 201, obtaining a query statement; wherein the query statement includes parameter information;

[0087] In an embodiment of the present application, a query statement sent by a user may be obtained. The query statement may be used to query target data from a preset database. The query statement may include parameter information, and the parameter information may be information of a variable number of parameters in the query statement. For example, in the query statement "select name from a limit 1", 1 may be the parameter information.

[0088] Step 202, searching for a preset template statement matching the query statement, and obtaining preprocessing information corresponding to the template statement;

[0089] In an embodiment of the present application, a plurality of preset template statements and corresponding relationships between the template statements and preprocessing information may be stored. A preset template statement matching the query statement may be searched, and preprocessing information corresponding to the template statement may be obtained according to the corresponding relationship between the template statement and the preprocessing information.

[0090] The preprocessing information may be information obtained by pre-parsing the template statement by the database, so that the database can use the preprocessing information to execute a query task similar to the template statement, without having to parse the obtained statement again, and can directly execute the data query task based on the preprocessing information.

[0091] In a specific implementation, if the template statement is identical to the query statement except for the parameter information, then it can be considered that the query statement matches the template statement.

[0092] The step of searching for a preset template statement matching the query statement includes:

[0093] S11, searching for a template statement that is identical to the query statement except for the parameter information, as a preset template statement that matches the query statement.

[0094] In an embodiment of the present application, the template statement that matches the query statement may be identical to the query statement except for the parameter information that is different from the query statement. Thus, it is possible to find out whether there is a template statement that is identical to the query statement except for the parameter information as the preset target statement that matches the query statement.

[0095] As an example of the present application, if the query statement is "select*from t limit 1", the template statement matching the query statement may be "select*from t limit?".

[0096] In one embodiment of the present application, the method further includes:

[0097] S21, generating a template statement according to the query statement when there is no matching template statement for the query statement;

[0098] In an embodiment of the present application, when there is no matching template statement for the query statement, a template statement can be generated based on the query statement to facilitate subsequent improvement in the processing efficiency of query statements of the same type.

[0099] In one embodiment of the present application, the step of generating a template statement according to the query statement includes:

[0100] S31, replacing the parameter information in the query statement with the placeholder information to generate a template statement.

[0101] In the embodiment of the present application, since the template statement needs to adapt to the query statement containing different parameter information, the parameter information in the query statement can be replaced with placeholder information, so that the template statement can be generated.

[0102] As an example of the present application, the query statement is "select name from a where id between1and 2", in which the parameter information is "1" and "2". The placeholder "?" can be used to replace the parameter information with "1" and "2" to obtain the template statement "selectname from a where idbetween?and?".

[0103] S22, using the template statement to generate a preprocessing statement;

[0104] In an embodiment of the present application, the template statement may be used to generate a preprocessing statement for acquiring preprocessing information from a database.

[0105] In a specific implementation, the template statement can be used to generate a binary preprocessing statement that complies with the database communication protocol. As a specific implementation of the present application, the preprocessing statement can be a message of the COM_STMT_PREPARE type.

[0106] S23, sending the prepared statement to the database, and obtaining the preprocessing information returned by the database.

[0107] In an embodiment of the present application, the prepared statement may be sent to the database, and the database may parse the prepared statement, generate preprocessing information and return it, so that the preprocessing information returned by the database may be obtained.

[0108] In a specific implementation, the preprocessing information returned by the database may include preprocessing identification information and parameter type information. The preprocessing identification information may be identification information assigned by the database to the prepared statement. The parameter type information is the type of parameter that can be set for the prepared statement recorded in the database. The parameter type may be an integer, a string, etc., which is not limited in this application.

[0109] As an example of the present application, the preprocessing information returned by the database for the prepared statement may include: status (status information), statement_id (preprocessing identification information), num_columns (number of columns), num_params (number of parameters), reserved_1 (reserved filler), warning_count (number of warnings), ParameterDefinitionBlock (parameter type information) and ColumnDefinitionBlock (column definition information).

[0110] In one embodiment of the present application, the step of searching for a preset template statement matching the query statement includes:

[0111] S41, determining whether the query statement conforms to a preset format;

[0112] In an embodiment of the present application, the query statement sent by the user may be in a plurality of different formats. The present application may match the query statement that conforms to the preset format with the template statement and convert it into a target execution statement. For the query statement that does not conform to the format, it may not be processed. Thus, it may be determined whether the query statement conforms to the preset format.

[0113] Among them, the preset format can be set according to actual needs. For example, the preset format can be at least one of a simple query statement, a complex query statement, a multi-table query statement, a nested query statement, and a parameterized query statement. This application does not impose any restrictions on this.

[0114] S42, when the query statement conforms to a preset format, searching for a preset template statement matching the query statement;

[0115] In the embodiment of the present application, if the query statement conforms to the preset format, the query statement can be converted into a target execution statement. A preset template statement matching the query statement can be queried, and the steps of obtaining preprocessing information corresponding to the template statement, using the preprocessing information and the parameter information to generate a target execution statement, and using the target execution statement to query the preset database for target data can be performed.

[0116] S43: If the query statement does not conform to a preset format, forward the query statement to the database.

[0117] In the embodiment of the present application, if the query statement does not conform to the preset format, it is not necessary to convert the query statement into a target execution statement. In this case, the query statement can be directly forwarded to the database, and the database directly parses the query statement and returns the target data.

[0118] In an embodiment of the present application, when the query statement conforms to a preset format, it can be further determined whether the query statement contains parameter information. When the query statement does not contain parameter information, it can be considered that the query statement is not suitable for converting the query statement into a target execution statement. At this time, the query statement can also be directly forwarded to the database, and the database directly parses the query statement and returns the target data.

[0119] In this way, the query statement can be dynamically turned on and off for conversion into a target execution statement. The query statement that conforms to the preset format is converted into a target execution statement, while the query statement that does not conform to the preset format can be directly forwarded to the database, which directly parses and processes the query statement.

[0120] As an example of the present application, the preset format may be a non-parameterized query statement. In the case where the query statement obtained is a non-parameterized query statement, the query statement may be converted into a target execution statement, a preset template statement matching the query statement is executed to query, and preprocessing information corresponding to the template statement is obtained, the preprocessing information and the parameter information are used to generate a target execution statement, and the target execution statement is used to query the preset database for target data. In the case where the query statement obtained is a parameterized query statement, it is not necessary to process the query statement at this time, and the query statement may be directly forwarded to the database.

[0121] In one embodiment of the present application, the method further includes:

[0122] S51, generating a mapping relationship between the template statement, the preprocessing identification information, and the parameter type information.

[0123] In an embodiment of the present application, a mapping relationship between the template statement, the preprocessing identification information, and the parameter type information can be generated and stored. Thus, after obtaining the query statement, a template statement matching the query statement is searched, and the preprocessing identification information and parameter type information corresponding to the query statement are determined according to the mapping relationship, thereby further improving processing efficiency.

[0124] In a specific implementation, the template statement can be converted into a hash value based on a hash algorithm (hash), and then a mapping relationship between the hash value, the preprocessing identification information, and the parameter type information is generated, and the mapping relationship is stored, thereby ensuring data security while reducing the amount of data.

[0125] As an example of the present application, the query statement is "selectname from a limit 888", and the parameter information "888" in the query statement can be replaced with the placeholder "?" to obtain the template statement "selectname from alimit?". Thereafter, the template statement "selectname from a limit?" can be converted into a hash value "abdc", and after determining that the preprocessing information is the preprocessing identification information is "3" and the parameter type information is "int", a mapping relationship {abdc=>{3,{int,?}} between the template statement, the preprocessing identification information, and the parameter type information can be generated.

[0126] Step 203, using the preprocessing information, the parameter information, and preset encoding identification information to generate a target execution statement; the encoding identification information is used to indicate that the data returns target data encoded based on a text protocol;

[0127] In an embodiment of the present application, the preprocessing information, the parameter information, and the preset encoding identification information can be used to generate a target execution statement; the encoding identification information is used to indicate that the data returns target data encoded based on a text protocol.

[0128] Wherein, the target execution statement may be a statement based on binary coding. Thus, the preprocessing information and the parameter information may be used to generate a target execution statement including the preprocessing information and the parameter information, and the target execution statement may be converted into a statement based on a binary coding protocol. As an example of the present application, the target execution statement may be a COM_STMT_EXECUTE message.

[0129] In a specific implementation, generally speaking, the database can execute the statement for the target and return the target data based on the encoding method of the binary protocol. However, since the query statement usually returns the target data based on the encoding method of the text protocol, the encoding identification information can be used to set the database to return the target data based on the text protocol encoding for the target execution statement.

[0130] After obtaining the target execution statement, the database can determine to return the target data based on the text protocol encoding method according to the encoding identification information contained in the target execution statement, so that the target data finally obtained by the user can be based on the text protocol encoding.

[0131] As an example of the present application, a flag may be present in the target execution statement. Generally speaking, the flag is an 8-byte field, and the database usually only uses the last 4 bits. The first 4 bits of the flag can be used as custom coding identification information, set to 0x80. The database can be set to use text protocol coding to return target data after receiving a target execution statement containing 0x80 coding identification information in the flag. Thus, although the target execution statement based on binary protocol coding is used to obtain the target data, the target data finally returned can still be based on text protocol coding. For the user, a query statement based on text protocol coding is still issued, and the target data based on text protocol coding is obtained, and the processing efficiency of the database is improved.

[0132] Step 204: Use the target execution statement to query the preset database for target data.

[0133] In an embodiment of the present application, the target execution statement can be used to query the target data from a preset database. Since the target execution statement includes the preprocessing information, the database does not need to parse the target execution statement again, but can directly use the preprocessing information and the parameter information included in the target execution statement to execute the query task and query the target data.

[0134] As an example of the present application, the query statement is "select * from a limit 1", where the parameter information is "1". After finding a template statement matching the query statement, the preprocessing information corresponding to the template statement can be obtained, the preprocessing information includes preprocessing identification information "3" and parameter type information "int". The preprocessing identification information "3", parameter type information "int" and the parameter information "1" can be used to generate a target execution statement. The database can use the preprocessing information and the parameter information contained in the target execution statement to know that the user wants to query "select * from a limit 1", and execute the query task to return the target data.

[0135] Therefore, for the query statement sent by the user, if there is an existing template statement, the query statement can be converted into a target execution statement, and the target execution statement is used to query the preset data for the target data. Therefore, the database can directly execute the query task without re-analyzing the obtained target execution statement, and query to obtain the target data, thereby improving the query processing efficiency.

[0136] In a specific implementation, a middleware can be preset, and the middleware can communicate with the user and the database at the same time. The middleware stores a number of preset template statements and the corresponding relationship between the template statements and the preprocessing information. After obtaining the query statement sent by the user, the middleware can search for the preset template statement that matches the query statement, and obtain the preprocessing information corresponding to the template statement, and use the preprocessing information and the parameter information to generate a target execution statement, and use the target execution statement to query the preset database for target data. After the middleware obtains the target data, it can return the target data to the user. Therefore, the middleware can assist the user in converting the query statement into the target execution statement and improve the query efficiency. And the user does not need to modify its client or client interface to use the target execution statement to query the target data.

[0137] Through the data query method of the embodiment of the present application, a query statement is obtained; wherein the query statement includes parameter information; a preset template statement matching the query statement is searched, and preprocessing information corresponding to the template statement is obtained; a target execution statement is generated using the preprocessing information, the parameter information, and the preset coding identification information; and the target execution statement is used to query the target data from the preset database. Thus, the query statement sent by the user can be converted into a target execution statement, and the target execution statement is used to query the target data from the database, so that the database can directly execute the query task without going through the statement parsing optimization process, thereby improving the query efficiency of the database.

[0138] Reference Figure 3 , shows a step flow chart of a data query method embodiment of the present application, which is applied to a query processing middleware, and the query processing middleware communicates with a client and a database at the same time.

[0139] In the embodiments of the present application, it is usually difficult to modify the user's client, and if the user needs to use prepared statements and target execution statements, it is usually necessary to modify and update the client so that the client can use the prepared statements and target execution statements. Especially for online applications, it is difficult to restart the online application so that the online application can use prepared statements and target execution statements. In addition, if the user uses prepared statements and target execution statements incorrectly, regardless of whether there are template statements, preprocessing information is obtained for the query statement, and then the target execution statement is generated to obtain the target data, which can easily cause the database to consume more computing resources.

[0140] Thus, a query processing middleware can be set between the client of the user and the database, and the query processing middleware communicates with the client and the database at the same time. The query processing middleware can convert the query statement sent by the client into a target execution statement, and use the target execution statement to obtain the target data from the database, so that the user can use the target execution preset to obtain the target data of the database without changing the application program, thereby effectively improving the processing efficiency of the database and being easy for the user to use.

[0141] The method may specifically include the following steps:

[0142] Step 301, the query processing middleware obtains the query statement sent by the client; wherein the query statement includes parameter information;

[0143] In an embodiment of the present application, the query processing middleware can obtain a query statement sent by the client of the user. The query statement can be used to query the target data from a preset database. The query statement can include parameter information, and the parameter information can be information of a variable number of parameters in the query statement.

[0144] Step 302, the query processing middleware searches for a preset template statement matching the query statement, and obtains preprocessing information corresponding to the template statement;

[0145] In an embodiment of the present application, the query processing middleware may store a plurality of preset template statements and a corresponding relationship between the template statements and the preprocessing information. The query processing middleware may search for a preset template statement that matches the query statement, and obtain the preprocessing information corresponding to the template statement according to the corresponding relationship between the template statement and the preprocessing information.

[0146] The preprocessing information may be information obtained by pre-parsing the template statement by the database, so that the database can use the preprocessing information to execute a query task similar to the template statement, without having to parse the obtained statement again, and can directly execute the data query task based on the preprocessing information.

[0147] In a specific implementation, if the template statement is identical to the query statement except for the parameter information, then it can be considered that the query statement matches the template statement.

[0148] Step 303, the query processing middleware uses the preprocessing information and the parameter information to generate a target execution statement;

[0149] In the embodiment of the present application, the query processing middleware may use the preprocessing information and the parameter information to generate a target execution statement. The target execution statement may be used to query the same target data as the query statement.

[0150] Step 304: the query processing middleware sends the target execution statement to the database, and obtains the target data returned by the database.

[0151] In an embodiment of the present application, the query processing middleware can use the target execution statement to query the target data from a preset database. Since the target execution statement contains the preprocessing information, the database does not need to parse the target execution statement again, but can directly use the preprocessing information and the parameter information contained in the target execution statement to execute the query task and query the target data. Thereafter, the query processing middleware can obtain the target data returned by the database.

[0152] Thus, for the query statement sent by the client, if the query processing middleware already has a template statement, the query processing middleware can convert the query statement into a target execution statement, and use the target execution statement to query the database for target data. Thus, the database can directly execute the query task without re-analyzing the acquired target execution statement, and obtain the target data, thereby improving the query processing efficiency.

[0153] Step 305: The query processing middleware returns the target data to the client.

[0154] In the embodiment of the present application, the query processing middleware can return the target data to the client, so that the client can obtain the target data corresponding to the query statement. Since the query processing middleware converts the query statement into a target execution statement before obtaining the target data from the database, the processing efficiency of the database is improved.

[0155] In the embodiment of the present application, the client can turn on or off the function of the query processing middleware to convert the query statement into a target execution statement according to actual needs. The query processing middleware can convert the query statement that conforms to the preset format into the target execution statement according to actual needs, and directly forward the query statement that does not conform to the preset format to the database, so that the dynamic use of the function of converting the query statement into the target execution statement can be realized according to actual needs.

[0156] As an example of this application, Figure 4 This is a schematic diagram of a data query method embodiment of the present application. It includes a client 401, a query processing middleware 402, and a database 403.

[0157] The client 401 can send a query statement to the query processing middleware 402. If the query processing middleware 402 does not have a template statement matching the query statement, it can generate a template statement based on the query statement; generate a preprocessed statement based on the template statement, and send the preprocessed statement to the database 403. The database 403 can return preprocessing identification information and parameter type information to the query processing middleware 402. Thereafter, the query processing middleware 402 can generate a target execution statement based on the preprocessing identification information and parameter type information, as well as the parameter information in the query statement, and send the target execution statement to the database 403. The database 403 can return target data to the query processing middleware 402 for the target execution statement. Thereafter, the query processing middleware 402 can forward the target data to the client 401, and the client 401 can obtain the target data for the query statement.

[0158] Through the data query method of the embodiment of the present application, the query processing middleware obtains the query statement sent by the client; wherein the query statement includes parameter information; the query processing middleware searches for a preset template statement that matches the query statement, and obtains the preprocessing information corresponding to the template statement; the query processing middleware uses the preprocessing information and the parameter information to generate a target execution statement; the query processing middleware sends the target execution statement to the database, and obtains the target data returned by the database; the query processing middleware returns the target data to the client. Thus, without changing the client, the query processing middleware converts the query statement sent by the client into a target execution statement, and uses the target execution statement to query the database for target data, so that the database can directly execute the query task without going through the statement parsing optimization process, thereby improving the query efficiency of the database.

[0159] It should be noted that, for the method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.

[0160] Reference Figure 5 , shows a structural block diagram of an embodiment of a data query device of the present application, which may specifically include the following modules:

[0161] The first query statement acquisition module 501 is used to acquire a query statement; wherein the query statement includes parameter information;

[0162] A first target statement search module 502 is used to search for a preset template statement matching the query statement and obtain preprocessing information corresponding to the template statement;

[0163] A first target execution statement generating module 503, configured to generate a target execution statement using the preprocessing information and the parameter information;

[0164] The first query module 504 is used to query the preset database for target data using the target execution statement.

[0165] In one embodiment of the present application, the device further includes:

[0166] A template generation module, used for generating a template statement according to the query statement when there is no matching template statement for the query statement;

[0167] A prepared statement generation module, used to generate a prepared statement using the template statement;

[0168] The preprocessing information acquisition module is used to send the preprocessing statement to the database and obtain the preprocessing information returned by the database.

[0169] In one embodiment of the present application, the preprocessing information includes preprocessing identification information and parameter type information;

[0170] The device also includes:

[0171] A mapping generation module is used to generate a mapping relationship between the template statement, the preprocessing identification information, and the parameter type information.

[0172] In one embodiment of the present application, the first target execution statement generation module includes:

[0173] The target execution statement generation submodule is used to generate a target execution statement using the preprocessing information, the parameter information, and preset encoding identification information; the encoding identification information is used to indicate that the data returns target data encoded based on a text protocol.

[0174] In one embodiment of the present application, the first target sentence search module includes:

[0175] The first target statement search submodule is used to search for a template statement that is identical to the query statement except for the parameter information, as a preset template statement that matches the query statement.

[0176] In one embodiment of the present application, the first target sentence search module includes:

[0177] A format determination submodule, used to determine whether the query statement conforms to a preset format;

[0178] A second target statement search submodule is used to search for a preset template statement matching the query statement when the query statement conforms to a preset format;

[0179] The forwarding submodule is used to forward the query statement to the database when the query statement does not conform to a preset format.

[0180] Reference Figure 6 , shows a structural block diagram of an embodiment of a data query device of the present application, which is applied to a query processing middleware, and the query processing middleware communicates with a client and a database at the same time; the device is deployed in the query processing middleware, and the device may specifically include the following modules:

[0181] The second query statement acquisition module 601 is used to acquire the query statement sent by the client; wherein the query statement includes parameter information;

[0182] A second target statement search module 602 is used to search for a preset template statement matching the query statement and obtain preprocessing information corresponding to the template statement;

[0183] A second target execution statement generating module 603, configured to generate a target execution statement using the preprocessing information and the parameter information;

[0184] A second query module 604 is used to send the target execution statement to the database and obtain the target data returned by the database;

[0185] The data returning module 605 is used to return the target data to the client.

[0186] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0187] The present application also provides a device, including:

[0188] one or more processors; and

[0189] One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, enable the device to perform the method described in the embodiments of the present application.

[0190] The embodiments of the present application also provide one or more machine-readable media on which instructions are stored, which, when executed by one or more processors, enable the processors to execute the methods described in the embodiments of the present application.

[0191] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0192] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0193] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0194] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0195] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1The steps for the functions specified in one or more boxes.

[0196] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0197] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0198] The data query method and the data query device provided by the present application are introduced in detail above. The principle and implementation mode of the present application are explained by using specific examples in this article. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for the general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation mode and the scope of application. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A data query method, characterized in that: It is applied to query processing middleware, which communicates with the client and the database at the same time; The query processing middleware stores a number of preset template statements and corresponding relationships between the template statements and preprocessing information; The method comprises: Obtaining a query statement; wherein the query statement includes parameter information; Searching for a preset template statement that matches the query statement, and acquiring preprocessing information corresponding to the template statement according to a correspondence between the template statement and the preprocessing information; the preprocessing information is information obtained by pre-parsing the template statement by the database; Generate a target execution statement using the preprocessing information and the parameter information; The target execution statement is used to query the database for target data.

2. The method according to claim 1, characterized in that The method further comprises: If there is no matching template statement for the query statement, generating a template statement according to the query statement; Using the template statement, generating a preprocessing statement; The prepared statement is sent to the database, and preprocessing information returned by the database is obtained.

3. The method according to claim 2, characterized in that The preprocessing information includes preprocessing identification information and parameter type information; The method further comprises: A mapping relationship between the template statement, the preprocessing identification information, and the parameter type information is generated.

4. The method according to claim 1, characterized in that: The step of using the preprocessing information and the parameter information to generate a target execution statement includes: The target execution statement is generated by using the preprocessing information, the parameter information, and the preset encoding identification information; the encoding identification information is used to indicate that the data returns the target data encoded based on the text protocol.

5. The method according to claim 1, characterized in that The step of searching for a preset template statement matching the query statement includes: A template statement that is identical to the query statement except for the parameter information is searched as a preset template statement that matches the query statement.

6. The method according to claim 1, characterized in that The step of searching for a preset template statement matching the query statement includes: Determining whether the query statement conforms to a preset format; When the query statement conforms to a preset format, searching for a preset template statement matching the query statement; If the query statement does not conform to a preset format, the query statement is forwarded to the database.

7. A data query method, characterized in that: It is applied to query processing middleware, which communicates with the client and the database at the same time; The query processing middleware stores a number of preset template statements and corresponding relationships between the template statements and preprocessing information; The method comprises: The query processing middleware obtains the query statement sent by the client; wherein the query statement includes parameter information; The query processing middleware searches for a preset template statement matching the query statement, and obtains preprocessing information corresponding to the template statement according to a corresponding relationship between the template statement and the preprocessing information; the preprocessing information is information obtained by pre-parsing the template statement by the database; The query processing middleware uses the preprocessing information and the parameter information to generate a target execution statement; The query processing middleware sends the target execution statement to the database and obtains the target data returned by the database; The query processing middleware returns the target data to the client.

8. A data query device, characterized in that: It is applied to query processing middleware, which communicates with the client and the database at the same time; The query processing middleware stores a number of preset template statements and corresponding relationships between the template statements and preprocessing information; The device comprises: A first query statement acquisition module, used to acquire a query statement; wherein the query statement includes parameter information; A first target statement search module is used to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement according to a corresponding relationship between the template statement and the preprocessing information; the preprocessing information is information obtained by pre-parsing the template statement by the database; A first target execution statement generating module, configured to generate a target execution statement using the preprocessing information and the parameter information; The first query module is used to query the database for target data using the target execution statement.

9. The device according to claim 8, characterized in that The device also includes: A template generation module, used for generating a template statement according to the query statement when there is no matching template statement for the query statement; A prepared statement generation module, used to generate a prepared statement using the template statement; The preprocessing information acquisition module is used to send the preprocessing statement to the database and obtain the preprocessing information returned by the database.

10. The device according to claim 9, characterized in that The preprocessing information includes preprocessing identification information and parameter type information; The device also includes: A mapping generation module is used to generate a mapping relationship between the template statement, the preprocessing identification information, and the parameter type information.

11. The device according to claim 8, characterized in that The first target execution statement generation module includes: The target execution statement generation submodule is used to generate a target execution statement using the preprocessing information, the parameter information, and preset encoding identification information; the encoding identification information is used to indicate that the data returns target data encoded based on a text protocol.

12. The device according to claim 8, characterized in that The first target sentence search module includes: The first target statement search submodule is used to search for a template statement that is identical to the query statement except for the parameter information, as a preset template statement that matches the query statement.

13. The device according to claim 8, characterized in that The first target sentence search module includes: A format determination submodule, used to determine whether the query statement conforms to a preset format; A second target statement search submodule is used to search for a preset template statement matching the query statement when the query statement conforms to a preset format; The forwarding submodule is used to forward the query statement to the database when the query statement does not conform to a preset format.

14. A data query device, characterized in that: It is applied to a query processing middleware, which communicates with a client and a database at the same time; the device is deployed in the query processing middleware, which stores a plurality of preset template statements and a corresponding relationship between the template statements and preprocessing information; The device comprises: A second query statement acquisition module, used to acquire the query statement sent by the client; wherein the query statement includes parameter information; A second target statement search module is used to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement according to the corresponding relationship between the template statement and the preprocessing information; the preprocessing information is information obtained by pre-parsing the template statement by the database; A second target execution statement generating module, configured to generate a target execution statement using the preprocessing information and the parameter information; The second query module is used to send the target execution statement to the database and obtain the target data returned by the database; wherein the database directly executes the data query task based on the preprocessing information in the target execution statement A data returning module is used to return the target data to the client.

15. A device, characterized in that: include: one or more processors; and One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, cause the apparatus to perform the method of any one of claims 1-6 or 7.

16. One or more machine-readable media having instructions stored thereon, which when executed by one or more processors cause the processors to perform the method of any one of claims 1-6 or 7.

Citation Information

Patent Citations

  • Data query method and device based on configuration information

    CN110019350A