WO2022042288A1 - Data query method and apparatus - Google Patents
Data query method and apparatus Download PDFInfo
- Publication number
- WO2022042288A1 WO2022042288A1 PCT/CN2021/111696 CN2021111696W WO2022042288A1 WO 2022042288 A1 WO2022042288 A1 WO 2022042288A1 CN 2021111696 W CN2021111696 W CN 2021111696W WO 2022042288 A1 WO2022042288 A1 WO 2022042288A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- statement
- query
- information
- template
- database
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2452—Query translation
- G06F16/24522—Translation of natural language queries to structured queries
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
Definitions
- the present application relates to the technical field of data processing, and in particular, to a data query method and a data query device.
- 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 database performs lexical and semantic analysis on the query statement, and the process of optimizing the query statement usually consumes certain computing resources, which easily leads to a long processing time of the query statement and reduces the processing efficiency of the database.
- 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.
- an embodiment of the present application discloses a data query method, including:
- the query statement includes parameter information
- the method further includes:
- the preprocessing information includes preprocessing identification information and parameter type information
- the method also includes:
- a mapping relationship between the template statement, the preprocessing identification information, and the parameter type information is generated.
- the step of generating a target execution statement by using the preprocessing information and the parameter information includes:
- a target execution statement is generated; the encoding identification information is used to instruct the data to return target data encoded based on a text protocol.
- the step of searching for a preset template statement matching the query statement includes:
- a template statement that is the same as the query statement except for the parameter information is searched as a preset template statement matching the query statement.
- the step of searching for a preset template statement matching the query statement includes:
- search for a preset template statement matching the query statement In the case that the query statement conforms to a preset format, search for a preset template statement matching the query statement;
- the query statement is forwarded to the database.
- the embodiment of the present application also discloses a data query method, which is applied to query processing middleware, and the query processing middleware communicates with a client and a database at the same time; the method includes:
- 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;
- 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 target data returned by the database;
- the query processing middleware returns the target data to the client.
- the embodiment of the present application also discloses a data query device, comprising:
- a first query statement obtaining module used for obtaining a query statement; wherein the query statement includes parameter information;
- a first target statement search module configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;
- a first target execution statement generation module configured to use the preprocessing information and the parameter information to generate a target execution statement
- the first query module is configured to use the target execution statement to query target data from a preset database.
- the device further includes:
- a template generation module configured to generate a template statement according to the query statement when the query statement does not have a matching template statement
- a prepared statement generation module for generating a prepared statement by using the template statement
- the preprocessing information acquiring module is configured to send the preprocessing statement to the database, and acquire the preprocessing information returned by the database.
- the preprocessing information includes preprocessing identification information and parameter type information
- the device also includes:
- the mapping generation module is used for generating the mapping relationship among the template statement, the preprocessing identification information, and the parameter type information.
- the first target execution statement generation module includes:
- a target execution statement generation submodule is used to generate a target execution statement by using the preprocessing information, the parameter information, and the preset encoding identification information; the encoding identification information is used to instruct the data to be returned based on text protocol encoding target data.
- the first target statement search module includes:
- the first target statement search sub-module is configured to search for a template statement that is the same as the query statement except for the parameter information, as a preset template statement matching the query statement.
- the first target statement search module includes:
- a format determination submodule for determining whether the query statement conforms to a preset format
- a second target statement search submodule configured to search for a preset template statement matching the query statement when the query statement conforms to a preset format
- the forwarding sub-module is configured to forward the query statement to the database if the query statement does not conform to the preset format.
- An embodiment of the present application discloses a data query device, which is applied to 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 query processing middleware
- the device includes:
- the second query statement obtaining module is used to obtain the query statement sent by the client; wherein, the query statement includes parameter information;
- a second target statement search module configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;
- a second target execution statement generation module configured to generate a target execution statement by using the preprocessing information and the parameter information
- a second query module configured to send the target execution statement to the database, and obtain target data returned by the database
- a data return module configured to return the target data to the client.
- the embodiment of the present application also discloses a device, comprising:
- One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, cause the apparatus to perform one or more of the methods described in the embodiments of the present application.
- the embodiments of the present application further disclose one or more machine-readable media, on which instructions are stored, and when executed by one or more processors, cause the processors to execute one or more of the methods described in the embodiments of the present application. a method.
- the query statement includes parameter information; search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement; Using the preprocessing information and the parameter information, a target execution statement is generated; using the target execution statement, a preset database is queried for target data. Therefore, 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 database for target data, so that the database can directly execute the query task without going through the statement parsing and optimization process, which improves the performance of the database. query efficiency.
- Fig. 1 is a flow chart of steps of a data query method embodiment of the present application
- Fig. 2 is a flow chart of steps of a data query method embodiment of the present application
- FIG. 3 is a flow chart of steps of an embodiment of a data query method of the present application.
- FIG. 4 is a schematic diagram of an embodiment of a data query method of the present application.
- FIG. 5 is a structural block diagram of an embodiment of a data query device of the present application.
- FIG. 6 is a structural block diagram of an embodiment of a data query apparatus according to the present application.
- the embodiment of the present application is aimed at the situation that the database performs lexical and semantic analysis on the query statement, and the process of optimizing the query statement reduces the efficiency of the database.
- the query statement is 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.
- the database can directly use the target execution statement to perform a data query task without analyzing and optimizing the target execution statement, and return the data query result, thereby improving the processing efficiency of the database.
- FIG. 1 a flow chart of steps of an embodiment of a data query method of the present application is shown, which may specifically include the following steps:
- Step 101 obtaining a query statement; wherein, the query statement includes parameter information;
- the query statement sent by the user can be acquired.
- the query statement can 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 can be the parameter information.
- Step 102 searching for a preset template statement matching the query statement, and acquiring preprocessing information corresponding to the template statement;
- preset template statements may be stored, as well as the corresponding relationship between the template statements and preprocessing information.
- a preset template statement matching the query statement can be searched, and the preprocessing information corresponding to the template statement can be acquired according to the correspondence between the template statement and the preprocessing information.
- the preprocessing information may be information obtained by preparsing the template statement by the database. Therefore, when the database can use the preprocessing information to perform a query task similar to the template statement, it is not necessary to parse the acquired statement again, and the data query task can be directly performed based on the preprocessing information.
- the template statement is the same as the query statement except for the parameter information, it can be considered that the query statement matches the template statement.
- Step 103 using the preprocessing information and the parameter information to generate a target execution statement
- the preprocessing information and the parameter information may be used to generate a target execution statement.
- the target execution statement can be used to query the same target data as the query statement.
- Step 104 using the target execution statement to query target data from a preset database.
- the target execution statement may be used to query target data from a preset database. Since the target execution statement contains the preprocessing information, the database can directly use the preprocessing information and the parameter information contained in the target execution statement without parsing the target execution statement again to execute the query task , query the target data.
- the query statement can be converted into a target execution statement, and the target execution statement can be used to query the preset data for target data. Therefore, the database can directly execute the query task without re-analyzing the obtained target execution statement, and obtain the target data by query, thereby improving the query processing efficiency.
- the query statement is "select*from a limit 1"
- the preprocessing information corresponding to the template statement can be obtained, using the The preprocessing information and the parameter information are 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 learn that what the user wants to query is "select*from a limit1", and execute the query task to return the target data.
- a middleware can be preset, and the middleware can communicate with the user and the database at the same time.
- the middleware stores several preset template statements, and the corresponding relationship between the template statements and preprocessing information.
- the middleware may search for a preset template statement matching the query statement, acquire preprocessing information corresponding to the template statement, and use the preprocessing information and the
- the parameter information is used to generate a target execution statement, and the target execution statement is used to query the target data from a preset database.
- the middleware can return the target data to the user. Therefore, the middleware can assist the user to convert the query statement into the target execution statement, thereby improving the query efficiency.
- users can use the target execution statement to query target data without modifying the client or the client interface.
- the query statement includes parameter information; search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement; Using the preprocessing information and the parameter information, a target execution statement is generated; using the target execution statement, a preset database is queried for target data. Therefore, 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 database for target data, so that the database can directly execute the query task without going through the statement parsing and optimization process, which improves the performance of the database. query efficiency.
- FIG. 2 a flow chart of steps of an embodiment of a data query method of the present application is shown, which may specifically include the following steps:
- Step 201 obtaining a query statement; wherein, the query statement includes parameter information;
- the query statement sent by the user can be acquired.
- the query statement can 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 can be the parameter information.
- Step 202 searching for a preset template statement matching the query statement, and acquiring preprocessing information corresponding to the template statement;
- preset template statements may be stored, as well as the corresponding relationship between the template statements and preprocessing information.
- a preset template statement matching the query statement may be searched for, and preprocessing information corresponding to the template statement may be acquired according to the correspondence between the template statement and the preprocessing information.
- the preprocessing information may be information obtained by preparsing the template statement by the database. Therefore, when the database can use the preprocessing information to perform a query task similar to the template statement, it is not necessary to parse the acquired statement again, and the data query task can be directly performed based on the preprocessing information.
- the template statement is the same as the query statement except for the parameter information, it can be considered that the query statement matches the template statement.
- the step of searching for a preset template statement matching the query statement includes:
- S11 Search for a template statement that is the same as the query statement except for the parameter information, as a preset template statement matching the query statement.
- the template statement matching the query statement may be the same as the query statement except that the parameter information is different from the query statement. In this way, it is possible to find out whether there is a template statement that is the same as the query statement except for the parameter information, as a preset target statement matching the query statement.
- the template statement matching the query statement may be "select*from t limit?".
- the method further includes:
- a template statement in the case that the query statement does not have a matching template statement, can be generated according to the query statement, so as to facilitate the subsequent improvement of processing efficiency of query statements of the same type.
- the step of generating a template statement according to the query statement includes:
- the parameter information in the query statement can be replaced with placeholder information, so that the template statement can be generated.
- the query statement is "select name from a where id between 1and 2", where the parameter information is "1" and "2", the placeholder "?” can be used to replace the parameter information with "1” and "2", resulting in the template statement "select name from a where id between?and?".
- the template statement may be used to generate a preprocessing statement for acquiring preprocessing information from a database.
- the template statement can be used to generate a binary prepared statement conforming to the database communication protocol.
- the prepared statement may be a message of type COM_STMT_PREPARE.
- S23 Send the preprocessing statement to the database, and obtain the preprocessing information returned by the database.
- the preprocessed statement may be sent to the database, and the database may perform parsing processing on the preprocessed statement, generate preprocessing information, and return it, so as to obtain the preprocessed statement returned by the database. information.
- the preprocessing information returned by the database may include preprocessing identification information and parameter type information.
- the preprocessing identification information may be identification information allocated by the database to the preprocessing statement.
- the parameter type information is the type of parameters that can be set by the prepared statement recorded in the database.
- the parameter type may be an integer type, a string type, etc., which is not limited in this 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), and num_params (number of parameters) , reserved_1 (reserved filler), warning_count (warning times), Parameter Definition Block (parameter type information), and Column Definition Block (column definition information).
- the step of searching for a preset template statement matching the query statement includes:
- the query statement sent by the user may be in multiple different formats.
- a query statement that conforms to a preset format can be matched with a template statement and converted into a target execution statement.
- the query statement that does not conform to the format it may not be processed.
- it can be determined whether the query statement conforms to the preset format.
- 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 limit it.
- the query statement can be converted into a target execution statement at this time.
- the preset template statement matching the query statement can be queried, and 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, and executed by using the target statement. statement, the step of querying the target data from the preset database.
- the query statement if the query statement does not conform to the preset format, it may not be necessary to convert the query statement into a target execution statement at this time. At this time, the query statement can be directly forwarded to the database, and the database can directly parse the query statement and return the target data.
- the query statement if the query statement conforms to the preset format, it may be further determined whether the query statement contains parameter information, and if the query statement does not contain parameter information, it may be considered that the query statement does not contain parameter information. If it is suitable for converting the query statement into a target execution statement, the query statement can also be directly forwarded to the database at this time, and the database directly parses the query statement and returns the target data.
- the dynamic opening and closing of converting the query statement into the target execution statement can be realized, the query statement that conforms to the preset format is executed and the query statement is converted into the target execution statement, and the query statement that does not conform to the preset format can be directly forwarded to the database, and the query statement is directly parsed and processed by the database.
- the preset format may be a non-parameterized query statement.
- the query statement can be converted into a target execution statement, the query statement is executed, and the preset template statement matching the query statement is executed, and the preset template statement corresponding to the template statement is obtained. Processing information, using the preprocessing information and the parameter information, generating a target execution statement, and querying a preset database for target data by using the target execution statement. If the obtained query statement is a parameterized query statement, the query statement may not need to be processed at this time, and the query statement may be directly forwarded to the database.
- the method further includes:
- a mapping relationship between the template statement, the preprocessing identification information, and the parameter type information may be generated, and the mapping relationship may be stored. Therefore, after acquiring 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.
- the template statement may 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, so that data security can be ensured while reducing the amount of data.
- a hash algorithm hash algorithm
- the query statement is "select name from a limit 888"
- the parameter information "888” in the query statement can be replaced with a placeholder "?” to obtain the template statement "select name from a limit 888" limit?”.
- the template statement "select name from a limit?” can be converted into a hash value "abdc”, after determining that the preprocessing information is the preprocessing identification information "3” and the parameter type information is "int”,
- Step 203 using the preprocessing information, the parameter information, and the preset encoding identification information to generate a target execution statement; the encoding identification information is used to instruct the data to return the target data encoded based on the text protocol;
- the preprocessing information, the parameter information, and the preset coding identification information may be used to generate a target execution statement; the coding identification information is used to instruct the data to return a text protocol-encoded based target data.
- the target execution statement may be a statement based on binary coding.
- the preprocessing information and the parameter information can be used to generate a target execution statement including the preprocessing information and the parameter information, and the target execution statement can be converted into a statement based on a binary encoding protocol.
- the target execution statement may be a COM_STMT_EXECUTE message.
- the database may execute a statement for the target, and return target data in an encoding manner based on a binary protocol.
- the query statement usually returns the target data based on the encoding method of the text protocol. Therefore, the encoding identification information can be used to set the database to return the target data encoded based on the text protocol for the target execution statement.
- the database may determine to return target data based on a text protocol encoding method according to the encoding identification information contained in the target execution statement. Therefore, the target data finally obtained by the user may be encoded based on the text protocol.
- a flag bit may exist in the target execution statement.
- the flag bit is a field of 8 bytes, and the database usually only uses the last 4 bits.
- the first 4 bits of the flag bits can be used as self-defined encoding identification information and set to 0x80.
- the database may be configured to use text protocol encoding to return the target data after receiving the target execution statement whose flag bit contains 0x80 encoded identification information. Therefore, although the target execution statement based on the binary protocol encoding is used to obtain the target data, the final returned target data can still be encoded based on the text protocol.
- the target data is encoded in the text protocol, and the processing efficiency of the database is improved.
- Step 204 using the target execution statement to query a preset database for target data.
- the target execution statement may be used to query target data from a preset database. Since the target execution statement contains the preprocessing information, the database can directly use the preprocessing information and the parameter information contained in the target execution statement without parsing the target execution statement again to execute the query task , query the target data.
- the query statement is "select*from a limit 1", and the parameter information is "1".
- the preprocessing information corresponding to the template statement can be obtained, and the preprocessing information includes the preprocessing identification information "3" and the parameter type information "int”.
- the identification information "3", the parameter type information "int”, and the parameter information "1” are processed to generate a target execution statement.
- the database can use the preprocessing information and the parameter information contained in the target execution statement to learn that what the user wants to query is "select*from a limit 1", and execute the query task to return the target data.
- the query statement can be converted into a target execution statement, and the target execution statement can be used to query the preset data for target data. Therefore, the database can directly execute the query task without re-analyzing the obtained target execution statement, and obtain the target data by query, thereby improving the query processing efficiency.
- a middleware can be preset, and the middleware can communicate with the user and the database at the same time.
- the middleware stores several preset template statements, and the corresponding relationship between the template statements and preprocessing information.
- the middleware may search for a preset template statement matching the query statement, acquire preprocessing information corresponding to the template statement, and use the preprocessing information and the
- the parameter information is used to generate a target execution statement, and the target execution statement is used to query the target data from a preset database.
- the middleware can return the target data to the user. Therefore, the middleware can assist the user to convert the query statement into the target execution statement, thereby improving the query efficiency.
- users can use the target execution statement to query target data without modifying the client or the client interface.
- the query statement includes parameter information; search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement; Using the preprocessing information, the parameter information, and the preset coding identification information, a target execution statement is generated; and the target execution statement is used to query a preset database for target data. Therefore, 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 database for target data, so that the database can directly execute the query task without going through the statement parsing and optimization process, which improves the performance of the database. query efficiency.
- FIG. 3 a flow chart of steps of an embodiment of a data query method of the present application is shown, which is applied to query processing middleware, and the query processing middleware communicates with the client and the database at the same time.
- a query processing middleware can be set between the user's client and the database, and the query processing middleware communicates with the client and the database at the same time.
- the query processing intermediate key can convert the query statement sent by the client into a target execution statement, and use the target execution statement to obtain target data from the database, so that the user can use the target execution preset to obtain the database without changing the application program.
- the target data can effectively improve the processing efficiency of the database, and it is easy for users to use.
- the method may specifically include the following steps:
- Step 301 the query processing middleware obtains a query statement sent by the client; wherein the query statement includes parameter information;
- the query processing middleware may acquire a query statement sent by the client of the user.
- the query statement can 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.
- 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;
- the query processing middleware may store several preset template statements, as well as the correspondence between the template statements and preprocessing information.
- the query processing middleware may search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement according to the correspondence between the template statement and the preprocessing information.
- the preprocessing information may be information obtained by preparsing the template statement by the database. Therefore, when the database can use the preprocessing information to perform a query task similar to the template statement, it is not necessary to parse the acquired statement again, and the data query task can be directly performed based on the preprocessing information.
- the template statement is the same as the query statement except for the parameter information, it can be considered that the query statement matches the template statement.
- Step 303 the query processing middleware uses the preprocessing information and the parameter information to generate a target execution statement
- the query processing middleware may use the preprocessing information and the parameter information to generate a target execution statement.
- the target execution statement can be used to query the same target data as the query statement.
- Step 304 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 may use the target execution statement to query a preset database for target data. Since the target execution statement contains the preprocessing information, the database can directly use the preprocessing information and the parameter information contained in the target execution statement without parsing the target execution statement again to execute the query task , query the target data. Thereafter, the query processing middleware may acquire the target data returned by the database.
- the query processing middleware can convert the query statement into a target execution statement, and use the The target execution statement queries the data for target data. Therefore, the database can directly execute the query task without re-analyzing the obtained target execution statement, and obtain the target data by query, thereby improving the query processing efficiency.
- Step 305 the query processing middleware returns the target data to the client.
- the query processing middleware may return the target data to the client, so that the client may obtain the target data corresponding to the query statement.
- the query processing middleware obtains target data from the database after converting the query statement into a target execution statement. The processing efficiency of the database is improved.
- the client may, according to actual needs, enable or disable the function of the query processing middleware to convert the query statement into a target execution statement.
- the query processing middleware can convert the query statements that conform to the preset format into target execution statements according to actual needs, and directly forward the query statements that do not conform to the preset format to the database, so that the query statement can be implemented according to actual needs.
- the query statement is converted into the dynamic use of the target execution statement function.
- FIG. 4 is a schematic diagram of an embodiment of a data query method according to an embodiment of the present application. It includes the client 401 , the query processing middleware 402 , and the database 403 .
- the client 401 may send a query statement to the query processing middleware 402, and if the query processing middleware 402 does not have a template statement matching the query statement, a template may be generated according to the query statement statement; generate a prepared statement according to the template statement, and send the prepared statement to the database 403 .
- the database 403 may return preprocessing identification information and parameter type information to the query processing middleware 402 . Thereafter, the query processing middleware 402 may generate a target execution statement based on the preprocessing identification information and parameter type information, and the parameter information in the query statement, and send the target execution statement to the database 403. , the database 403 may return target data to the query processing middleware 402 for the target execution statement. Thereafter, the query processing middleware 402 may forward the target data to the client 401, and the client 401 may obtain the target data for the query statement.
- 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 the query statement that matches the query statement. preset template statement, and obtain 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 reports to the The database sends the target execution statement, and obtains the target data returned by the database; the query processing middleware returns the target data to 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 After the statement parsing and optimization process, the query task can be directly executed, which improves the query efficiency of the database.
- FIG. 5 a structural block diagram of an embodiment of a data query apparatus of the present application is shown, which may specifically include the following modules:
- the first query statement obtaining module 501 is used to obtain a query statement; wherein, the query statement includes parameter information;
- the first target statement search module 502 is configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;
- a first target execution statement generation module 503, configured to generate a target execution statement by using the preprocessing information and the parameter information;
- the first query module 504 is configured to use the target execution statement to query target data from a preset database.
- the device further includes:
- a template generation module configured to generate a template statement according to the query statement when the query statement does not have a matching template statement
- a prepared statement generation module for generating a prepared statement by using the template statement
- the preprocessing information acquiring module is configured to send the preprocessing statement to the database, and acquire the preprocessing information returned by the database.
- the preprocessing information includes preprocessing identification information and parameter type information
- the device also includes:
- the mapping generation module is used for generating the mapping relationship among the template statement, the preprocessing identification information, and the parameter type information.
- the first target execution statement generation module includes:
- a target execution statement generation submodule is used to generate a target execution statement by using the preprocessing information, the parameter information, and the preset encoding identification information; the encoding identification information is used to instruct the data to be returned based on text protocol encoding target data.
- the first target sentence search module includes:
- the first target statement search sub-module is configured to search for a template statement that is the same as the query statement except for the parameter information, as a preset template statement matching the query statement.
- the first target sentence search module includes:
- a format determination submodule for determining whether the query statement conforms to a preset format
- the second target statement search submodule is used to search for a preset template statement matching with the query statement when the query statement meets the preset format
- the forwarding sub-module is configured to forward the query statement to the database if the query statement does not conform to the preset format.
- FIG. 6 shows a structural block diagram of an embodiment of a data query apparatus of the present application, which is applied to query processing middleware, and the query processing middleware communicates with a client and a database at the same time; the apparatus is deployed in the In the query processing middleware, the device may specifically include the following modules:
- the second query statement obtaining module 601 is configured to obtain the query statement sent by the client; wherein the query statement includes parameter information;
- a second target statement search module 602 configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;
- the second target execution statement generation module 603 is configured to use the preprocessing information and the parameter information to generate a target execution statement
- the data returning module 605 is configured to return the target data to the client.
- the embodiment of the present application also provides a device, including:
- One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, cause the apparatus to perform the methods described in the embodiments of the present application.
- the embodiments of the present application further provide one or more machine-readable media on which instructions are stored, and when executed by one or more processors, cause the processors to execute the methods described in the embodiments of the present application.
- embodiments of the embodiments of the present application may be provided as methods, apparatuses, or computer program products. Accordingly, the embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present application may take 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.) having computer-usable program code embodied therein.
- computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
- These computer program instructions may be provided to the processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing terminal equipment to produce a machine that causes the instructions to be executed by the processor of the computer or other programmable data processing terminal equipment Means are created for implementing the functions specified in the flow or flows of the flowcharts and/or the blocks or blocks of the block diagrams.
- These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal equipment to operate in a particular manner, such that the instructions stored in the computer readable memory result in an article of manufacture comprising instruction means, the The instruction means implement the functions specified in the flow or flow of the flowcharts and/or the block or blocks of the block diagrams.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Artificial Intelligence (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The embodiments of the present application provide a data query method and apparatus. Said method comprises: acquiring a query statement, the query statement comprising parameter information; searching for a preset template statement matching the query statement, and acquiring preprocessed information corresponding to the template statement; using the preprocessed information and the parameter information to generate a target execution statement; and using the target execution sentence to query a preset database for target data. In this way, a query statement sent by a user can be converted into a target execution statement, and the target execution statement is used to query a database for target data, so that the database can directly execute a query task without a statement parsing optimization process, thereby increasing the query efficiency of the database.
Description
本申请要求2020年08月31日递交的申请号为202010901686.7、发明名称为“一种数据查询方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with application number 202010901686.7 filed on August 31, 2020 and the invention title is "A data query method and device", the entire contents of which are incorporated into this application by reference.
本申请涉及数据处理技术领域,特别是涉及一种数据查询方法和一种数据查询装置。The present application relates to the technical field of data processing, and in particular, to a data query method and a data query device.
现有技术中,当用户需要向数据库查询数据时,通常可以向数据库发送查询语句。所述数据库可以对所述查询语句进行词法和语义解析,优化查询语句,制定执行计划,其后执行并向用户返回结果。其中数据库对查询语句进行词法和语义解析,优化查询语句的过程,通常需要消耗一定的计算资源,并且容易导致查询语句的处理时间较长,降低数据库的处理效率。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. Among them, the database performs lexical and semantic analysis on the query statement, and the process of optimizing the query statement usually consumes certain computing resources, which easily leads to a long processing time of the query statement and reduces the processing efficiency of the database.
发明内容SUMMARY OF THE INVENTION
鉴于上述问题,提出了本申请实施例以便提供一种克服上述问题或者至少部分地解决上述问题的一种数据查询方法和相应的一种数据查询装置。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.
为了解决上述问题,本申请实施例公开了一种数据查询方法,包括:In order to solve the above problems, an embodiment of the present application discloses a data query method, including:
获取查询语句;其中,所述查询语句包括参数信息;Obtain a query statement; wherein, the query statement includes parameter information;
查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;Searching for a preset template statement matching the query statement, and acquiring 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, query target data from a preset database.
可选地,所述方法还包括:Optionally, the method further includes:
在所述查询语句不存在匹配的模板语句的情况下,根据所述查询语句,生成模板语句;In the case that the query statement does not have a matching template statement, generate a template statement according to the query statement;
采用所述模板语句,生成预处理语句;Using the template statement to generate a prepared statement;
向所述数据库发送所述预处理语句,获取所述数据库返回的预处理信息。Send the preprocessing statement to the database, and obtain the preprocessing information returned by the database.
可选地,所述预处理信息包括预处理标识信息以及参数类型信息;Optionally, the preprocessing information includes preprocessing identification information and parameter type information;
所述方法还包括:The method also includes:
生成所述模板语句、所述预处理标识信息、以及参数类型信息之间的映射关系。A mapping relationship between the template statement, the preprocessing identification information, and the parameter type information is generated.
可选地,所述采用所述预处理信息以及所述参数信息,生成目标执行语句的步骤,包括:Optionally, the step of generating a target execution statement by using the preprocessing information and the parameter information includes:
采用所述预处理信息、所述参数信息、以及预设的编码标识信息,生成目标执行语句;所述编码标识信息用于指示所述数据返回基于文本协议编码的目标数据。Using the preprocessing information, the parameter information, and the preset encoding identification information, a target execution statement is generated; the encoding identification information is used to instruct the data to return target data encoded based on a text protocol.
可选地,所述查找与所述查询语句匹配的预设的模板语句步骤,包括:Optionally, the step of searching for a preset template statement matching the query statement includes:
查找除所述参数信息之外与所述查询语句相同的模板语句,作为与所述查询语句匹配的预设的模板语句。A template statement that is the same as the query statement except for the parameter information is searched as a preset template statement matching the query statement.
可选地,所述查找与所述查询语句匹配的预设的模板语句的步骤,包括:Optionally, the step of searching for a preset template statement matching the query statement includes:
确定所述查询语句是否符合预设格式;determining whether the query statement conforms to a preset format;
在所述查询语句符合预设格式的情况下,查找与所述查询语句匹配的预设的模板语句;In the case that the query statement conforms to a preset format, search for a preset template statement matching the query statement;
在所述查询语句不符合预设格式的情况下,将所述查询语句转发至所述数据库。If the query statement does not conform to the preset format, the query statement is forwarded to the database.
本申请实施例还公开了一种数据查询方法,其应用于查询处理中间件,所述查询处理中间件同时与客户端以及数据库通信;所述方法包括:The embodiment of the present application also discloses a data query method, which is applied to query processing middleware, and the query processing middleware communicates with a client and a database at the same time; the method includes:
所述查询处理中间件获取所述客户端发送的查询语句;其中,所述查询语句包括参数信息;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;
所述查询处理中间件采用所述预处理信息以及所述参数信息,生成目标执行语句;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 target data returned by the database;
所述查询处理中间件向所述客户端返回所述目标数据。The query processing middleware returns the target data to the client.
本申请实施例还公开了一种数据查询装置,包括:The embodiment of the present application also discloses a data query device, comprising:
第一查询语句获取模块,用于获取查询语句;其中,所述查询语句包括参数信息;a first query statement obtaining module, used for obtaining a query statement; wherein the query statement includes parameter information;
第一目标语句查找模块,用于查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;a first target statement search module, configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;
第一目标执行语句生成模块,用于采用所述预处理信息以及所述参数信息,生成目标执行语句;a first target execution statement generation module, configured to use the preprocessing information and the parameter information to generate a target execution statement;
第一查询模块,用于采用所述目标执行语句,向预设的数据库查询目标数据。The first query module is configured to use the target execution statement to query target data from a preset database.
可选地,所述装置还包括:Optionally, the device further includes:
模板生成模块,用于在所述查询语句不存在匹配的模板语句的情况下,根据所述查询语句,生成模板语句;a template generation module, configured to generate a template statement according to the query statement when the query statement does not have a matching template statement;
预处理语句生成模块,用于采用所述模板语句,生成预处理语句;a prepared statement generation module for generating a prepared statement by using the template statement;
预处理信息获取模块,用于向所述数据库发送所述预处理语句,获取所述数据库返回的预处理信息。The preprocessing information acquiring module is configured to send the preprocessing statement to the database, and acquire the preprocessing information returned by the database.
可选地,所述预处理信息包括预处理标识信息以及参数类型信息;Optionally, the preprocessing information includes preprocessing identification information and parameter type information;
所述装置还包括:The device also includes:
映射生成模块,用于生成所述模板语句、所述预处理标识信息、以及参数类型信息之间的映射关系。The mapping generation module is used for generating the mapping relationship among the template statement, the preprocessing identification information, and the parameter type information.
可选地,所述第一目标执行语句生成模块包括:Optionally, the first target execution statement generation module includes:
目标执行语句生成子模块,用于采用所述预处理信息、所述参数信息、以及预设的编码标识信息,生成目标执行语句;所述编码标识信息用于指示所述数据返回基于文本协议编码的目标数据。A target execution statement generation submodule is used to generate a target execution statement by using the preprocessing information, the parameter information, and the preset encoding identification information; the encoding identification information is used to instruct the data to be returned based on text protocol encoding target data.
可选地,所述第一目标语句查找模块包括:Optionally, the first target statement search module includes:
第一目标语句查找子模块,用于查找除所述参数信息之外与所述查询语句相同的模板语句,作为与所述查询语句匹配的预设的模板语句。The first target statement search sub-module is configured to search for a template statement that is the same as the query statement except for the parameter information, as a preset template statement matching the query statement.
可选地,所述第一目标语句查找模块包括:Optionally, the first target statement search module includes:
格式确定子模块,用于确定所述查询语句是否符合预设格式;a format determination submodule for determining whether the query statement conforms to a preset format;
第二目标语句查找子模块,用于在所述查询语句符合预设格式的情况下,查找与所述查询语句匹配的预设的模板语句;a second target statement search submodule, configured to search for a preset template statement matching the query statement when the query statement conforms to a preset format;
转发子模块,用于在所述查询语句不符合预设格式的情况下,将所述查询语句转发至所述数据库。The forwarding sub-module is configured to forward the query statement to the database if the query statement does not conform to the preset format.
本申请实施例中公开了一种数据查询装置,其应用于查询处理中间件,所述查询处理中间件同时与客户端以及数据库通信;所述装置部署在所述查询处理中间件中,所述装置包括:An embodiment of the present application discloses a data query device, which is applied to 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 query processing middleware The device includes:
第二查询语句获取模块,用于获取所述客户端发送的查询语句;其中,所述查询语句包括参数信息;The second query statement obtaining module is used to obtain the query statement sent by the client; wherein, the query statement includes parameter information;
第二目标语句查找模块,用于查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;A second target statement search module, configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;
第二目标执行语句生成模块,用于采用所述预处理信息以及所述参数信息,生成目标执行语句;a second target execution statement generation module, configured to generate a target execution statement by using the preprocessing information and the parameter information;
第二查询模块,用于向所述数据库发送所述目标执行语句,并获取所述数据库返回的目标数据;A second query module, configured to send the target execution statement to the database, and obtain target data returned by the database;
数据返回模块,用于向所述客户端返回所述目标数据。A data return module, configured to return the target data to the client.
本申请实施例还公开了一种装置,包括:The embodiment of the present application also discloses a device, comprising:
一个或多个处理器;和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 one or more of the methods described in the embodiments of the present application.
本申请实施例还公开了一个或多个机器可读介质,其上存储有指令,当由一个或多个处理器执行时,使得所述处理器执行如本申请实施例所述的一个或多个的方法。The embodiments of the present application further disclose one or more machine-readable media, on which instructions are stored, and when executed by one or more processors, cause the processors to execute one or more of the methods described in the embodiments of the present application. a method.
本申请实施例包括以下优点:The embodiments of the present application include the following advantages:
通过本申请实施例的数据查询方法,获取查询语句;其中,所述查询语句包括参数信息;查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;采用所述预处理信息以及所述参数信息,生成目标执行语句;采用所述目标执行语句,向预设的数据库查询目标数据。从而可以将用户发送的查询语句转换为目标执行语句,并采用所述目标执行语句向数据库查询目标数据,从而所述数据库可以无需经过语句解析优化过程,即可直接执行查询任务,提高了数据库的查询效率。Obtain a query statement through the data query method of the embodiment of the present application; wherein, the query statement includes parameter information; search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement; Using the preprocessing information and the parameter information, a target execution statement is generated; using the target execution statement, a preset database is queried for target data. Therefore, 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 database for target data, so that the database can directly execute the query task without going through the statement parsing and optimization process, which improves the performance of the database. query efficiency.
图1是本申请的一种数据查询方法实施例的步骤流程图;Fig. 1 is a flow chart of steps of a data query method embodiment of the present application;
图2是本申请的一种数据查询方法实施例的步骤流程图;Fig. 2 is a flow chart of steps of a data query method embodiment of the present application;
图3是本申请的一种数据查询方法实施例的步骤流程图;3 is a flow chart of steps of an embodiment of a data query method of the present application;
图4是本申请的一种数据查询方法实施例的示意图;4 is a schematic diagram of an embodiment of a data query method of the present application;
图5是本申请的一种数据查询装置实施例的结构框图;5 is a structural block diagram of an embodiment of a data query device of the present application;
图6是本申请的一种数据查询装置实施例的结构框图。FIG. 6 is a structural block diagram of an embodiment of a data query apparatus according to the present application.
为使本申请的上述目的、特征和优点能够更加明显易懂,下面结合附图和具体实施方式对本申请作进一步详细的说明。In order to make the above objects, features and advantages of the present application more clearly understood, the present application will be described in further detail below with reference to the accompanying drawings and specific embodiments.
本申请实施例针对数据库对查询语句进行词法和语义解析,优化查询语句的过程降低数据库效率这一情况,通过预先设置模板语句以及与模板语句对应的预处理信息,在获取到查询语句后,可以将查询语句与模板语句匹配,并基于所述查询语句的参数信息以及与所述查询语句匹配的模板语句对应的预处理信息,生成目标执行语句,并采用所述目标执行语句向数据库查询。所述数据库在获取所述目标执行语句后,可以无需对所述目标执行语句进行解析优化,而可以直接采用所述目标执行语句执行数据查询任务,返回数据查询结果,提高了数据库的处理效率。The embodiment of the present application is aimed at the situation that the database performs lexical and semantic analysis on the query statement, and the process of optimizing the query statement reduces the efficiency of the database. The query statement is 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 acquiring the target execution statement, the database can directly use the target execution statement to perform a data query task without analyzing and optimizing the target execution statement, and return the data query result, thereby improving the processing efficiency of the database.
参照图1,示出了本申请的一种数据查询方法实施例的步骤流程图,具体可以包括如下步骤:Referring to FIG. 1, a flow chart of steps of an embodiment of a data query method of the present application is shown, which may specifically include the following steps:
步骤101,获取查询语句;其中,所述查询语句包括参数信息; Step 101, obtaining a query statement; wherein, the query statement includes parameter information;
在本申请实施例中,可以获取用户发送的查询语句。所述查询语句可以用于向预设的数据库查询目标数据。所述查询语句可以包括参数信息,所述参数信息可以为查询语句中可变数量参数的信息。例如,在查询语句“select name from a limit 1”中,1可以为所述参数信息。In this embodiment of the present application, the query statement sent by the user can be acquired. The query statement can 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 can be the parameter information.
步骤102,查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息; Step 102, searching for a preset template statement matching the query statement, and acquiring preprocessing information corresponding to the template statement;
在本申请实施例中,可以存储有若干预设的模板语句,以及所述模板语句与预处理信息之间的对应关系。可以查找与所述查询语句匹配的预设的模板语句,并根据所述模 板语句与所述预处理信息之间的对应关系,获取所述模板语句对应的预处理信息。In this embodiment of the present application, several preset template statements may be stored, as well as the corresponding relationship between the template statements and preprocessing information. A preset template statement matching the query statement can be searched, and the preprocessing information corresponding to the template statement can be acquired according to the correspondence between the template statement and the preprocessing information.
其中,所述预处理信息可以为所述数据库对所述模板语句预先解析得到的信息。从而对于数据库来说可以采用所述预处理信息执行与所述模板语句相似的查询任务的情况下,可以无需再次解析获取到的语句,而可以基于所述预处理信息直接执行数据查询任务。The preprocessing information may be information obtained by preparsing the template statement by the database. Therefore, when the database can use the preprocessing information to perform a query task similar to the template statement, it is not necessary to parse the acquired statement again, and the data query task can be directly performed based on the preprocessing information.
在具体实现中,若所述模板语句除所述参数信息之外,皆与所述查询语句相同,则可以认为所述查询语句与所述模板语句匹配。In a specific implementation, if the template statement is the same as the query statement except for the parameter information, it can be considered that the query statement matches the template statement.
步骤103,采用所述预处理信息以及所述参数信息,生成目标执行语句; Step 103, using the preprocessing information and the parameter information to generate a target execution statement;
在本申请实施例中,可以采用所述预处理信息以及所述参数信息,生成目标执行语句。所述目标执行语句可以用于查询与所述查询语句相同的目标数据。In this embodiment of the present application, the preprocessing information and the parameter information may be used to generate a target execution statement. The target execution statement can be used to query the same target data as the query statement.
步骤104,采用所述目标执行语句,向预设的数据库查询目标数据。 Step 104, using the target execution statement to query target data from a preset database.
在本申请实施例中,可以采用所述目标执行语句,向预设的数据库查询目标数据。由于所述目标执行语句包含所述预处理信息,所述数据库可以无需再次解析所述目标执行语句,而可以直接采用所述目标执行语句中包含的预处理信息以及所述参数信息,执行查询任务,查询所述目标数据。In this embodiment of the present application, the target execution statement may be used to query target data from a preset database. Since the target execution statement contains the preprocessing information, the database can directly use the preprocessing information and the parameter information contained in the target execution statement without parsing the target execution statement again to execute the query task , query the target data.
由此,对于用户发送的查询语句,在已有模板语句的情况下,可以将所述查询语句转换为目标执行语句,并采用所述目标执行语句向预设的数据查询目标数据。从而所述数据库无需再次解析获取到的目标执行语句即可直接执行查询任务,查询得到目标数据,提高了查询处理效率。Thus, for the query statement sent by the user, in the case of an existing template statement, the query statement can be converted into a target execution statement, and the target execution statement can be used to query the preset data for target data. Therefore, the database can directly execute the query task without re-analyzing the obtained target execution statement, and obtain the target data by query, thereby improving the query processing efficiency.
作为本申请的一种示例,所述查询语句为“select*from a limit 1”,可以在查找到与所述查询语句匹配的模板语句后,获取所述模板语句对应的预处理信息,采用所述预处理信息以及所述参数信息,生成目标执行语句。所述数据库可以采用所述目标执行语句中包含的预处理信息以及所述参数信息,得知用户希望查询的是“select*from a limit1”,并执行查询任务,返回目标数据。As an example of the present application, the query statement is "select*from a limit 1", and after finding a template statement matching the query statement, the preprocessing information corresponding to the template statement can be obtained, using the The preprocessing information and the parameter information are 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 learn that what the user wants to query is "select*from a limit1", and execute the query task to return the target data.
在具体实现中,可以预设一中间件,所述中间件可以同时与用户以及数据库进行通信。所述中间件中存储有若干预设的模板语句,以及所述模板语句与预处理信息之间的对应关系。在获取到用户发送的查询语句后,所述中间件可以查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息,采用所述预处理信息以及所述参数信息,生成目标执行语句,采用所述目标执行语句,向预设的数据库查询目标数据。所述中间件获取得到目标数据后,可以向用户返回目标数据。从而所述中间件可以协助用户将查询语句转换为目标执行语句,提高查询效率。且用户无需对其客户端或者客户端接口进行修改,即可实现使用目标执行语句查询目标数据。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 several preset template statements, and the corresponding relationship between the template statements and preprocessing information. After acquiring the query statement sent by the user, the middleware may search for a preset template statement matching the query statement, acquire preprocessing information corresponding to the template statement, and use the preprocessing information and the The parameter information is used to generate a target execution statement, and the target execution statement is used to query the target data from a preset database. After obtaining the target data, the middleware can return the target data to the user. Therefore, the middleware can assist the user to convert the query statement into the target execution statement, thereby improving the query efficiency. In addition, users can use the target execution statement to query target data without modifying the client or the client interface.
通过本申请实施例的数据查询方法,获取查询语句;其中,所述查询语句包括参数信息;查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理 信息;采用所述预处理信息以及所述参数信息,生成目标执行语句;采用所述目标执行语句,向预设的数据库查询目标数据。从而可以将用户发送的查询语句转换为目标执行语句,并采用所述目标执行语句向数据库查询目标数据,从而所述数据库可以无需经过语句解析优化过程,即可直接执行查询任务,提高了数据库的查询效率。Obtain a query statement through the data query method of the embodiment of the present application; wherein, the query statement includes parameter information; search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement; Using the preprocessing information and the parameter information, a target execution statement is generated; using the target execution statement, a preset database is queried for target data. Therefore, 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 database for target data, so that the database can directly execute the query task without going through the statement parsing and optimization process, which improves the performance of the database. query efficiency.
参照图2,示出了本申请的一种数据查询方法实施例的步骤流程图,具体可以包括如下步骤:Referring to FIG. 2 , a flow chart of steps of an embodiment of a data query method of the present application is shown, which may specifically include the following steps:
步骤201,获取查询语句;其中,所述查询语句包括参数信息; Step 201, obtaining a query statement; wherein, the query statement includes parameter information;
在本申请实施例中,可以获取用户发送的查询语句。所述查询语句可以用于向预设的数据库查询目标数据。所述查询语句可以包括参数信息,所述参数信息可以为查询语句中可变数量参数的信息。例如,在查询语句“select name from a limit 1”中,1可以为所述参数信息。In this embodiment of the present application, the query statement sent by the user can be acquired. The query statement can 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 can be the parameter information.
步骤202,查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;Step 202, searching for a preset template statement matching the query statement, and acquiring preprocessing information corresponding to the template statement;
在本申请实施例中,可以存储有若干预设的模板语句,以及所述模板语句与预处理信息之间的对应关系。可以查找与所述查询语句匹配的预设的模板语句,并根据所述模板语句与所述预处理信息之间的对应关系,获取所述模板语句对应的预处理信息。In this embodiment of the present application, several preset template statements may be stored, as well as the corresponding relationship between the template statements and preprocessing information. A preset template statement matching the query statement may be searched for, and preprocessing information corresponding to the template statement may be acquired according to the correspondence between the template statement and the preprocessing information.
其中,所述预处理信息可以为所述数据库对所述模板语句预先解析得到的信息。从而对于数据库来说可以采用所述预处理信息执行与所述模板语句相似的查询任务的情况下,可以无需再次解析获取到的语句,而可以基于所述预处理信息直接执行数据查询任务。The preprocessing information may be information obtained by preparsing the template statement by the database. Therefore, when the database can use the preprocessing information to perform a query task similar to the template statement, it is not necessary to parse the acquired statement again, and the data query task can be directly performed based on the preprocessing information.
在具体实现中,若所述模板语句除所述参数信息之外,皆与所述查询语句相同,则可以认为所述查询语句与所述模板语句匹配。In a specific implementation, if the template statement is the same as the query statement except for the parameter information, it can be considered that the query statement matches the template statement.
所述查找与所述查询语句匹配的预设的模板语句步骤,包括:The step of searching for a preset template statement matching the query statement includes:
S11,查找除所述参数信息之外与所述查询语句相同的模板语句,作为与所述查询语句匹配的预设的模板语句。S11: Search for a template statement that is the same as the query statement except for the parameter information, as a preset template statement matching the query statement.
在本申请实施例中,与所述查询语句匹配的所述模板语句可以除所述参数信息与所述查询语句不同之外,其余部分与所述查询语句相同。由此,可以查找是否存在除所述参数信息之外与所述查询语句相同的模板语句,作为与所述查询语句匹配的预设的目标语句。In this embodiment of the present application, the template statement matching the query statement may be the same as the query statement except that the parameter information is different from the query statement. In this way, it is possible to find out whether there is a template statement that is the same as the query statement except for the parameter information, as a preset target statement matching the query statement.
作为本申请的一种示例,若所述查询语句为“select*from t limit 1”,则与所述查询语句匹配的模板语句可以为“select*from t limit?”。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?".
在本申请的一种实施例中,所述方法还包括:In an embodiment of the present application, the method further includes:
S21,在所述查询语句不存在匹配的模板语句的情况下,根据所述查询语句,生成模板语句;S21, in the case that the query statement does not have a matching template statement, generate a template statement according to the query statement;
在本申请实施例中,在所述查询语句不存在匹配的模板语句的情况下,则可以根据所述查询语句,生成模板语句,便于后续提高同类型查询语句的处理效率。In the embodiment of the present application, in the case that the query statement does not have a matching template statement, a template statement can be generated according to the query statement, so as to facilitate the subsequent improvement of processing efficiency of query statements of the same type.
在本申请的一种实施例中,所述根据所述查询语句,生成模板语句的步骤,包括:In an embodiment of the present application, the step of generating a template statement according to the query statement includes:
S31,将所述查询语句中的参数信息,替换为占位符信息,生成模板语句。S31 , replace the parameter information in the query statement with placeholder information to generate a template statement.
在本申请实施例中,由于所述模板语句需要适配包含不同参数信息的查询语句,可以将所述查询语句中的参数信息,替换为占位符信息,从而可以生成模板语句。In the embodiment of the present application, since the template statement needs to be adapted to query statements 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.
作为本申请的一种示例,查询语句为“select name from a where id between 1and 2”,其中的参数信息为“1”和“2”,可以采用占位符“?”替换所述参数信息为“1”和“2”,得到模板语句“select name from a where id between?and?”。As an example of this application, the query statement is "select name from a where id between 1and 2", where the parameter information is "1" and "2", the placeholder "?" can be used to replace the parameter information with "1" and "2", resulting in the template statement "select name from a where id between?and?".
S22,采用所述模板语句,生成预处理语句;S22, using the template statement to generate a prepared statement;
在本申请实施例中,可以采用所述模板语句,生成向数据库获取预处理信息的预处理语句。In this embodiment of the present application, the template statement may be used to generate a preprocessing statement for acquiring preprocessing information from a database.
在具体实现中,可以采用所述模板语句,生成符合数据库通讯协议的二进制的预处理语句。作为本申请的一种具体实现方式,所述预处理语句可以为COM_STMT_PREPARE类型的报文。In a specific implementation, the template statement can be used to generate a binary prepared statement conforming to the database communication protocol. As a specific implementation manner of the present application, the prepared statement may be a message of type COM_STMT_PREPARE.
S23,向所述数据库发送所述预处理语句,获取所述数据库返回的预处理信息。S23: Send the preprocessing statement to the database, and obtain the preprocessing information returned by the database.
在本申请实施例中,可以向所述数据库发送所述预处理语句,所述数据库可以对所述预处理语句进行解析处理,生成预处理信息并返回,从而可以获取所述数据库返回的预处理信息。In this embodiment of the present application, the preprocessed statement may be sent to the database, and the database may perform parsing processing on the preprocessed statement, generate preprocessing information, and return it, so as to obtain the preprocessed statement returned by the database. information.
在具体实现中,所述数据库返回的预处理信息中可以包括预处理标识信息,以及参数类型信息。其中,所述预处理标识信息可以为所述数据库为所述预处理语句分配的标识信息。所述参数类型信息为所述数据库记录的所述预处理语句可以设置的参数的类型。所述参数类型可以为整型、字符串型等,本申请对此不做限制。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 allocated by the database to the preprocessing statement. The parameter type information is the type of parameters that can be set by the prepared statement recorded in the database. The parameter type may be an integer type, a string type, etc., which is not limited in this application.
作为本申请的一种示例,所述数据库针对所述预处理语句返回的预处理信息可以包括:status(状态信息)、statement_id(预处理标识信息)、num_columns(列数)、num_params(参数数量)、reserved_1(预留填充符)、warning_count(警告次数)、Parameter Definition Block(参数类型信息)以及Column Definition Block(列定义信息)。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), and num_params (number of parameters) , reserved_1 (reserved filler), warning_count (warning times), Parameter Definition Block (parameter type information), and Column Definition Block (column definition information).
在本申请的一种实施例中,所述查找与所述查询语句匹配的预设的模板语句的步骤,包括:In an embodiment of the present application, the step of searching for a preset template statement matching the query statement includes:
S41,确定所述查询语句是否符合预设格式;S41, determine whether the query statement conforms to a preset format;
在本申请实施例中,所述用户发送的查询语句可以为多个不同格式类型。而本申请可以针对符合预设格式的查询语句,将其与模板语句匹配,并转换为目标执行语句。而对于不符合格式的查询语句,可以不对其进行处理。由此,可以确定所述查询语句是否符合预设格式。In this embodiment of the present application, the query statement sent by the user may be in multiple different formats. In the present application, a query statement that conforms to a preset format can be matched with a template statement and converted into a target execution statement. For the query statement that does not conform to the format, it may not be processed. Thus, it can be determined whether the query statement conforms to the preset format.
其中,所述预设格式可以根据实际需要进行设置,例如,所述预设格式可以为简单查询语句、复杂查询语句、多表查询语句、嵌套查询语句、参数化查询语句中的至少一种,本申请对此不做限制。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 limit it.
S42,在所述查询语句符合预设格式的情况下,查找与所述查询语句匹配的预设的模板语句;S42, when the query statement conforms to a preset format, search for a preset template statement matching the query statement;
在本申请实施例中,在所述查询语句符合预设格式的情况下,则此时可以将所述查询语句转换为目标执行语句。可以查询与所述查询语句匹配的预设的模板语句,并执行获取所述模板语句对应的预处理信息,采用所述预处理信息以及所述参数信息,生成目标执行语句,采用所述目标执行语句,向预设的数据库查询目标数据的步骤。In this 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 at this time. The preset template statement matching the query statement can be queried, and 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, and executed by using the target statement. statement, the step of querying the target data from the preset database.
S43,在所述查询语句不符合预设格式的情况下,将所述查询语句转发至所述数据库。S43, if the query statement does not conform to the preset format, forward the query statement to the database.
在本申请实施例中,在所述查询语句不符合预设格式的情况下,则此时可以不需要将所述查询语句转换为目标执行语句。则此时可以直接将所述查询语句转发至所述数据库,由所述数据库直接解析所述查询语句并返回目标数据。In this embodiment of the present application, if the query statement does not conform to the preset format, it may not be necessary to convert the query statement into a target execution statement at this time. At this time, the query statement can be directly forwarded to the database, and the database can directly parse the query statement and return the target data.
在本申请实施例中,在查询语句符合预设格式的情况下,可以进一步确定所述查询语句是否包含参数信息,在所述查询语句不包含参数信息的情况下,可以认为所述查询语句不适用于将所述查询语句转换为目标执行语句,则此时也可以直接将所述查询语句转发至所述数据库,由所述数据库直接解析所述查询语句并返回目标数据。In the embodiment of the present application, if the query statement conforms to the preset format, it may be further determined whether the query statement contains parameter information, and if the query statement does not contain parameter information, it may be considered that the query statement does not contain parameter information. If it is suitable for converting the query statement into a target execution statement, the query statement can also be directly forwarded to the database at this time, and the database directly parses the query statement and returns the target data.
由此,可以实现将查询语句转换为目标执行语句的动态开启与关闭,对符合预设格式的查询语句执行将查询语句转换为目标执行语句,而对于不符合预设格式的查询语句可以直接转发至所述数据库,由所述数据库直接解析处理所述查询语句。In this way, the dynamic opening and closing of converting the query statement into the target execution statement can be realized, the query statement that conforms to the preset format is executed and the query statement is converted into the target execution statement, and the query statement that does not conform to the preset format can be directly forwarded to the database, and the query statement is directly parsed and processed by the database.
作为本申请的一种示例,所述预设格式可以为非参数化的查询语句。获取到的查询语句为非参数化的查询语句的情况下,可以将查询语句转换为目标执行语句,执行查询与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息,采用所述预处理信息以及所述参数信息,生成目标执行语句,采用所述目标执行语句,向预设的数据库查询目标数据的步骤。在获取到的查询语句为参数化的查询语句的情况下,则此时可以不需要对查询语句进行处理,而可以直接转发所述查询语句至所述数据库。As an example of the present application, the preset format may be a non-parameterized query statement. When the obtained query statement is a non-parameterized query statement, the query statement can be converted into a target execution statement, the query statement is executed, and the preset template statement matching the query statement is executed, and the preset template statement corresponding to the template statement is obtained. Processing information, using the preprocessing information and the parameter information, generating a target execution statement, and querying a preset database for target data by using the target execution statement. If the obtained query statement is a parameterized query statement, the query statement may not need to be processed at this time, and the query statement may be directly forwarded to the database.
在本申请的一种实施例中,所述方法还包括:In an embodiment of the present application, the method further includes:
S51,生成所述模板语句、所述预处理标识信息、以及参数类型信息之间的映射关系。S51. Generate a mapping relationship among the template statement, the preprocessing identification information, and the parameter type information.
在本申请实施例中,可以生成所述模板语句、所述预处理标识信息、以及所述参数类型信息之间的映射关系,并存储所述映射关系。从而在获取所述查询语句之后,查找与所述查询语句匹配的模板语句,并根据所述映射关系,确定所述查询语句对应的预处理标识信息以及参数类型信息,进一步提高处理效率。In this embodiment of the present application, a mapping relationship between the template statement, the preprocessing identification information, and the parameter type information may be generated, and the mapping relationship may be stored. Therefore, after acquiring 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.
在具体实现中,所述模板语句可以基于哈希算法(hash)转换为哈希值,再生成所述哈希值、所述预处理标识信息、以及所述参数类型信息之间的映射关系,并存储所述 映射关系,从而可以在减少数据量的同时,确保数据安全。In a specific implementation, the template statement may 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, so that data security can be ensured while reducing the amount of data.
作为本申请的一种示例,查询语句为“select name from a limit 888”,可以将所述查询语句中的参数信息“888”用占位符“?”替换,得到模板语句“select name from a limit?”。其后,可以将模板语句“select name from a limit?”转换为哈希值“abdc”,在确定所述预处理信息为预处理标识信息为“3”,参数类型信息为“int”之后,可以生成所述模板语句、所述预处理标识信息、以及参数类型信息之间的映射关系{abdc=>{3,{int,?}}。As an example of this application, the query statement is "select name from a limit 888", the parameter information "888" in the query statement can be replaced with a placeholder "?" to obtain the template statement "select name from a limit 888" limit?". Thereafter, the template statement "select name from a limit?" can be converted into a hash value "abdc", after determining that the preprocessing information is the preprocessing identification information "3" and the parameter type information is "int", A mapping relationship between the template statement, the preprocessing identification information, and the parameter type information can be generated {abdc=>{3,{int,? }}.
步骤203,采用所述预处理信息、所述参数信息、以及预设的编码标识信息,生成目标执行语句;所述编码标识信息用于指示所述数据返回基于文本协议编码的目标数据; Step 203, using the preprocessing information, the parameter information, and the preset encoding identification information to generate a target execution statement; the encoding identification information is used to instruct the data to return the target data encoded based on the text protocol;
在本申请实施例中,可以采用所述预处理信息、所述参数信息、以及预设的编码标识信息,生成目标执行语句;所述编码标识信息用于指示所述数据返回基于文本协议编码的目标数据。In this embodiment of the present application, the preprocessing information, the parameter information, and the preset coding identification information may be used to generate a target execution statement; the coding identification information is used to instruct the data to return a text protocol-encoded based target data.
其中,所述目标执行语句可以为基于二进制编码的语句。由此,可以采用所述预处理信息以及所述参数信息,生成包含所述预处理信息以及所述参数信息的目标执行语句,并将所述目标执行语句转换为基于二进制编码协议的语句。作为本申请的一种示例,所述目标执行语句可以为COM_STMT_EXECUTE报文。Wherein, the target execution statement may be a statement based on binary coding. Thus, the preprocessing information and the parameter information can be used to generate a target execution statement including the preprocessing information and the parameter information, and the target execution statement can be converted into a statement based on a binary encoding protocol. As an example of the present application, the target execution statement may be a COM_STMT_EXECUTE message.
在具体实现中,一般来说,所述数据库可以针对所述目标执行语句,基于二进制协议的编码方式返回目标数据。然而,由于所述查询语句通常返回的是基于文本协议编码方式的目标数据。因此,可以采用所述编码标识信息,设置所述数据库针对所述目标执行语句返回基于文本协议编码的目标数据。In a specific implementation, in general, the database may execute a statement for the target, and return target data in an encoding manner based on a binary protocol. However, because the query statement usually returns the target data based on the encoding method of the text protocol. Therefore, the encoding identification information can be used to set the database to return the target data encoded based on the text protocol for the target execution statement.
所述数据库在获取所述目标执行语句后,可以根据所述目标执行语句中包含的编码标识信息,确定返回基于文本协议编码方式的目标数据。从而用户最终获取得到的目标数据可以是基于文本协议编码的。After acquiring the target execution statement, the database may determine to return target data based on a text protocol encoding method according to the encoding identification information contained in the target execution statement. Therefore, the target data finally obtained by the user may be encoded based on the text protocol.
作为本申请的一种示例,所述目标执行语句中可以存在标志位(flag),一般来说,标志位为8字节的字段,数据库通常只使用后4位。可以将所述标志位的前4位用作自定义的编码标识信息,设置为0x80。可以设置所述数据库在接收到标志位包含0x80编码标识信息的目标执行语句后,采用文本协议编码返回目标数据。从而虽然采用了基于二进制协议编码的目标执行语句获取目标数据,最后返回的目标数据可以仍然为基于文本协议编码的,对于用户来说,仍然是发出了基于文本协议编码的查询语句,得到了基于文本协议编码的目标数据,而数据库的处理效率得到了提高。As an example of the present application, a flag bit (flag) may exist in the target execution statement. Generally speaking, the flag bit is a field of 8 bytes, and the database usually only uses the last 4 bits. The first 4 bits of the flag bits can be used as self-defined encoding identification information and set to 0x80. The database may be configured to use text protocol encoding to return the target data after receiving the target execution statement whose flag bit contains 0x80 encoded identification information. Therefore, although the target execution statement based on the binary protocol encoding is used to obtain the target data, the final returned target data can still be encoded based on the text protocol. The target data is encoded in the text protocol, and the processing efficiency of the database is improved.
步骤204,采用所述目标执行语句,向预设的数据库查询目标数据。Step 204, using the target execution statement to query a preset database for target data.
在本申请实施例中,可以采用所述目标执行语句,向预设的数据库查询目标数据。由于所述目标执行语句包含所述预处理信息,所述数据库可以无需再次解析所述目标执行语句,而可以直接采用所述目标执行语句中包含的预处理信息以及所述参数信息,执行查询任务,查询所述目标数据。In this embodiment of the present application, the target execution statement may be used to query target data from a preset database. Since the target execution statement contains the preprocessing information, the database can directly use the preprocessing information and the parameter information contained in the target execution statement without parsing the target execution statement again to execute the query task , query the target data.
作为本申请的一种示例,所述查询语句为“select*from a limit 1”,其中参数信息为“1”。可以在查找到与所述查询语句匹配的模板语句后,获取所述模板语句对应的预处理信息,所述预处理信息包括预处理标识信息“3”以及参数类型信息“int”,可以采用预处理标识信息“3”、参数类型信息“int”以及所述参数信息“1”,生成目标执行语句。所述数据库可以采用所述目标执行语句中包含的预处理信息以及所述参数信息,得知用户希望查询的是“select*from a limit 1”,并执行查询任务,返回目标数据。As an example of this application, the query statement is "select*from a limit 1", and the parameter information is "1". After a template statement matching the query statement is found, the preprocessing information corresponding to the template statement can be obtained, and the preprocessing information includes the preprocessing identification information "3" and the parameter type information "int". The identification information "3", the parameter type information "int", and the parameter information "1" are processed to generate a target execution statement. The database can use the preprocessing information and the parameter information contained in the target execution statement to learn that what the user wants to query is "select*from a limit 1", and execute the query task to return the target data.
由此,对于用户发送的查询语句,在已有模板语句的情况下,可以将所述查询语句转换为目标执行语句,并采用所述目标执行语句向预设的数据查询目标数据。从而所述数据库无需再次解析获取到的目标执行语句即可直接执行查询任务,查询得到目标数据,提高了查询处理效率。Thus, for the query statement sent by the user, in the case of an existing template statement, the query statement can be converted into a target execution statement, and the target execution statement can be used to query the preset data for target data. Therefore, the database can directly execute the query task without re-analyzing the obtained target execution statement, and obtain the target data by query, thereby improving the query processing efficiency.
在具体实现中,可以预设一中间件,所述中间件可以同时与用户以及数据库进行通信。所述中间件中存储有若干预设的模板语句,以及所述模板语句与预处理信息之间的对应关系。在获取到用户发送的查询语句后,所述中间件可以查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息,采用所述预处理信息以及所述参数信息,生成目标执行语句,采用所述目标执行语句,向预设的数据库查询目标数据。所述中间件获取得到目标数据后,可以向用户返回目标数据。从而所述中间件可以协助用户将查询语句转换为目标执行语句,提高查询效率。且用户无需对其客户端或者客户端接口进行修改,即可实现使用目标执行语句查询目标数据。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 several preset template statements, and the corresponding relationship between the template statements and preprocessing information. After acquiring the query statement sent by the user, the middleware may search for a preset template statement matching the query statement, acquire preprocessing information corresponding to the template statement, and use the preprocessing information and the The parameter information is used to generate a target execution statement, and the target execution statement is used to query the target data from a preset database. After obtaining the target data, the middleware can return the target data to the user. Therefore, the middleware can assist the user to convert the query statement into the target execution statement, thereby improving the query efficiency. In addition, users can use the target execution statement to query target data without modifying the client or the client interface.
通过本申请实施例的数据查询方法,获取查询语句;其中,所述查询语句包括参数信息;查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;采用所述预处理信息、所述参数信息、以及预设的编码标识信息,生成目标执行语句;采用所述目标执行语句,向预设的数据库查询目标数据。从而可以将用户发送的查询语句转换为目标执行语句,并采用所述目标执行语句向数据库查询目标数据,从而所述数据库可以无需经过语句解析优化过程,即可直接执行查询任务,提高了数据库的查询效率。Obtain a query statement through the data query method of the embodiment of the present application; wherein, the query statement includes parameter information; search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement; Using the preprocessing information, the parameter information, and the preset coding identification information, a target execution statement is generated; and the target execution statement is used to query a preset database for target data. Therefore, 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 database for target data, so that the database can directly execute the query task without going through the statement parsing and optimization process, which improves the performance of the database. query efficiency.
参照图3,示出了本申请的一种数据查询方法实施例的步骤流程图,其应用于查询处理中间件,所述查询处理中间件同时与客户端以及数据库通信。Referring to FIG. 3 , a flow chart of steps of an embodiment of a data query method of the present application is shown, which is applied to query processing middleware, and the query processing middleware communicates with the client and the database at the same time.
在本申请实施例中,用户的客户端通常较难进行改动,而如果用户需要使用预处理语句以及目标执行语句,通常需要对所述客户端进行修改、更新,才可以使所述客户端使用预处理语句以及目标执行语句。特别是对于线上应用来说,重启线上应用使所述线上应用可以使用预处理语句以及目标执行语句是较为困难的。并且,如果用户不正确地使用预处理语句以及目标执行语句,无论是否存在模板语句,都针对查询语句获取预处理信息,再生成目标执行语句获取目标数据,反而容易导致数据库消耗更多的计算资源。In the embodiment of the present application, it is usually difficult to modify the client of the user, and if the user needs to use prepared statements and target execution statements, the client usually needs to be modified and updated before the client can use 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 incorrectly uses the prepared statement and the target execution statement, regardless of whether there is a template statement, the preprocessing information is obtained for the query statement, and then the target execution statement is generated to obtain the target data, which will easily cause the database to consume more computing resources. .
由此,可以在所述用户的客户端与所述数据库之间设置一查询处理中间件,所述查 询处理中间件同时与客户端以及数据库通信。所述查询处理中间键可以将客户端发送的查询语句转换为目标执行语句,采用目标执行语句向所述数据库获取目标数据,从而用户可以无需对应用程序改动,即可使用目标执行预设获取数据库的目标数据,从而可以有效地提高数据库的处理效率,且用户容易使用。Thus, a query processing middleware can be set between the user's client and the database, and the query processing middleware communicates with the client and the database at the same time. The query processing intermediate key can convert the query statement sent by the client into a target execution statement, and use the target execution statement to obtain target data from the database, so that the user can use the target execution preset to obtain the database without changing the application program. The target data can effectively improve the processing efficiency of the database, and it is easy for users to use.
所述方法具体可以包括如下步骤:The method may specifically include the following steps:
步骤301,所述查询处理中间件获取所述客户端发送的查询语句;其中,所述查询语句包括参数信息; Step 301, the query processing middleware obtains a query statement sent by the client; wherein the query statement includes parameter information;
在本申请实施例中,所述查询处理中间件可以获取用户的所述客户端发送的查询语句。所述查询语句可以用于向预设的数据库查询目标数据。所述查询语句可以包括参数信息,所述参数信息可以为查询语句中可变数量参数的信息。In this embodiment of the present application, the query processing middleware may acquire a query statement sent by the client of the user. The query statement can 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.
步骤302,所述查询处理中间件查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;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;
在本申请实施例中,所述查询处理中间件可以存储有若干预设的模板语句,以及所述模板语句与预处理信息之间的对应关系。所述查询处理中间件可以查找与所述查询语句匹配的预设的模板语句,并根据所述模板语句与所述预处理信息之间的对应关系,获取所述模板语句对应的预处理信息。In this embodiment of the present application, the query processing middleware may store several preset template statements, as well as the correspondence between the template statements and preprocessing information. The query processing middleware may search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement according to the correspondence between the template statement and the preprocessing information.
其中,所述预处理信息可以为所述数据库对所述模板语句预先解析得到的信息。从而对于数据库来说可以采用所述预处理信息执行与所述模板语句相似的查询任务的情况下,可以无需再次解析获取到的语句,而可以基于所述预处理信息直接执行数据查询任务。The preprocessing information may be information obtained by preparsing the template statement by the database. Therefore, when the database can use the preprocessing information to perform a query task similar to the template statement, it is not necessary to parse the acquired statement again, and the data query task can be directly performed based on the preprocessing information.
在具体实现中,若所述模板语句除所述参数信息之外,皆与所述查询语句相同,则可以认为所述查询语句与所述模板语句匹配。In a specific implementation, if the template statement is the same as the query statement except for the parameter information, it can be considered that the query statement matches the template statement.
步骤303,所述查询处理中间件采用所述预处理信息以及所述参数信息,生成目标执行语句; Step 303, the query processing middleware uses the preprocessing information and the parameter information to generate a target execution statement;
在本申请实施例中,所述查询处理中间件可以采用所述预处理信息以及所述参数信息,生成目标执行语句。所述目标执行语句可以用于查询与所述查询语句相同的目标数据。In this 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 can be used to query the same target data as the query statement.
步骤304,所述查询处理中间件向所述数据库发送所述目标执行语句,并获取所述数据库返回的目标数据。 Step 304, the query processing middleware sends the target execution statement to the database, and obtains the target data returned by the database.
在本申请实施例中,所述查询处理中间件可以采用所述目标执行语句,向预设的数据库查询目标数据。由于所述目标执行语句包含所述预处理信息,所述数据库可以无需再次解析所述目标执行语句,而可以直接采用所述目标执行语句中包含的预处理信息以及所述参数信息,执行查询任务,查询所述目标数据。其后,所述查询处理中间件可以获取所述数据库返回的目标数据。In this embodiment of the present application, the query processing middleware may use the target execution statement to query a preset database for target data. Since the target execution statement contains the preprocessing information, the database can directly use the preprocessing information and the parameter information contained in the target execution statement without parsing the target execution statement again to execute the query task , query the target data. Thereafter, the query processing middleware may acquire the target data returned by the database.
由此,对于所述客户端发送的查询语句,在所述查询处理中间件已有模板语句的情况下,所述查询处理中间件可以将所述查询语句转换为目标执行语句,并采用所述目标执行语句向所述数据查询目标数据。从而所述数据库无需再次解析获取到的目标执行语句即可直接执行查询任务,查询得到目标数据,提高了查询处理效率。Therefore, 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 The target execution statement queries the data for target data. Therefore, the database can directly execute the query task without re-analyzing the obtained target execution statement, and obtain the target data by query, thereby improving the query processing efficiency.
步骤305,所述查询处理中间件向所述客户端返回所述目标数据。 Step 305, the query processing middleware returns the target data to the client.
在本申请实施例中,所述查询处理中间件可以向所述客户端返回所述目标数据,从而所述客户端可以获取得到所述查询语句对应的目标数据。而由于所述查询处理中间件将所述查询语句转换为目标执行语句后在向所述数据库获取目标数据。所述数据库的处理效率得到提高。In this embodiment of the present application, the query processing middleware may return the target data to the client, so that the client may obtain the target data corresponding to the query statement. However, the query processing middleware obtains target data from the database after converting the query statement into a target execution statement. The processing efficiency of the database is improved.
在本申请实施例中,所述客户端可以根据实际需要,开启或关闭所述查询处理中间件将所述查询语句转换为目标执行语句的功能。所述查询处理中间件可以根据实际需要,将符合预设格式的查询语句转换为目标执行语句,对不符合预设格式的查询语句则直接转发至所述数据库,从而可以根据实际需要,实现对查询语句转换为目标执行语句功能的动态使用。In this embodiment of the present application, the client may, according to actual needs, enable or disable the function of the query processing middleware to convert the query statement into a target execution statement. The query processing middleware can convert the query statements that conform to the preset format into target execution statements according to actual needs, and directly forward the query statements that do not conform to the preset format to the database, so that the query statement can be implemented according to actual needs. The query statement is converted into the dynamic use of the target execution statement function.
作为本申请的一种示例,图4为本申请实施例的一种数据查询方法实施例的示意图。其中包括客户端401、查询处理中间件402、以及数据库403。As an example of the present application, FIG. 4 is a schematic diagram of an embodiment of a data query method according to an embodiment of the present application. It includes the client 401 , the query processing middleware 402 , and the database 403 .
所述客户端401可以向所述查询处理中间件402发送查询语句,在所述查询处理中间件402不存在与所述查询语句匹配的模板语句的情况下,可以根据所述查询语句,生成模板语句;根据所述模板语句生成预处理语句,将所述预处理语句向所述数据库403发送。所述数据库403可以向所述查询处理中间件402返回预处理标识信息以及参数类型信息。其后,所述查询处理中间件402可以基于所述预处理标识信息以及参数类型信息,以及所述查询语句中的参数信息,生成目标执行语句,并将所述数据库403发送所述目标执行语句,所述数据库403可以针对所述目标执行语句向所述查询处理中间件402返回目标数据。其后所述查询处理中间件402可以将所述目标数据转发至所述客户端401,所述客户端401可以获取得到针对所述查询语句的目标数据。The client 401 may send a query statement to the query processing middleware 402, and if the query processing middleware 402 does not have a template statement matching the query statement, a template may be generated according to the query statement statement; generate a prepared statement according to the template statement, and send the prepared statement to the database 403 . The database 403 may return preprocessing identification information and parameter type information to the query processing middleware 402 . Thereafter, the query processing middleware 402 may generate a target execution statement based on the preprocessing identification information and parameter type information, and the parameter information in the query statement, and send the target execution statement to the database 403. , the database 403 may return target data to the query processing middleware 402 for the target execution statement. Thereafter, the query processing middleware 402 may forward the target data to the client 401, and the client 401 may obtain the target data for the query statement.
通过本申请实施例的数据查询方法,所述查询处理中间件获取所述客户端发送的查询语句;其中,所述查询语句包括参数信息;所述查询处理中间件查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;所述查询处理中间件采用所述预处理信息以及所述参数信息,生成目标执行语句;所述查询处理中间件向所述数据库发送所述目标执行语句,并获取所述数据库返回的目标数据;所述查询处理中间件向所述客户端返回所述目标数据。从而可以在不改动客户端的情况下,所述查询处理中间件将所述客户端发送的查询语句转换为目标执行语句,并采用所述目标执行语句向数据库查询目标数据,从而所述数据库可以无需经过语句解析优化过程,即可直接执行查询任务,提高了数据库的查询效率。With 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 the query statement that matches the query statement. preset template statement, and obtain 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 reports to the The database sends the target execution statement, and obtains the target data returned by the database; the query processing middleware returns the target data to the client. Therefore, 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 After the statement parsing and optimization process, the query task can be directly executed, which improves the query efficiency of the database.
需要说明的是,对于方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请实施例并不受所描述的动作顺序的限制,因为依据本申请实施例,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作并不一定是本申请实施例所必须的。It should be noted that, for the sake of simple description, the method embodiments are expressed as a series of action combinations, but those skilled in the art should know that the embodiments of the present application are not limited by the described action sequence, because According to the embodiments of the present application, certain steps may be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know 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.
参照图5,示出了本申请的一种数据查询装置实施例的结构框图,具体可以包括如下模块:Referring to FIG. 5, a structural block diagram of an embodiment of a data query apparatus of the present application is shown, which may specifically include the following modules:
第一查询语句获取模块501,用于获取查询语句;其中,所述查询语句包括参数信息;The first query statement obtaining module 501 is used to obtain a query statement; wherein, the query statement includes parameter information;
第一目标语句查找模块502,用于查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;The first target statement search module 502 is configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;
第一目标执行语句生成模块503,用于采用所述预处理信息以及所述参数信息,生成目标执行语句;a first target execution statement generation module 503, configured to generate a target execution statement by using the preprocessing information and the parameter information;
第一查询模块504,用于采用所述目标执行语句,向预设的数据库查询目标数据。The first query module 504 is configured to use the target execution statement to query target data from a preset database.
在本申请一种实施例中,所述装置还包括:In an embodiment of the present application, the device further includes:
模板生成模块,用于在所述查询语句不存在匹配的模板语句的情况下,根据所述查询语句,生成模板语句;a template generation module, configured to generate a template statement according to the query statement when the query statement does not have a matching template statement;
预处理语句生成模块,用于采用所述模板语句,生成预处理语句;a prepared statement generation module for generating a prepared statement by using the template statement;
预处理信息获取模块,用于向所述数据库发送所述预处理语句,获取所述数据库返回的预处理信息。The preprocessing information acquiring module is configured to send the preprocessing statement to the database, and acquire the preprocessing information returned by the database.
在本申请一种实施例中,所述预处理信息包括预处理标识信息以及参数类型信息;In an embodiment of the present application, the preprocessing information includes preprocessing identification information and parameter type information;
所述装置还包括:The device also includes:
映射生成模块,用于生成所述模板语句、所述预处理标识信息、以及参数类型信息之间的映射关系。The mapping generation module is used for generating the mapping relationship among the template statement, the preprocessing identification information, and the parameter type information.
在本申请一种实施例中,所述第一目标执行语句生成模块包括:In an embodiment of the present application, the first target execution statement generation module includes:
目标执行语句生成子模块,用于采用所述预处理信息、所述参数信息、以及预设的编码标识信息,生成目标执行语句;所述编码标识信息用于指示所述数据返回基于文本协议编码的目标数据。A target execution statement generation submodule is used to generate a target execution statement by using the preprocessing information, the parameter information, and the preset encoding identification information; the encoding identification information is used to instruct the data to be returned based on text protocol encoding target data.
在本申请一种实施例中,所述第一目标语句查找模块包括:In an embodiment of the present application, the first target sentence search module includes:
第一目标语句查找子模块,用于查找除所述参数信息之外与所述查询语句相同的模板语句,作为与所述查询语句匹配的预设的模板语句。The first target statement search sub-module is configured to search for a template statement that is the same as the query statement except for the parameter information, as a preset template statement matching the query statement.
在本申请一种实施例中,所述第一目标语句查找模块包括:In an embodiment of the present application, the first target sentence search module includes:
格式确定子模块,用于确定所述查询语句是否符合预设格式;a format determination submodule for determining whether the query statement conforms to a preset format;
第二目标语句查找子模块,用于在所述查询语句符合预设格式的情况下,查找与所 述查询语句匹配的预设的模板语句;The second target statement search submodule is used to search for a preset template statement matching with the query statement when the query statement meets the preset format;
转发子模块,用于在所述查询语句不符合预设格式的情况下,将所述查询语句转发至所述数据库。The forwarding sub-module is configured to forward the query statement to the database if the query statement does not conform to the preset format.
参照图6,示出了本申请的一种数据查询装置实施例的结构框图,其应用于查询处理中间件,所述查询处理中间件同时与客户端以及数据库通信;所述装置部署在所述查询处理中间件中,所述装置具体可以包括如下模块:Referring to FIG. 6, it shows a structural block diagram of an embodiment of a data query apparatus of the present application, which is applied to query processing middleware, and the query processing middleware communicates with a client and a database at the same time; the apparatus is deployed in the In the query processing middleware, the device may specifically include the following modules:
第二查询语句获取模块601,用于获取所述客户端发送的查询语句;其中,所述查询语句包括参数信息;The second query statement obtaining module 601 is configured to obtain the query statement sent by the client; wherein the query statement includes parameter information;
第二目标语句查找模块602,用于查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;A second target statement search module 602, configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;
第二目标执行语句生成模块603,用于采用所述预处理信息以及所述参数信息,生成目标执行语句;The second target execution statement generation module 603 is configured to use the preprocessing information and the parameter information to generate a target execution statement;
第二查询模块604,用于向所述数据库发送所述目标执行语句,并获取所述数据库返回的目标数据;A second query module 604, configured to send the target execution statement to the database, and obtain target data returned by the database;
数据返回模块605,用于向所述客户端返回所述目标数据。The data returning module 605 is configured to return the target data to the client.
对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。As for the apparatus embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and reference may be made to the partial description of the method embodiment for related parts.
本申请实施例还提供了一种装置,包括:The embodiment of the present application also provides a device, including:
一个或多个处理器;和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 methods described in the embodiments of the present application.
本申请实施例还提供了一个或多个机器可读介质,其上存储有指令,当由一个或多个处理器执行时,使得所述处理器执行本申请实施例所述的方法。The embodiments of the present application further provide one or more machine-readable media on which instructions are stored, and when executed by one or more processors, cause the processors to execute the methods described in the embodiments of the present application.
本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same and similar parts between the various embodiments may be referred to each other.
本领域内的技术人员应明白,本申请实施例的实施例可提供为方法、装置、或计算机程序产品。因此,本申请实施例可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that the embodiments of the embodiments of the present application may be provided as methods, apparatuses, or computer program products. Accordingly, the embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present application may take 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.) having computer-usable program code embodied therein.
本申请实施例是参照根据本申请实施例的方法、终端设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据 处理终端设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理终端设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。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 will be understood that each flow and/or block in the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to the processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing terminal equipment to produce a machine that causes the instructions to be executed by the processor of the computer or other programmable data processing terminal equipment Means are created for implementing the functions specified in the flow or flows of the flowcharts and/or the blocks or blocks of the block diagrams.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理终端设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal equipment to operate in a particular manner, such that the instructions stored in the computer readable memory result in an article of manufacture comprising instruction means, the The instruction means implement the functions specified in the flow or flow of the flowcharts and/or the block or blocks of the block diagrams.
这些计算机程序指令也可装载到计算机或其他可编程数据处理终端设备上,使得在计算机或其他可编程终端设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程终端设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded on a computer or other programmable data processing terminal equipment, so that a series of operational steps are performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby executing on the computer or other programmable terminal equipment The instructions executed on the above provide steps for implementing the functions specified in the flowchart or blocks and/or the block or blocks of the block diagrams.
尽管已描述了本申请实施例的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例做出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请实施例范围的所有变更和修改。Although the preferred embodiments of the embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once the basic inventive concepts are known. Therefore, the appended claims are intended to be construed to include the preferred embodiments as well as all changes and modifications that fall within the scope of the embodiments of the present application.
最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者终端设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者终端设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者终端设备中还存在另外的相同要素。Finally, it should also be noted that in this document, relational terms such as first and second are used only to distinguish one entity or operation from another, and do not necessarily require or imply these entities or that there is any such actual relationship or sequence between operations. Moreover, the terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion, such that a process, method, article or terminal device comprising a list of elements includes not only those elements, but also a non-exclusive list of elements. other elements, or also include elements inherent to such a process, method, article or terminal equipment. Without further limitation, an element defined by the phrase "comprises a..." does not preclude the presence of additional identical elements in the process, method, article or terminal device comprising said element.
以上对本申请所提供的一种数据查询方法和一种数据查询装置,进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。A data query method and a data query device provided by the present application have been introduced in detail above. The principles and implementations of the present application are described with specific examples in this paper. The descriptions of the above embodiments are only used to help At the same time, for those of ordinary skill in the art, according to the idea of this application, there will be changes in the specific implementation and application scope. In summary, the content of this specification does not It should be understood as a limitation of this application.
Claims (16)
- 一种数据查询方法,其特征在于,包括:A data query method, comprising:获取查询语句;其中,所述查询语句包括参数信息;Obtain a query statement; wherein, the query statement includes parameter information;查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;Searching for a preset template statement matching the query statement, and acquiring 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, query target data from a preset database.
- 根据权利要求1所述的方法,其特征在于,所述方法还包括:The method according to claim 1, wherein the method further comprises:在所述查询语句不存在匹配的模板语句的情况下,根据所述查询语句,生成模板语句;In the case that the query statement does not have a matching template statement, generate a template statement according to the query statement;采用所述模板语句,生成预处理语句;Using the template statement to generate a prepared statement;向所述数据库发送所述预处理语句,获取所述数据库返回的预处理信息。Send the preprocessing statement to the database, and obtain the preprocessing information returned by the database.
- 根据权利要求2所述的方法,其特征在于,所述预处理信息包括预处理标识信息以及参数类型信息;The method according to claim 2, wherein the preprocessing information comprises preprocessing identification information and parameter type information;所述方法还包括:The method also includes:生成所述模板语句、所述预处理标识信息、以及参数类型信息之间的映射关系。A mapping relationship between the template statement, the preprocessing identification information, and the parameter type information is generated.
- 根据权利要求1所述的方法,其特征在于,所述采用所述预处理信息以及所述参数信息,生成目标执行语句的步骤,包括:The method according to claim 1, wherein the step of using the preprocessing information and the parameter information to generate the target execution statement comprises:采用所述预处理信息、所述参数信息、以及预设的编码标识信息,生成目标执行语句;所述编码标识信息用于指示所述数据返回基于文本协议编码的目标数据。Using the preprocessing information, the parameter information, and the preset encoding identification information, a target execution statement is generated; the encoding identification information is used to instruct the data to return target data encoded based on a text protocol.
- 根据权利要求1所述的方法,其特征在于,所述查找与所述查询语句匹配的预设的模板语句步骤,包括:The method according to claim 1, wherein the step of searching for a preset template statement matching the query statement comprises:查找除所述参数信息之外与所述查询语句相同的模板语句,作为与所述查询语句匹配的预设的模板语句。A template statement that is the same as the query statement except for the parameter information is searched as a preset template statement matching the query statement.
- 根据权利要求1所述的方法,其特征在于,所述查找与所述查询语句匹配的预设的模板语句的步骤,包括:The method according to claim 1, wherein the step of searching for a preset template statement matching the query statement comprises:确定所述查询语句是否符合预设格式;determining whether the query statement conforms to a preset format;在所述查询语句符合预设格式的情况下,查找与所述查询语句匹配的预设的模板语句;In the case that the query statement conforms to a preset format, search for a preset template statement matching the query statement;在所述查询语句不符合预设格式的情况下,将所述查询语句转发至所述数据库。If the query statement does not conform to the preset format, the query statement is forwarded to the database.
- 一种数据查询方法,其特征在于,其应用于查询处理中间件,所述查询处理中间件同时与客户端以及数据库通信;所述方法包括:A data query method, characterized in that it is applied to query processing middleware, and the query processing middleware communicates with a client and a database at the same time; 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;所述查询处理中间件采用所述预处理信息以及所述参数信息,生成目标执行语句;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 target data returned by the database;所述查询处理中间件向所述客户端返回所述目标数据。The query processing middleware returns the target data to the client.
- 一种数据查询装置,其特征在于,包括:A data query device, comprising:第一查询语句获取模块,用于获取查询语句;其中,所述查询语句包括参数信息;a first query statement obtaining module, used for obtaining a query statement; wherein the query statement includes parameter information;第一目标语句查找模块,用于查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;a first target statement search module, configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;第一目标执行语句生成模块,用于采用所述预处理信息以及所述参数信息,生成目标执行语句;a first target execution statement generation module, configured to use the preprocessing information and the parameter information to generate a target execution statement;第一查询模块,用于采用所述目标执行语句,向预设的数据库查询目标数据。The first query module is configured to use the target execution statement to query target data from a preset database.
- 根据权利要求8所述的装置,其特征在于,所述装置还包括:The device according to claim 8, wherein the device further comprises:模板生成模块,用于在所述查询语句不存在匹配的模板语句的情况下,根据所述查询语句,生成模板语句;a template generation module, configured to generate a template statement according to the query statement when the query statement does not have a matching template statement;预处理语句生成模块,用于采用所述模板语句,生成预处理语句;a prepared statement generation module for generating a prepared statement by using the template statement;预处理信息获取模块,用于向所述数据库发送所述预处理语句,获取所述数据库返回的预处理信息。The preprocessing information acquiring module is configured to send the preprocessing statement to the database, and acquire the preprocessing information returned by the database.
- 根据权利要求9所述的装置,其特征在于,所述预处理信息包括预处理标识信息以及参数类型信息;The apparatus according to claim 9, wherein the preprocessing information comprises preprocessing identification information and parameter type information;所述装置还包括:The device also includes:映射生成模块,用于生成所述模板语句、所述预处理标识信息、以及参数类型信息之间的映射关系。The mapping generation module is used for generating the mapping relationship among the template statement, the preprocessing identification information, and the parameter type information.
- 根据权利要求8所述的装置,其特征在于,所述第一目标执行语句生成模块包括:The device according to claim 8, wherein the first target execution statement generation module comprises:目标执行语句生成子模块,用于采用所述预处理信息、所述参数信息、以及预设的编码标识信息,生成目标执行语句;所述编码标识信息用于指示所述数据返回基于文本协议编码的目标数据。A target execution statement generation submodule is used to generate a target execution statement by using the preprocessing information, the parameter information, and the preset encoding identification information; the encoding identification information is used to instruct the data to be returned based on text protocol encoding target data.
- 根据权利要求8所述的装置,其特征在于,所述第一目标语句查找模块包括:The device according to claim 8, wherein the first target sentence search module comprises:第一目标语句查找子模块,用于查找除所述参数信息之外与所述查询语句相同的模板语句,作为与所述查询语句匹配的预设的模板语句。The first target statement search sub-module is configured to search for a template statement that is the same as the query statement except for the parameter information, as a preset template statement matching the query statement.
- 根据权利要求8所述的装置,其特征在于,所述第一目标语句查找模块包括:The device according to claim 8, wherein the first target sentence search module comprises:格式确定子模块,用于确定所述查询语句是否符合预设格式;a format determination submodule for determining whether the query statement conforms to a preset format;第二目标语句查找子模块,用于在所述查询语句符合预设格式的情况下,查找与所述查询语句匹配的预设的模板语句;a second target statement search submodule, configured to search for a preset template statement matching the query statement when the query statement conforms to a preset format;转发子模块,用于在所述查询语句不符合预设格式的情况下,将所述查询语句转发 至所述数据库。A forwarding sub-module is configured to forward the query statement to the database when the query statement does not conform to a preset format.
- 一种数据查询装置,其特征在于,其应用于查询处理中间件,所述查询处理中间件同时与客户端以及数据库通信;所述装置部署在所述查询处理中间件中,所述装置包括:A data query device, characterized in that it is applied to 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 comprises:第二查询语句获取模块,用于获取所述客户端发送的查询语句;其中,所述查询语句包括参数信息;The second query statement obtaining module is used to obtain the query statement sent by the client; wherein, the query statement includes parameter information;第二目标语句查找模块,用于查找与所述查询语句匹配的预设的模板语句,并获取所述模板语句对应的预处理信息;A second target statement search module, configured to search for a preset template statement matching the query statement, and obtain preprocessing information corresponding to the template statement;第二目标执行语句生成模块,用于采用所述预处理信息以及所述参数信息,生成目标执行语句;a second target execution statement generation module, configured to generate a target execution statement by using the preprocessing information and the parameter information;第二查询模块,用于向所述数据库发送所述目标执行语句,并获取所述数据库返回的目标数据;A second query module, configured to send the target execution statement to the database, and obtain target data returned by the database;数据返回模块,用于向所述客户端返回所述目标数据。A data return module, configured to return the target data to the client.
- 一种数据查询装置,其特征在于,包括:A data query device, comprising:一个或多个处理器;和one or more processors; and其上存储有指令的一个或多个机器可读介质,当由所述一个或多个处理器执行时,使得所述装置执行如权利要求1-6或7所述的一个或多个的方法。One or more machine-readable media having instructions stored thereon that, when executed by the one or more processors, cause the apparatus to perform the method of one or more of claims 1-6 or 7 .
- 一个或多个机器可读介质,其上存储有指令,当由一个或多个处理器执行时,使得所述处理器执行如权利要求1-6或7所述的一个或多个的方法。One or more machine-readable media having stored thereon instructions that, when executed by one or more processors, cause the processors to perform the method of one or more of claims 1-6 or 7.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010901686.7A CN112163000A (en) | 2020-08-31 | 2020-08-31 | Data query method and device |
CN202010901686.7 | 2020-08-31 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2022042288A1 true WO2022042288A1 (en) | 2022-03-03 |
Family
ID=73858751
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2021/111696 WO2022042288A1 (en) | 2020-08-31 | 2021-08-10 | Data query method and apparatus |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN112163000A (en) |
WO (1) | WO2022042288A1 (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114661751A (en) * | 2022-03-22 | 2022-06-24 | 医渡云(北京)技术有限公司 | Data production method, device, system, equipment and medium based on SQL (structured query language) knowledge base |
CN114866613A (en) * | 2022-04-28 | 2022-08-05 | 上海极豆科技有限公司 | Internet of vehicles request processing method and device, electronic equipment and storage medium |
CN116975126A (en) * | 2023-09-25 | 2023-10-31 | 恒生电子股份有限公司 | Data query method, device, computing equipment and computer readable storage medium |
CN117556452A (en) * | 2024-01-10 | 2024-02-13 | 支付宝(杭州)信息技术有限公司 | Access control method for database and related equipment |
Families Citing this family (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112163000A (en) * | 2020-08-31 | 2021-01-01 | 阿里巴巴集团控股有限公司 | Data query method and device |
CN112559914B (en) * | 2020-12-21 | 2024-05-14 | 北京搜房科技发展有限公司 | Index data display method and device |
CN113190422B (en) * | 2021-03-22 | 2022-05-13 | 云和恩墨(北京)信息技术有限公司 | Quality analysis method, device, terminal and medium for SQL (structured query language) statements |
CN113094574A (en) * | 2021-04-09 | 2021-07-09 | 北京奇艺世纪科技有限公司 | Information query method and device, electronic equipment and readable storage medium |
CN113448980A (en) * | 2021-06-18 | 2021-09-28 | 青岛海尔科技有限公司 | Method and device for generating SQL (structured query language) statement and electronic equipment |
CN113742385A (en) * | 2021-09-15 | 2021-12-03 | 第四范式(北京)技术有限公司 | Data query method and device |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102193922A (en) * | 2010-03-04 | 2011-09-21 | 杭州华三通信技术有限公司 | Method and device for accessing database |
CN107229628A (en) * | 2016-03-23 | 2017-10-03 | 中兴通讯股份有限公司 | The method and device of distributed data base pretreatment |
US20180329965A1 (en) * | 2017-05-15 | 2018-11-15 | Fujitsu Limited | Display method and display apparatus |
CN110609842A (en) * | 2019-09-19 | 2019-12-24 | 中国银行股份有限公司 | Message composition method and system |
CN111177180A (en) * | 2019-12-11 | 2020-05-19 | 北京百分点信息科技有限公司 | Data query method and device and electronic equipment |
CN112163000A (en) * | 2020-08-31 | 2021-01-01 | 阿里巴巴集团控股有限公司 | Data query method and device |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110019350B (en) * | 2017-07-28 | 2021-06-29 | 北京京东尚科信息技术有限公司 | Data query method and device based on configuration information |
CN110968591A (en) * | 2018-09-30 | 2020-04-07 | 北京国双科技有限公司 | Query statement generation method and device, storage medium and processor |
CN111414407A (en) * | 2020-02-13 | 2020-07-14 | 中国平安人寿保险股份有限公司 | Data query method and device of database, computer equipment and storage medium |
-
2020
- 2020-08-31 CN CN202010901686.7A patent/CN112163000A/en active Pending
-
2021
- 2021-08-10 WO PCT/CN2021/111696 patent/WO2022042288A1/en active Application Filing
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102193922A (en) * | 2010-03-04 | 2011-09-21 | 杭州华三通信技术有限公司 | Method and device for accessing database |
CN107229628A (en) * | 2016-03-23 | 2017-10-03 | 中兴通讯股份有限公司 | The method and device of distributed data base pretreatment |
US20180329965A1 (en) * | 2017-05-15 | 2018-11-15 | Fujitsu Limited | Display method and display apparatus |
CN110609842A (en) * | 2019-09-19 | 2019-12-24 | 中国银行股份有限公司 | Message composition method and system |
CN111177180A (en) * | 2019-12-11 | 2020-05-19 | 北京百分点信息科技有限公司 | Data query method and device and electronic equipment |
CN112163000A (en) * | 2020-08-31 | 2021-01-01 | 阿里巴巴集团控股有限公司 | Data query method and device |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114661751A (en) * | 2022-03-22 | 2022-06-24 | 医渡云(北京)技术有限公司 | Data production method, device, system, equipment and medium based on SQL (structured query language) knowledge base |
CN114866613A (en) * | 2022-04-28 | 2022-08-05 | 上海极豆科技有限公司 | Internet of vehicles request processing method and device, electronic equipment and storage medium |
CN114866613B (en) * | 2022-04-28 | 2024-02-23 | 上海极豆科技有限公司 | Internet of vehicles request processing method and device, electronic equipment and storage medium |
CN116975126A (en) * | 2023-09-25 | 2023-10-31 | 恒生电子股份有限公司 | Data query method, device, computing equipment and computer readable storage medium |
CN116975126B (en) * | 2023-09-25 | 2023-12-19 | 恒生电子股份有限公司 | Data query method, device, computing equipment and computer readable storage medium |
CN117556452A (en) * | 2024-01-10 | 2024-02-13 | 支付宝(杭州)信息技术有限公司 | Access control method for database and related equipment |
Also Published As
Publication number | Publication date |
---|---|
CN112163000A (en) | 2021-01-01 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2022042288A1 (en) | Data query method and apparatus | |
US8078647B2 (en) | Ontology data import/export method and apparatus | |
CN106682147A (en) | Mass data based query method and device | |
CN107704453B (en) | Character semantic analysis method, character semantic analysis terminal and storage medium | |
US9355171B2 (en) | Clustering of near-duplicate documents | |
US20070168380A1 (en) | System and method for storing text annotations with associated type information in a structured data store | |
US10275229B2 (en) | Encoded data object notation persistence format | |
CN1255224A (en) | Text normalization using context-free grammar | |
US10713302B2 (en) | Search processing method and device | |
CN114756569B (en) | Multi-layer parsing method for structured query statement, computer equipment and storage medium | |
CN108763536B (en) | Database access method and device | |
US11669553B2 (en) | Context-dependent shared dictionaries | |
US20240202589A1 (en) | Transformation For Machine Learning Pre-Processing | |
CN114356971A (en) | Data processing method, device and system | |
US20040049495A1 (en) | System and method for automatically generating general queries | |
CN117743301A (en) | Database route optimization method and device, electronic equipment and storage medium | |
CN110069489B (en) | Information processing method, device and equipment and computer readable storage medium | |
WO2019000697A1 (en) | Information search method, system, server, and readable storage medium | |
KR20200094673A (en) | Method and device for compressing rdf triple data using ra trees | |
US20230056131A1 (en) | Server and method for classifying entities of a query | |
US20120131046A1 (en) | Fast matching for content-based addressing | |
EP3695308A1 (en) | Method and system for content agnostic file indexing | |
WO2021143010A1 (en) | Response method and device for distributed computing task | |
CN113064914A (en) | Data extraction method and device | |
US11977852B2 (en) | Anaphoric reference resolution using natural language processing and machine learning |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 21860127 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 21860127 Country of ref document: EP Kind code of ref document: A1 |