Query instruction execution method, device, electronic device and computer readable medium
By combining and parameterizing the table names and library names in the query instructions, a shared execution plan is generated, which solves the problem of performance lag in the MySQL database shard scenario and improves the database query performance.
Patent Information
- Application Number
- CN201910798315.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-08-27
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2039-08-27
AI Technical Summary
In the sharding scenario, due to the limitation of the Prepared Statement protocol on constants, the execution plan of query instructions that need to include all physical subtables in the cache. As the number of physical subtables and query complexity increases, performance lags. question.
Through the business parameters in the received query instructions, the table name and library name are determined and merged, a parameterized execution plan is generated, and the second query instruction sent to the distributed database node is generated, so that all physical sub-tables of the logical table are shared with one implementation plan.
It effectively solves the performance lag caused by the execution plan of all physical subtables of cache logical tables, and improves database query performance.
Smart Images

Figure CN112445817B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present application relate to the field of databases, and in particular, to a method, device, electronic device, and computer-readable medium for executing a query instruction. Background Art
[0002] MySQL database is an open source relational database and is currently one of the most popular databases. In the sharding scenario of MySQL database, in order to solve the storage capacity limitation and improve the query performance of a single table, a large number of physical sub-tables with the same structure are created for the logical table. Since the default query template of the Prepared Statement protocol of MySQL database only allows the use of placeholders for constants, the cached execution plan needs to include the execution plan of the query instructions for all physical sub-tables. As the number of physical sub-tables and the complexity of query instructions increase, a large amount of cache will be occupied, causing performance problems. Therefore, how to effectively solve the performance problems caused by caching the execution plans of all physical sub-tables of the logical table has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] The purpose of this application is to propose a query instruction execution method, device, electronic device and computer-readable medium to solve the problem of how to effectively solve the performance lag caused by the execution plan of all physical sub-tables of the cache logical table in the prior art.
[0004] According to the first aspect of the embodiment of the present application, a method for executing a query instruction is provided. The method includes: determining the library name and / or table name to be filled in the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, wherein the execution plan is an execution plan with parameterized library name and / or table name; merging the business parameters, the table name and / or the library name to obtain the merged result of the business parameters, the table name and / or the library name to be filled in the execution plan of the query template corresponding to the first query instruction; based on the merged result, filling the business parameters, the table name and / or the library name into the execution plan respectively to generate a second query instruction sent to the node of the distributed database for execution.
[0005] According to the second aspect of the embodiment of the present application, a query instruction execution device is provided. The device includes: a first determination module, which is used to determine the table name and / or library name to be filled in the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, wherein the execution plan is an execution plan with parameterized table name and / or library name; a merging module, which is used to merge the business parameters, the table name and / or the library name to obtain the merged result of the business parameters, the table name and / or the library name to be filled in the execution plan of the query template corresponding to the first query instruction; a filling module, which is used to fill the business parameters, the table name and / or the library name into the execution plan respectively based on the merged result to generate a second query instruction sent to the node of the distributed database for execution.
[0006] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors; and a computer-readable medium configured to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the execution method of the query instruction as described in the first aspect of the above embodiment.
[0007] According to a fourth aspect of an embodiment of the present application, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method for executing a query instruction as described in the first aspect of the above embodiment is implemented.
[0008] According to the technical solution provided by the embodiment of the present application, according to the business parameters in the received first query instruction, the table name and / or library name to be filled in the execution plan of the query template corresponding to the first query instruction is determined, wherein the execution plan is an execution plan after the table name and / or the library name are parameterized; and the business parameters, the table name and / or the library name are merged to obtain the merged result of the business parameters, the table name and / or the library name in the execution plan of the query template corresponding to the first query instruction to be filled; then based on the merged result, the business parameters, the table name and / or the library name are respectively filled into the execution plan to generate a second query instruction sent to the node of the distributed database for execution. Compared with the existing Prepared Statement mechanism solution, through the execution plan of the query template parameterized by the table name and / or library name, all physical sub-tables of the logical table share an execution plan, thereby effectively solving the performance jamming problem caused by the execution plan of all physical sub-tables of the cached logical table. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0010] Figure 1A This is a flowchart of the steps of the method for executing the query instruction in the first embodiment of the present application;
[0011] Figure 1B A schematic diagram of a parameterization process of an execution plan table name provided according to Embodiment 1 of the present application;
[0012] Figure 2 This is a flowchart of the steps of the method for executing the query instruction in the second embodiment of the present application;
[0013] Figure 3A This is a schematic diagram of the structure of the distributed database system in Embodiment 3 of the present application;
[0014] Figure 3B A schematic diagram of the execution process of the query instruction provided according to the third embodiment of the present application;
[0015] Figure 4 This is a schematic diagram of the structure of the execution device of the query instruction in the fourth embodiment of the present application;
[0016] Figure 5 This is a schematic diagram of the structure of the execution device of the query instruction in the fifth embodiment of the present application;
[0017] Figure 6 This is a schematic diagram of the structure of an electronic device in Embodiment 6 of the present application;
[0018] Figure 7 This is the hardware structure of the electronic device in Example 7 of the present application. DETAILED DESCRIPTION
[0019] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only configured to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.
[0020] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0021] Reference Figure 1A , showing a step flow chart of the method for executing the query instruction of the first embodiment of the present application.
[0022] Specifically, the query instruction execution method of this embodiment includes the following steps:
[0023] In step S101, according to the business parameters in the received first query instruction, the table name and / or library name to be filled in the execution plan of the query template corresponding to the first query instruction is determined.
[0024] In an embodiment of the present application, the first query instruction may be an SQL instruction. The SQL instruction may be an SQL instruction for instructing to access data in a distributed database, an SQL instruction for instructing to query a distributed relational database, an SQL instruction for instructing to update a distributed relational database, or an SQL instruction for instructing to manage a distributed relational database, etc. The SQL (Structured Query Language) is a special-purpose programming language, a programming language for database query, used for accessing data and querying, updating and managing a relational database system. The business parameter may be understood as a business constant carried in the first query instruction, for example, a specific employee ID in an employee ID field, an employee salary in an employee salary field. The execution plan may be understood as an execution plan in which the table name and / or the library name are parameterized. In the existing Prepared Statement mechanism, the execution plan of the query template corresponding to the first query instruction is an execution plan in which the business parameters are parameterized, while in this embodiment, the execution plan of the query template corresponding to the first query instruction is an execution plan in which the table name and / or the library name are parameterized again on the basis of the parameterized business parameters. Among them, the table name can be understood as the table name of the physical sub-table of the logical table, and the library name can be understood as the library name of the database where the logical table is located. The logical table may include sub-tables, single tables, or broadcast tables, etc. The sub-table can be understood as a data table split by a splitting rule. The single table can be understood as a data table that is not split by a splitting rule and is stored in the storage disk of the main node of the distributed database. The broadcast table can be understood as a data table that is not split by a splitting rule and is distributed and stored on the storage disks of the distributed database nodes. The query template is used to efficiently execute the same or similar query instructions. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitations on this.
[0025] In some optional embodiments, when determining the table name and / or library name to be filled into the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, the table name and / or the library name are determined based on the business parameters, the conditions for splitting the logical table into physical sub-tables, and the pre-configured sub-library and table rules. Thereby, the table name and / or the library name of the physical sub-table of the logical table can be accurately determined through the business parameters, the conditions for splitting the logical table into physical sub-tables, and the pre-configured sub-library and table rules. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0026] In a specific example, when a logical table named t1 is established, a physical sub-table table name template t1_{00} is saved in the DRDS (distributed relational database server) metadata, where {00} is a placeholder. When the splitting condition of the logical table into the physical sub-table is the identification field, and the pre-configured sub-library and table rules are: (#id#.longValue().abs()%24).intdiv(3), that is, there are 8 sub-libraries and 3 sub-tables in each sub-library, the business parameter 1 in the first query instruction received is substituted into the pre-configured sub-library and table rules (modulo 24 and then divided by 3 and rounded to an integer), and 1 is obtained, and the placeholder in the table name template of the physical sub-table is replaced after 0 is added on the left to obtain the table name t1_01 of the physical sub-table. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0027] In some optional embodiments, before determining the table name and / or library name to be filled into the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, the method further includes: receiving the query template containing constant placeholders predefined by the client through a prepared statement; parsing and optimizing the query template to obtain an execution plan based on a logical table for the query template; parameterizing the table name and / or the library name in the execution plan based on the logical table to obtain an execution plan with the table name and / or the library name parameterized. Thus, through the execution plan with the table name and / or the library name parameterized, all physical sub-tables of the logical table share an execution plan, thereby effectively solving the performance jamming problem caused by the execution plan of all physical sub-tables of the cached logical table. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0028] In a specific example, the prepared statement can be understood as a statement for pre-defining a query template containing a constant placeholder to support efficient execution of the same or similar query instructions. When parsing and optimizing the query template, the query template is parsed to obtain multiple equivalent execution plans based on the logical table corresponding to the query template; the execution cost of each equivalent execution plan based on the logical table is calculated; based on the execution cost of each equivalent execution plan based on the logical table, the equivalent execution plan based on the logical table corresponding to the query template is finally determined. Among them, the execution plan based on the logical table of the query template is an execution plan with parameterized business parameters, rather than an execution plan with parameterized business parameters, table names and / or library names. The execution plan with parameterized table names and / or library names is an execution plan with parameterized table names and / or library names again on the basis of parameterized business parameters. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0029] In a specific example, when the table name and / or the library name in the execution plan based on the logical table are parameterized to obtain the execution plan with the table name and / or the library name parameterized, the first grammatical unit in the execution plan based on the logical table is traversed, and if it is determined that the first grammatical unit contains the table name and / or the library name, the table name and / or the library name is replaced with a special placeholder; if it is determined that the first grammatical unit does not contain the table name and / or the library name, and the first grammatical unit contains a subquery, it is determined whether the second grammatical unit in the subquery contains the table name and / or the library name; if it is determined that the second grammatical unit in the subquery contains the table name and / or the library name, the table name and / or the library name is replaced with the special placeholder. In this way, an execution plan with the table name and / or the library name parameterized can be obtained. It can be understood that the above description is only exemplary, and the embodiments of the present application do not limit this in any way.
[0030] In a specific example, the first grammatical unit and the second grammatical unit can be understood as grammatical units that are naturally divided in the execution plan based on the logical table. For example, the WHERE part of the SELECT / DELETE statement, the SET part of the UPDATE statement, etc. can all be understood as grammatical units. The special placeholder can be a placeholder with a subscript of -1. By using a placeholder with a subscript of -1, it is convenient to sort business parameters, table names and / or library names when actually executing the query instructions entered by the user. The subquery is a program module that nests queries at the lower level in a commonly used computer language SELECT-query language. When a query A is a condition of another query B, it is called a subquery, such as query A is a subquery. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitations on this.
[0031] In some optional embodiments, before replacing the table name and / or the library name with a special placeholder, the method further includes: if it is determined that the table name and / or the library name has an alias, then executing the step of replacing the table name and / or the library name with a special placeholder; if it is determined that the table name and / or the library name does not have an alias, then generating an alias with the same name as the table name and / or the library name, and executing the step of replacing the table name and / or the library name with a special placeholder. Thereby, before replacing the table name and / or the library name with a special placeholder, retaining the alias of the table name and / or the library name can ensure the semantic correctness of the parameterized execution plan of the table name and / or the library name. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0032] In a specific example, a user sends a query template to a DRDS proxy server through a client. After receiving the query template, the DRDS proxy server parses and optimizes the query template to obtain an execution plan based on a logical table, which contains one or more references to the logical table. Then, the DRDS proxy server parameterizes the table name and / or library name for the execution plan based on the logical table. Specifically, Figure 1BAs shown, the grammatical unit in the execution plan based on the logical table is traversed to determine whether the grammatical unit contains a table name and / or a library name. If the grammatical unit contains a table name and / or a library name, it is determined whether the table name and / or the library name contained in the grammatical unit has a corresponding alias. If there is a corresponding alias, the table name and / or the library name is replaced with a special placeholder. If there is no corresponding alias, an alias with the same name as the table name and / or the library name is generated, and the table name and / or the library name is replaced with a special placeholder. If the grammatical unit does not contain a table name and / or a library name, it is determined whether the grammatical unit contains a subquery. If the grammatical unit contains a subquery, the grammatical unit in the subquery is traversed to determine whether the grammatical unit in the subquery contains a table name and / or a library name. If the grammatical unit in the subquery contains a table name and / or a library name, it is determined whether the table name and / or the library name contained in the grammatical unit in the subquery has a corresponding alias. If there is a corresponding alias, the table name and / or the library name is replaced with a special placeholder. If there is no corresponding alias, an alias with the same name as the table name and / or library name is generated, and the table name and / or library name is replaced with a special placeholder. The DRDS proxy server caches the execution plan parameterized by the table name and / or library name, and returns the ID of the generated query template to the client. At this time, all physical sub-tables of the logical table share an execution plan. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0033] In step S102, the business parameters, the table name and / or the library name are merged to obtain a merged result of the business parameters, the table name and / or the library name to be filled into the execution plan of the query template corresponding to the first query instruction.
[0034] In some optional embodiments, when the business parameters, the table name and / or the library name are merged, the business parameters are sorted in the order in which the business parameters appear in the first query instruction to obtain a sorted list of the business parameters; the table name and / or the library name are inserted into the sorted list of the business parameters in the order in which the special placeholders in the syntax unit in the execution plan appear to obtain a sorted list of the business parameters, the table name and / or the library name. In this way, the sorting results of the business parameters, table names and / or library names can be accurately obtained. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0035] In a specific example, the information of the order in which the business parameters appear in the first query instruction can be sent by the client to the DRDS proxy server. The information of the order in which the special placeholders in the syntax unit in the execution plan can be obtained by the DRDS proxy server according to the execution plan of the query template corresponding to the first query instruction in the plan cache. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0036] In step S103, based on the merging result, the business parameters, the table name and / or the library name are respectively filled into the execution plan to generate a second query instruction sent to a node of the distributed database for execution.
[0037] In some optional embodiments, when the business parameters, the table name and / or the library name are filled into the execution plan based on the merge result to generate the second query instruction sent to the node of the distributed database for execution, the syntax unit in the parameterized execution plan of the table name and / or the library name is traversed, and if the syntax unit contains a common placeholder, the common placeholder is replaced with the corresponding business parameter based on the merge result to generate the second query instruction sent to the node of the distributed database for execution; if the syntax unit contains a special placeholder, the special placeholder is replaced with the corresponding table name and / or library name based on the merge result to generate the second query instruction sent to the node of the distributed database for execution. Thus, through the merge result of the business parameters, the table name and / or the library name, the business parameters, the table name and / or the library name can be accurately filled into the execution plan to generate the second query instruction sent to the node of the distributed database for execution. It can be understood that the above description is only exemplary, and the embodiments of the present application do not limit this in any way.
[0038] In a specific example, the cached execution plan is traversed in the order in which the grammatical units appear, and a judgment is made when a placeholder is encountered. If it is a common placeholder, the business parameters are added to the result queue. If it is a special placeholder, the table name and / or library name of the physical sub-table is added to the result queue. Finally, based on the execution plan of the query template corresponding to the first query instruction and the business parameters, table name and / or library name in the result queue, a second query instruction is generated and sent to the node of the distributed database for execution. It will be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0039] Through the query instruction execution method provided by the embodiment of the present application, according to the business parameters in the received first query instruction, the table name and / or library name to be filled in the execution plan of the query template corresponding to the first query instruction is determined, wherein the execution plan is an execution plan after the table name and / or the library name are parameterized; and the business parameters, the table name and / or the library name are merged to obtain the merged result of the business parameters, the table name and / or the library name in the execution plan of the query template corresponding to the first query instruction to be filled; then based on the merged result, the business parameters, the table name and / or the library name are respectively filled into the execution plan to generate a second query instruction sent to the node of the distributed database for execution. Compared with the existing Prepared Statement mechanism solution, through the query template's execution plan parameterized by the table name and / or library name, all physical sub-tables of the logical table share an execution plan, thereby effectively solving the performance jamming problem caused by the execution plan of all physical sub-tables of the cached logical table.
[0040] The execution method of the query instruction of this embodiment can be executed by any appropriate device with data processing capabilities, including but not limited to: cameras, terminals, mobile terminals, PCs, servers, vehicle-mounted devices, entertainment equipment, advertising equipment, personal digital assistants (PDAs), tablet computers, laptop computers, handheld game consoles, smart glasses, smart watches, wearable devices, virtual display devices or display enhancement devices (such as Google Glass, Oculus Rift, Hololens, Gear VR), etc.
[0041] Reference Figure 2 , showing a step flow chart of the method for executing the query instruction of the second embodiment of the present application.
[0042] Specifically, the query instruction execution method of this embodiment includes the following steps:
[0043] In step S201, based on the business parameters in the received first query instruction, a table name and / or a library name to be filled in the execution plan of the query template corresponding to the first query instruction is determined.
[0044] Since step S201 is similar to the above step S101, it will not be described again here.
[0045] In step S202, the business parameters, the table name and / or the library name are merged to obtain a merged result of the business parameters, the table name and / or the library name to be filled into the execution plan of the query template corresponding to the first query instruction.
[0046] Since step S202 is similar to the above step S102, it will not be described again here.
[0047] In step S203, based on the merging result, the business parameters, the table name and / or the library name are respectively filled into the execution plan to generate a second query instruction sent to a node of the distributed database for execution.
[0048] Since step S203 is similar to the above step S103, it will not be described again here.
[0049] In step S204, the execution result of the node of the distributed database for the second query instruction is received, and based on the execution result of the node for the second query instruction, the execution result of the first query instruction is returned to the client.
[0050] In an embodiment of the present application, the DRDS proxy server performs a merge process or a cluster process on the received execution results of the nodes of the distributed database for the second query instruction to obtain the execution result for the first query instruction. After obtaining the execution result for the first query instruction, the DRDS proxy server returns the execution result for the first query instruction to the client. It can be understood that the above description is only exemplary and the embodiment of the present application does not impose any limitation on this.
[0051] Through the query instruction execution method provided by the embodiment of the present application, according to the business parameters in the received first query instruction, the table name and / or parameters to be filled in the execution plan of the query template corresponding to the first query instruction are determined, wherein the execution plan is an execution plan with parameterized table name and / or library name; and the business parameters, the table name and / or the library name are merged to obtain the merged result of the business parameters, the table name and / or the library name in the execution plan of the query template corresponding to the first query instruction to be filled; then based on the merged result, the business parameters, the table name and / or the library name are respectively filled into the execution plan to generate a second query instruction sent to the node of the distributed database for execution, and then the execution result of the node of the distributed database for the second query instruction is received, and then based on the execution result of the node for the second query instruction, the execution result of the first query instruction is returned to the client, which is consistent with the existing Prepared Compared with the solution of the Statement mechanism, the execution plan parameterized by the table name and / or library name of the query template enables all physical sub-tables of the logical table to share an execution plan, thereby effectively solving the performance lag problem caused by caching the execution plans of all physical sub-tables of the logical table.
[0052] The execution method of the query instruction of this embodiment can be executed by any appropriate device with data processing capabilities, including but not limited to: cameras, terminals, mobile terminals, PCs, servers, vehicle-mounted devices, entertainment equipment, advertising equipment, personal digital assistants (PDAs), tablet computers, laptop computers, handheld game consoles, smart glasses, smart watches, wearable devices, virtual display devices or display enhancement devices (such as Google Glass, Oculus Rift, Hololens, Gear VR), etc.
[0053] Reference Figure 3A , showing a schematic diagram of the structure of the distributed database system in Example 3 of the present application.
[0054] The distributed database system provided in this embodiment includes: a client, a server connected to the client, and a distributed database node connected to the server; the client is used to send the business parameters in a first query instruction to the server; the server is used to determine the table name and / or library name to be filled in the execution plan of the query template corresponding to the first query instruction based on the received business parameters, wherein the execution plan is an execution plan with parameterized table name and / or library name; and merge the business parameters, the table name and / or the library name to obtain a merged result of the business parameters, the table name and / or the library name to be filled in the execution plan of the query template corresponding to the first query instruction; and then based on the merged result, fill the business parameters, the table name and / or the library name into the execution plan respectively to generate a second query instruction sent to the node of the distributed database for execution.
[0055] In a specific example, the number of the distributed database nodes is multiple, and the server is connected to the multiple distributed database nodes. In addition, each distributed database node has a corresponding storage disk. The storage disk can store logical tables of the database, such as sub-tables, single tables, or broadcast tables, etc. Among them, the sub-tables can be understood as data tables split by splitting rules. The single table can be understood as a data table that is not split by the splitting rules and is stored in the storage disk of the distributed database master node. The broadcast table can be understood as a data table that is not split by the splitting rules and is distributed and stored on the storage disks of the distributed database nodes. The server can be a DRDS proxy server. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitations on this.
[0056] In a specific example, Figure 3BAs shown, the distributed database system includes a client, a DRDS proxy server connected to the client, and various distributed database nodes connected to the DRDS proxy server, such as nodes MySQLA, MySQL B, etc. The DRDS proxy server is a server added between the client and the distributed database node, which mainly provides the client with the ability of MySQL shard routing. The SQL command entered by the user will be routed to one of the distributed database nodes according to the sharding algorithm of the DRDS proxy server. Through the DRDS proxy server, the user can easily manage and operate multiple distributed database nodes. The execution process of the SQL command is as follows: the client sends an SQL template to the DRDS proxy server, and the DRDS proxy server parses and optimizes the received SQL template to generate an execution plan based on the logical table, and parameterizes the table name and / or library name in the generated execution plan based on the logical table to obtain an execution plan with parameterized table name and / or library name. Then, the execution plan with parameterized table name and / or library name is cached, and the generated SQL template ID is returned to the client. When actually executing the SQL instruction input by the user, the client sends the business parameters carried in the SQL instruction input by the user to the DRDS proxy server. The DRDS proxy server determines the table name and / or library name to be filled in the execution plan of the SQL template corresponding to the user input SQL instruction according to the business parameters in the received user input SQL instruction, and merges the business parameters, the table name and / or the library name to obtain the merged result of the business parameters, the table name and / or the library name; then based on the merged result, the business parameters, the table name and / or the library name are respectively filled into the execution plan to generate the SQL instruction sent to the node of the distributed database for execution. The node of the distributed database executes the SQL instruction sent by the DRDS proxy server and returns the execution result of the SQL instruction to the DRDS proxy server. The DRDS proxy server merges or aggregates the execution results of the SQL instructions returned by the distributed database nodes to obtain the execution result for the user input SQL instruction. After obtaining the execution result for the user input SQL instruction, the DRDS proxy server returns the execution result for the user input SQL instruction to the client. It should be understood that the above description is merely exemplary and the embodiments of the present application do not impose any limitation thereto.
[0057] The distributed database system of this embodiment is used to implement the execution methods of the corresponding query instructions in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0058] Reference Figure 4 , showing a schematic diagram of the structure of the execution device of the query instruction in the fourth embodiment of the present application.
[0059] The execution device of the query instruction of this embodiment includes: a first determination module 301, which is used to determine the table name and / or library name to be filled in the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, wherein the execution plan is an execution plan with parameterized table name and / or library name; a merging module 302, which is used to merge the business parameters, the table name and / or the library name to obtain a merged result of the business parameters, the table name and / or the library name to be filled in the execution plan of the query template corresponding to the first query instruction; a filling module 303, which is used to fill the business parameters, the table name and / or the library name into the execution plan respectively based on the merged result to generate a second query instruction sent to the node of the distributed database for execution.
[0060] The query instruction execution device of this embodiment is used to implement the corresponding query instruction execution methods in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0061] Reference Figure 5 , showing a schematic diagram of the structure of the execution device of the query instruction in the fifth embodiment of the present application.
[0062] The execution device of the query instruction of this embodiment includes: a first determination module 404, which is used to determine the table name and / or library name to be filled in the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, wherein the execution plan is an execution plan with parameterized table name and / or library name; a merging module 405, which is used to merge the business parameters, the table name and / or the library name to obtain a merged result of the business parameters, the table name and / or the library name to be filled in the execution plan of the query template corresponding to the first query instruction; a filling module 406, which is used to fill the business parameters, the table name and / or the library name into the execution plan respectively based on the merged result to generate a second query instruction sent to the node of the distributed database for execution.
[0063] Optionally, before the first determination module 404, the device also includes: a receiving module 401, used to receive the query template containing constant placeholders pre-defined by the client through a prepared statement; a parsing and optimization module 402, used to parse and optimize the query template to obtain an execution plan of the query template based on a logical table; a parameterization module 403, used to parameterize the table name and / or the library name in the execution plan based on the logical table to obtain an execution plan with the table name and / or the library name parameterized.
[0064] Optionally, the parameterization module 403 includes: a first replacement module 4033, used to traverse the first grammatical unit in the execution plan based on the logical table, and if it is determined that the first grammatical unit contains the table name and / or the library name, replace the table name and / or the library name with a special placeholder; a second determination module 4034, used to determine whether the second grammatical unit in the subquery contains the table name and / or the library name if it is determined that the first grammatical unit does not contain the table name and / or the library name, and the first grammatical unit contains a subquery; a second replacement module 4035, used to replace the table name and / or the library name with the special placeholder if it is determined that the second grammatical unit in the subquery contains the table name and / or the library name.
[0065] Optionally, before the first replacement module 4033, the parameterization module 403 also includes: a first execution module 4031, which is used to execute the step of replacing the table name and / or the library name with a special placeholder if it is determined that the table name and / or the library name has an alias; and a second execution module 4032, which is used to generate an alias with the same name as the table name and / or the library name, and execute the step of replacing the table name and / or the library name with a special placeholder if it is determined that the table name and / or the library name does not have an alias.
[0066] Optionally, the first determination module 404 is specifically used to determine the table name and / or the library name based on the business parameters, the conditions for splitting the logical table into physical sub-tables, and pre-configured library and table sub-table rules.
[0067] Optionally, the merging module 405 is specifically used to: sort the business parameters in the order in which the business parameters appear in the first query instruction to obtain a sorted list of the business parameters; insert the table name and / or the library name into the sorted list of the business parameters in the order in which the special placeholders in the syntax units in the execution plan appear to obtain a sorted list of the business parameters, the table name and / or the library name.
[0068] Optionally, the filling module 406 is specifically used to: traverse the syntax units in the parameterized execution plan of the table name and / or the library name, and if the syntax unit contains ordinary placeholders, then based on the merge result, replace the ordinary placeholders with corresponding business parameters to generate a second query instruction sent to the node of the distributed database for execution; if the syntax unit contains special placeholders, then based on the merge result, replace the special placeholders with corresponding table names and / or library names to generate a second query instruction sent to the node of the distributed database for execution.
[0069] The query instruction execution device of this embodiment is used to implement the corresponding query instruction execution methods in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0070] Figure 6 This is a schematic diagram of the structure of an electronic device in Embodiment 6 of the present application; the electronic device may include:
[0071] One or more processors 601;
[0072] The computer readable medium 602 may be configured to store one or more programs,
[0073] When the one or more programs are executed by the one or more processors, the one or more processors implement the query instruction execution method as described in the above-mentioned embodiment 1 or embodiment 2.
[0074] Figure 7 The hardware structure of the electronic device in the seventh embodiment of the present application; Figure 7 As shown, the hardware structure of the electronic device may include: a processor 701, a communication interface 702, a computer readable medium 703 and a communication bus 704;
[0075] The processor 701, the communication interface 702, and the computer readable medium 703 communicate with each other via a communication bus 704;
[0076] Optionally, the communication interface 702 may be an interface of a communication module, such as an interface of a GSM module;
[0077] Among them, the processor 701 can be specifically configured to: determine the library name and / or table name to be filled in the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, wherein the execution plan is an execution plan with parameterized library name and / or table name; merge the business parameters, the table name and / or the library name to obtain the merged result of the business parameters, the table name and / or the library name in the execution plan of the query template corresponding to the first query instruction to be filled; based on the merged result, fill the business parameters, the table name and / or the library name into the execution plan respectively to generate a second query instruction sent to the node of the distributed database for execution.
[0078] The processor 701 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0079] The computer readable medium 703 can be, but is not limited to, a random access memory medium (RAM), a read-only memory medium (ROM), a programmable read-only memory medium (PROM), an erasable programmable read-only memory medium (EPROM), an electrically erasable read-only memory medium (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
[0080] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code configured to execute the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through a communication part, and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), the above functions defined in the method of the present application are executed. It should be noted that the computer-readable medium described in the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable medium can be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more conductors, a portable computer disk, a hard disk, a random access storage medium (RAM), a read-only storage medium (ROM), an erasable programmable read-only storage medium (EPROM or flash memory), an optical fiber, a portable compact disk read-only storage medium (CD-ROM), an optical storage medium, a magnetic storage medium, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, an apparatus or a device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program configured to be used by or in combination with an instruction execution system, an apparatus or a device. The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0081] Computer program code configured to perform the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0082] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment, or a part of a code, and the module, program segment, or a part of the code contains one or more executable instructions configured to implement the specified logical function. There are specific sequential relationships in the above-mentioned specific embodiments, but these sequential relationships are only exemplary. When the specific implementation is implemented, these steps may be less, more, or the execution order may be adjusted. That is, in some implementations as replacements, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0083] The modules involved in the embodiments of the present application may be implemented in software or in hardware. The modules described may also be provided in a processor, for example, may be described as: a processor comprising a first determination module, a merging module and a filling module. Among them, the names of these modules do not constitute a limitation on the module itself in certain circumstances, for example, the first determination module may also be described as "a module for determining the table name and / or library name in the execution plan of the query template corresponding to the first query instruction to be filled in based on the business parameters in the received first query instruction".
[0084] As another aspect, the present application further provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the method for executing a query instruction as described in the above-mentioned embodiment 1 or embodiment 2.
[0085] As another aspect, the present application also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by the device, the device: determines the library name and / or table name to be filled in the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, wherein the execution plan is an execution plan parameterized by the library name and / or the table name; merges the business parameters, the table name and / or the library name to obtain the merged result of the business parameters, the table name and / or the library name to be filled in the execution plan of the query template corresponding to the first query instruction; based on the merged result, fills the business parameters, the table name and / or the library name into the execution plan respectively to generate a second query instruction sent to the node of the distributed database for execution.
[0086] The expressions "first", "second", "the first" or "the second" used in various embodiments of the present disclosure may modify various components regardless of order and / or importance, but these expressions do not limit the corresponding components. The above expressions are only configured for the purpose of distinguishing an element from other elements. For example, a first user device and a second user device represent different user devices, although both are user devices. For example, a first element may be referred to as a second element, and similarly, a second element may be referred to as a first element without departing from the scope of the present disclosure.
[0087] When one element (e.g., a first element) is referred to as being "(operably or communicatively) coupled" or "(operably or communicatively) coupled to" or "connected to" another element (e.g., a second element), it is understood that the one element is directly connected to the other element or the one element is indirectly connected to the other element via yet another element (e.g., a third element). Conversely, it is understood that when an element (e.g., a first element) is referred to as being "directly connected" or "directly coupled" to another element (the second element), no element (e.g., a third element) is interposed between the two.
[0088] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.
Claims
1. A method for executing a query instruction, characterized in that: The method comprises: Determine, according to the business parameters in the received first query instruction, a library name and / or a table name to be filled into an execution plan of a query template corresponding to the first query instruction, wherein the execution plan is an execution plan after the library name and / or the table name is parameterized; Merging the business parameters, the table name and / or the library name to obtain a merged result of the business parameters, the table name and / or the library name to be filled into the execution plan of the query template corresponding to the first query instruction; Based on the merge result, the business parameter, the table name and / or the library name are respectively filled into the execution plan to generate a second query instruction sent to a node of the distributed database for execution; The merging of the business parameters, the table name and / or the library name to obtain a merging result of the business parameters, the table name and / or the library name to be filled into the execution plan of the query template corresponding to the first query instruction includes: Sorting the service parameters according to the order in which the service parameters appear in the first query instruction to obtain a sorted list of the service parameters; The table name and / or the library name are inserted into the sorted list of the business parameters according to the order of appearance of the special placeholders in the syntax unit in the execution plan to obtain the sorted list of the business parameters, the table name and / or the library name.
2. The method according to claim 1, characterized in that Before determining the library name and / or table name to be filled into the execution plan of the query template corresponding to the first query instruction according to the business parameters in the received first query instruction, the method further includes: Receiving the query template containing constant placeholders predefined by the client through a prepared statement; Parsing and optimizing the query template to obtain an execution plan of the query template based on a logic table; The table name and / or the library name in the execution plan based on the logical table is parameterized to obtain an execution plan with the table name and / or the library name parameterized.
3. The method according to claim 2, characterized in that The parameterizing the table name and / or the library name in the execution plan based on the logical table to obtain the execution plan with the table name and / or the library name parameterized includes: Traversing the first grammatical unit in the execution plan based on the logical table, if it is determined that the first grammatical unit contains the table name and / or the library name, replacing the table name and / or the library name with a special placeholder; If it is determined that the first grammatical unit does not contain the table name and / or the library name, and the first grammatical unit contains a subquery, determining whether a second grammatical unit in the subquery contains the table name and / or the library name; If it is determined that the second syntax unit in the subquery contains the table name and / or the library name, the table name and / or the library name is replaced with the special placeholder.
4. The method according to claim 3, characterized in that Before replacing the table name and / or the library name with a special placeholder, the method further includes: If it is determined that the table name and / or the library name has an alias, a step of replacing the table name and / or the library name with a special placeholder is performed; If it is determined that the table name and / or the library name does not have an alias, an alias having the same name as the table name and / or the library name is generated, and a step of replacing the table name and / or the library name with a special placeholder is performed.
5. The method according to claim 1, characterized in that The determining, according to the business parameters in the received first query instruction, the library name and / or table name to be filled in the execution plan of the query template corresponding to the first query instruction includes: The table name and / or the library name is determined based on the business parameters, the conditions for splitting the logical table into physical sub-tables, and the pre-configured library and table sub-table rules.
6. The method according to claim 1, characterized in that Based on the merge result, filling the business parameter, the table name and / or the library name into the execution plan respectively to generate a second query instruction sent to a node of the distributed database for execution, including: Traversing the syntax units in the parameterized execution plan of the table name and / or the library name, if the syntax units contain common placeholders, replacing the common placeholders with corresponding business parameters based on the merge result, so as to generate a second query instruction sent to a node of the distributed database for execution; If the grammatical unit contains a special placeholder, based on the merge result, the special placeholder is replaced with a corresponding table name and / or library name to generate a second query instruction that is sent to a node of the distributed database for execution.
7. A query instruction execution device, characterized in that: The device comprises: A first determination module, configured to determine, according to a business parameter in a received first query instruction, a table name and / or a library name to be filled into an execution plan of a query template corresponding to the first query instruction, wherein the execution plan is an execution plan after parameterizing the table name and / or the library name; a merging module, used to merge the business parameters, the table name and / or the library name to obtain a merged result of the business parameters, the table name and / or the library name to be filled into the execution plan of the query template corresponding to the first query instruction; A filling module, used to fill the business parameter, the table name and / or the library name into the execution plan respectively based on the merging result, so as to generate a second query instruction sent to a node of a distributed database for execution; The merging module is specifically used for: Sorting the service parameters according to the order in which the service parameters appear in the first query instruction to obtain a sorted list of the service parameters; The table name and / or the library name are inserted into the sorted list of the business parameters according to the order of appearance of the special placeholders in the syntax unit in the execution plan to obtain the sorted list of the business parameters, the table name and / or the library name.
8. The device according to claim 7, characterized in that Before the first determining module, the device further includes: A receiving module, configured to receive the query template containing constant placeholders predefined by a client through a prepared statement; A parsing and optimization module, used for parsing and optimizing the query template to obtain an execution plan of the query template based on a logic table; The parameterization module is used to parameterize the table name and / or the library name in the execution plan based on the logical table to obtain an execution plan with the table name and / or the library name parameterized.
9. The device according to claim 8, characterized in that The parameterization module comprises: A first replacement module is used for traversing a first syntax unit in an execution plan based on the logic table, and if it is determined that the first syntax unit contains the table name and / or the library name, replacing the table name and / or the library name with a special placeholder; a second determination module, configured to determine whether a second grammatical unit in the subquery contains the table name and / or the library name if it is determined that the first grammatical unit does not contain the table name and / or the library name, and the first grammatical unit contains a subquery; The second replacement module is used to replace the table name and / or the library name with the special placeholder if it is determined that the second grammatical unit in the subquery contains the table name and / or the library name.
10. The device according to claim 9, characterized in that Before the first replacement module, the parameterization module further includes: A first execution module, configured to execute a step of replacing the table name and / or the library name with a special placeholder if it is determined that the table name and / or the library name has an alias; The second execution module is used for generating an alias with the same name as the table name and / or the library name if it is determined that the table name and / or the library name has no alias, and executing the step of replacing the table name and / or the library name with a special placeholder.
11. The device according to claim 7, characterized in that The first determining module is specifically configured to: The table name and / or the library name is determined based on the business parameters, the conditions for splitting the logical table into physical sub-tables, and the pre-configured library and table sub-table rules.
12. The device according to claim 7, characterized in that The filling module is specifically used for: Traversing the syntax units in the parameterized execution plan of the table name and / or the library name, if the syntax units contain common placeholders, replacing the common placeholders with corresponding business parameters based on the merge result, so as to generate a second query instruction sent to a node of the distributed database for execution; If the grammatical unit contains a special placeholder, based on the merge result, the special placeholder is replaced with a corresponding table name and / or library name to generate a second query instruction that is sent to a node of the distributed database for execution.
13. A distributed database system, characterized in that: The system comprises: A client, a server connected to the client, and a distributed database node connected to the server; The client is used to send the service parameters in the first query instruction to the server; The server is used to determine, based on the received business parameters, a table name and / or a library name to be filled into an execution plan of a query template corresponding to the first query instruction, wherein the execution plan is an execution plan in which the table name and / or the library name are parameterized; and merge the business parameters, the table name and / or the library name to obtain a merged result of the business parameters, the table name and / or the library name in the execution plan of the query template corresponding to the first query instruction; and then based on the merged result, fill the business parameters, the table name and / or the library name into the execution plan respectively to generate a second query instruction sent to a node of the distributed database for execution; The merging of the business parameters, the table name and / or the library name to obtain a merging result of the business parameters, the table name and / or the library name to be filled into the execution plan of the query template corresponding to the first query instruction includes: Sorting the service parameters according to the order in which the service parameters appear in the first query instruction to obtain a sorted list of the service parameters; The table name and / or the library name are inserted into the sorted list of the business parameters according to the order of appearance of the special placeholders in the syntax unit in the execution plan to obtain the sorted list of the business parameters, the table name and / or the library name.
14. An electronic device comprising: one or more processors; A computer readable medium configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method for executing the query instruction as described in any one of claims 1 to 6.
15. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for executing the query instruction as described in any one of claims 1 to 6 is implemented.
