Method and apparatus for realizing cross-instance routing of structured query statement, and system
By receiving and forwarding structured query statements in database service instances, the problem of low data access across instances is solved, statement-level routing and resource saving is achieved, and OLTP query performance is improved.
Patent Information
- Application Number
- PCT/CN2024/116684
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-06
- Filing Date
- 2024-09-03
- Publication Date
- 2025-06-12
AI Technical Summary
In the database, accessing data across instances is inefficient and cannot meet the high-demand online transaction processing (OLTP) query scenarios.
The structured query statement is received through the first database service instance and it is determined whether it has the ability to send to the second database service instance. If available, establish a connection and forward the query statement to the second database service instance side for execution.
Optimize the intermediate redundancy invalid operation, implement statement-level routing, save resources in service instances, and improve the efficiency of data access across instances.
Smart Images

Figure CN2024116684_12062025_PF_FP_ABST
Abstract
Description
Method, device and system for implementing cross-instance routing of structured query statements Technical Field
[0001] The present disclosure relates to the field of databases, and in particular to a method, device, and system for implementing cross-instance routing of structured query statements. Background Art
[0002] In a database, when data resides in other data sources, access to that data is typically achieved through a foreign table mechanism. Furthermore, some distributed databases employ coordinating nodes and data nodes. The coordinating node aggregates and computes data from the data nodes before returning it to the user. This also involves cross-instance data access. However, this cross-instance access is often inefficient and cannot meet the high-performance requirements of online transaction processing (OLTP) queries.
[0003] Currently, no effective solution has been proposed to address the problem of low efficiency in accessing data across instances in related technologies.
[0004] Summary of the Invention
[0005] The embodiments of the present disclosure provide a method, device, and system for implementing cross-instance routing of structured query statements, which at least solve the problem of low efficiency in accessing data across instances in related technologies.
[0006] According to one aspect of an embodiment of the present disclosure, a method for implementing cross-instance routing of structured query statements is provided, including: a first database service instance end receives a structured query statement; the first database service instance end determines whether the structured query statement has the ability to be sent to a second database service instance end; if it is determined that the structured query statement has the ability to be sent to the second database service instance end, the first database service instance end establishes a connection with the second database service instance end, and forwards the structured query statement to the second database service instance end for execution.
[0007] Optionally, when a user end is connected to a first database service instance end through a simple query protocol, the first database service instance end determines whether a structured query statement has the ability to be sent to a second database service instance end, including: the first database service instance end receives a query message, wherein the query message carries a structured query statement; the first database service instance end parses the structured query statement into a parse tree data structure; the first database service instance end analyzes and verifies the database objects in the parse tree data structure to generate a query tree data structure; the first database service instance end analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance end.
[0008] Optionally, the first database service instance end analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance end, including: if the first database service instance end does not store the data that the structured query statement needs to query, determining that the structured query statement has the ability to be sent to the second database service instance end; if the first database service instance end stores the data that the structured query statement needs to query, determining that the structured query statement does not have the ability to be sent to the second database service instance end.
[0009] Optionally, forwarding the query statement to the second database service instance end for execution includes: the first database service instance end deleting the query tree data structure and entering the routing mode; after entering the routing mode, the first database service instance end forwarding the query message to the second database service instance end for execution; the first database service instance end searching for a port listening on the second database service instance end, establishing a connection with the port, and returning a query result received from the second database service instance end through the port to the user end, wherein the query result is queried by the second database service instance end according to the structured query statement; when the target message is received from the second database service instance end through the port, the first database service instance end exits the routing mode.
[0010] Optionally, when the user end is connected to the first database service instance end through an extended query protocol, the first database service instance end determines whether the structured query statement has the ability to be sent to the second database service instance end, including: the first database service instance end receives a parsing message from the user end, wherein the parsing message carries the structured query statement; the database service instance end parses the structured query statement into a parse tree data structure; the first database service instance end analyzes and verifies the database objects in the parse tree data structure to generate a query tree data structure; the first database service instance end analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance end.
[0011] Optionally, forwarding the query statement to the second database service instance end for execution includes: the first database service instance end deleting the query tree data structure and entering the routing mode; after entering the routing mode, the first database service instance end forwarding the parsed message to the second database service instance end for execution; the first database service instance end forwarding the bound message to the second database service instance end for execution, and storing the name of the structured query statement bound to the bound message and the association relationship between the structured query statement and the second database service instance end; the first database service instance end searching for a port listening on the second database service instance end, establishing a connection with the port, and returning a query result received from the second database service instance end through the port to the user end, wherein the query result is queried by the second database service instance end based on the structured query statement; when the target message is received from the second database service instance end through the port, the first database service instance end exits the routing mode.
[0012] Optionally, the above method also includes: when a binding message is detected, the first database service instance end searches locally to see whether a name identical to the structured query statement bound to the binding message is stored; if a name identical to the structured query statement bound to the binding message is stored on the first database service instance end, the first database service instance end determines the second database service instance end corresponding to the name of the structured query statement based on the association relationship; the first database service instance end enters routing mode, searches for a port listening to the second database service instance end, establishes a connection with the port, and returns the query result received from the second database service instance end through the port to the user end; when the target message is received through the port, the first database service instance end exits routing mode.
[0013] Optionally, the method further includes: when it is determined that the structured query statement cannot be sent to the second database service instance, the first database service instance executes the structured query statement locally.
[0014] According to another aspect of an embodiment of the present disclosure, a device for implementing cross-instance routing of structured query statements is also provided, including: a receiving module, configured to receive a structured query statement at a first database service instance end; a judging module, configured to judge at the first database service instance end whether the structured query statement has the ability to be sent to a second database service instance end; and a processing module, configured to establish a connection between the first database service instance end and the second database service instance end, and forward the structured query statement to the second database service instance end for execution, if it is judged that the structured query statement has the ability to be sent to the second database service instance end.
[0015] According to another aspect of an embodiment of the present disclosure, a system for implementing cross-instance routing of structured query statements is also provided, including: a first database service instance end and at least one second database service instance end, wherein the first database service instance end is used to run a database service instance and is configured to execute the method for implementing cross-instance routing of structured query statements in any of the above embodiments, wherein the database service instance is used to directly provide data services to the client; and at least one second database service instance end is used to run an external database service instance, wherein the external database service instance is used to provide external data services for the database service instance.
[0016] According to another aspect of the embodiments of the present disclosure, an electronic device is provided, including: a processor, and a memory for storing a program, wherein the program includes instructions, and when the instructions are executed by the processor, the processor executes the method for implementing cross-instance routing of structured query statements in any of the above embodiments.
[0017] According to yet another aspect of the embodiments of the present disclosure, a non-transitory machine-readable medium storing computer instructions is provided, where the computer instructions are used to cause a computer to execute the method for implementing cross-instance routing of structured query statements in any of the above embodiments.
[0018] Beneficial effects of the embodiments of the present disclosure:
[0019] In an embodiment of the present disclosure, a first database service instance receives a structured query statement; the first database service instance determines whether the structured query statement has the ability to be sent to a second database service instance; if it is determined that the structured query statement has the ability to be sent to the second database service instance, the first database service instance establishes a connection with the second database service instance, and forwards the structured query statement to the second database service instance for execution. In this manner, in a database service instance directly connected to a customer, an SQL query statement that can be completely pushed down to an external data source is forwarded to the external database instance through direct routing, thereby optimizing intermediate redundant and invalid operations, realizing statement-level routing, and saving resources in the service instance, thereby achieving the technical effect of improving the efficiency of cross-instance access to data, and further solving the technical problem of low efficiency of cross-instance access to data in related technologies.
[0020] The details of one or more embodiments of the present disclosure are set forth in the accompanying drawings and the description below to make other features, objects, and advantages of the present disclosure more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] To more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other embodiments can be derived from these drawings without inventive effort.
[0022] FIG1 is a schematic diagram of an execution path for accessing data across instances in the related art;
[0023] FIG2 is a flowchart of a method for implementing cross-instance routing of structured query statements according to an embodiment of the present disclosure;
[0024] FIG3 is a schematic diagram of an execution path for accessing data across instances according to an embodiment of the present disclosure;
[0025] FIG4a is a schematic diagram of the execution path of the user end connecting to the database using a simple query protocol;
[0026] FIG4 b is a schematic diagram of an execution path of a user terminal using a simple query protocol to connect to a database and access data across instances in the related art;
[0027] FIG4c is a schematic diagram of an execution path of a user terminal using a simple query protocol to connect to a database and access data across instances according to an embodiment of the present disclosure;
[0028] FIG4 d is a flowchart of a process in which a user terminal uses a simple query protocol to connect to a database and access data across instances according to an embodiment of the present disclosure;
[0029] FIG5a is a schematic diagram of the execution path of the user end connecting to the database using the extended query protocol;
[0030] FIG5 b is a schematic diagram of an execution path of a user terminal using an extended query protocol to connect to a database and access data across instances in the related art;
[0031] FIG5c is a schematic diagram of an execution path of a user terminal using an extended query protocol to connect to a database and access data across instances according to an embodiment of the present disclosure;
[0032] FIG5 d is a schematic diagram of an execution path of a user terminal using an extended query protocol to connect to a database and repeatedly access data across instances according to an embodiment of the present disclosure;
[0033] FIG6 is a structural block diagram of an apparatus for implementing cross-instance routing of structured query statements according to an embodiment of the present disclosure;
[0034] FIG7 is a structural block diagram of a system for implementing cross-instance routing of structured query statements according to an embodiment of the present disclosure;
[0035] FIG8 is a schematic structural diagram of an electronic device according to this embodiment. DETAILED DESCRIPTION
[0036] The following describes embodiments of the present invention in more detail with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the present invention. It should be understood that the accompanying drawings and embodiments of the present invention are for illustrative purposes only and are not intended to limit the scope of protection of the present invention.
[0037] In order to better understand the embodiments of the present disclosure, the technical terms involved in the embodiments of the present disclosure are explained as follows:
[0038] SQL, short for Structured Query Language, is a database query and programming language used to access data as well as query, update, and manage relational database systems.
[0039] The external table mechanism includes two aspects: one is connecting to the external data source. The external table query logic must first establish a connection with the external data source; the other is defining the query conditions. Before executing an external query, it is necessary to clarify the purpose of the query and the conditions for the required data.
[0040] OLTP, short for Online Transaction Processing, is one of the ways to quickly respond to user operations.
[0041] Database service instance: a database instance used to directly serve customers.
[0042] External database service instance: used to provide external data services for the database service instance.
[0043] Simple query protocol: Simple query protocol, client and database connection communication protocol,
[0044] Extend query protocol: The extended query protocol splits the simple protocol described above into several steps. The results of the preparation steps can be reused multiple times to improve efficiency.
[0045] Parse: Parsing process, responsible for parsing SQL statements into parse tree data structure.
[0046] Analyze: The analysis process is responsible for analyzing and verifying the database objects in the parse tree and generating the query tree.
[0047] Plan: The query optimization process is responsible for generating an executable query execution plan for the query tree based on relational algebra and physical execution cost.
[0048] execute: Plan execution process, responsible for executing the query execution plan and obtaining the execution results.
[0049] FIG1 is a schematic diagram of the execution path of cross-instance data access in related technologies. As shown in FIG1 , traditional cross-instance data access mainly includes the following execution steps:
[0050] The database service instance receives the SQL sent by the user and performs parse, analyze, plan, and execute in sequence. The database service instance optimizes the access SQL and generates an execution plan tree. In the plan tree, access to external data sources is abstracted as SQL, and then the external data source is accessed through SQL during execution.
[0051] The external database service instance receives the SQL sent by the database service instance, executes parse, analyze, plan, and execute in sequence, obtains the data query results, and returns them to the user.
[0052] The disadvantage of traditional cross-instance data access is that when the SQL in the database service instance only accesses external data sources, that is, when the SQL can be completely pushed down to the external data source, the parse, analyze, plan, and execute steps are performed in both the local database service instance and the external database service instance. This process involves redundant query optimization and redundant data packaging and unpacking when transmitting data between the database service instance and the external data source.
[0053] When accessing external data across instances, usually the entire statement can be completely sent to the external data source. At this time, the main role of the service instance connected by the user is to be responsible for the transfer of data, especially in the case of repeated execution. How to improve the efficiency of transfer can greatly improve the efficiency of accessing data across instances. In the technical solution provided by the present invention, when SQL can be completely pushed down to the external data source, based on cache caching technology, the transfer service in the database service instance is promoted to the routing transfer of data packets, avoiding the execution of SQL in the database service instance. Instead, the query request is directly routed to the external data source. The database service instance is only responsible for receiving the results of the external data source and routing them directly to the user end, which can greatly improve its execution efficiency. The following is a detailed explanation.
[0054] FIG2 is a flow chart of a method for implementing cross-instance routing of structured query statements according to an embodiment of the present disclosure. As shown in FIG2 , the method includes the following steps:
[0055] Step S202: The first database service instance receives a structured query statement.
[0056] It should be noted that the first database service instance end is a hardware device that runs a database service instance.
[0057] In step S204 , the first database service instance determines whether the structured query statement has the capability of being sent to the second database service instance.
[0058] Step S206: If it is determined that the structured query statement has the ability to be sent to the second database service instance end, the first database service instance end establishes a connection with the second database service instance end and forwards the structured query statement to the second database service instance end for execution.
[0059] The second database service instance end is a hardware device that runs an external database service instance.
[0060] Figure 3 is a schematic diagram of an execution path for cross-instance data access according to an embodiment of the present disclosure. The technical solution provided by the present disclosure uses the execution plan obtained after query optimization of SQL in the database service instance. By determining whether it can be completely pushed down (check push in Figure 3), this SQL is marked in memory as routing SQL (mark as route in Figure 3), and a connection to the external data source is established. The query message is routed to the external database instance, and the results of the external database instance are monitored and directly routed to the user. The external database instance performs parse, analyze, plan, and execute without any intermediate parsing. The database service instance is responsible for receiving user-side messages and, based on the message type, determines whether to process locally or route to an external data instance for processing.
[0061] Through the above technical solution, by forwarding SQL query statements that can be completely pushed down to external data sources to external database instances through direct routing in the database service instance directly connected to the customer, the purpose of optimizing intermediate redundant and invalid operations, realizing statement-level routing, and saving resources in the service instance is achieved, thereby achieving the technical effect of improving the efficiency of cross-instance access to data.
[0062] Since the protocols used by users to connect to the database are usually divided into two types, one is the simple query protocol and the other is the extended query protocol, the following describes the detailed design under the two different protocols.
[0063] According to an optional embodiment of the present disclosure, when a user end is connected to a first database service instance end via a simple query protocol, step S204 is performed in which the first database service instance end determines whether a structured query statement has the ability to be sent to a second database service instance end, including the following steps: the first database service instance end receives a query message, wherein the query message carries a structured query statement; the first database service instance end parses the structured query statement into a parse tree data structure; the first database service instance end analyzes and verifies database objects in the parse tree data structure to generate a query tree data structure; the first database service instance end analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance end.
[0064] As an optional embodiment of the present disclosure, the first database service instance end analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance end, which is achieved by the following method: if the first database service instance end does not store the data that the structured query statement needs to query, it is determined that the structured query statement has the ability to be sent to the second database service instance end; if the first database service instance end stores the data that the structured query statement needs to query, it is determined that the structured query statement does not have the ability to be sent to the second database service instance end.
[0065] Figure 4a is a schematic diagram of the execution path for a user connecting to a database using the simple query protocol. As shown in Figure 4a, under the simple query protocol, the user only sends a query message (i.e., the Query message in Figure 4a, hereinafter referred to as the Q message) carrying an SQL statement. The database service instance is responsible for receiving the Q message and processing it, namely, performing parse, analyze, plan, and execute operations, and then sending the data row Data Row as the return result to the user. Figure 4a also shows that before returning the data row Data Row to the user, the database service instance first sends a data description message Row Description to the user. After sending the data row Data Row, it also needs to send a command completion message Command Complete to the user. When the user receives the Ready For Query message sent by the database instance, the query process ends.
[0066] Figure 4b is a schematic diagram of the execution path of the user end using a simple query protocol to connect to the database for cross-instance data access in the related art. Under the simple query protocol, the database cannot effectively cache the query optimization results, so the database service instance needs to execute parse, analyze, plan, and execute for each execution. In the case of retrieving data across instances, the external database service instance also needs to execute parse, analyze, plan, and execute once. At the same time, the database service instance needs to receive the data (Data Row) returned by the external database service instance, and is responsible for parsing the data transmitted from the external database service instance according to the execution plan, and then repackaging and sending it to the user end. In the database service instance, query optimization and execution are the most time-consuming stages, and this redundant operation brings performance loss.
[0067] Figure 4c is a schematic diagram of the execution path of a user terminal using a simple query protocol to connect to a database for cross-instance data access according to an embodiment of the present disclosure. As shown in Figure 4c, in order to solve the above technical problems, the technical solution provided by the embodiment of the present disclosure adopts a method of analyzing the query tree data structure (Query Tree) after parse and analyze in the database service instance to determine whether the SQL can be completely sent to the external database service instance (check and push in Figure 4c). If the SQL can be completely sent to the external database service instance, the database service instance enters the routing mode (enter router mode in Figure 4c), selects the corresponding external data source connection, and routes the current Q message directly to the external data service library service instance for execution, that is, executes parse, analyze, plan, and execute in the external database service instance. At this time, the database service instance directly connected to the client acts as a routing function. Direct routing avoids redundant query optimization and execution in the database service instance, thereby improving execution efficiency.
[0068] According to an optional embodiment of the present disclosure, step S206 is executed to forward the query statement to the second database service instance end for execution, which is achieved by the following method: the first database service instance end deletes the query tree data structure and enters routing mode; after entering routing mode, the first database service instance end forwards the query message to the second database service instance end for execution; the first database service instance end searches for a port listening on the second database service instance end, establishes a connection with the port, and returns a query result received from the second database service instance end through the port to the user end, wherein the query result is found by the second database service instance end based on the structured query statement; when a target message (Ready For Query) is received from the second database service instance end through the port, the first database service instance end exits routing mode.
[0069] FIG4 d is a flowchart of a process for a user terminal to connect to a database using a simple query protocol to access data across instances according to an embodiment of the present disclosure. As shown in FIG4 d , the entire process includes the following steps:
[0070] S1: The user sends a Q message to the database service instance, which carries SQL.
[0071] S2: After receiving the Q message, the database parses and analyzes the SQL to obtain the Query Tree.
[0072] S3: The database service instance analyzes the query tree to determine whether the SQL statement can be pushed down to the external database service instance. If not, the SQL statement is executed on the local database service instance. If yes, the query tree is cleared, the system enters routing mode, and a connection is found and established with the port listening on the external database service instance.
[0073] S4, the database service instance determines whether the message from the external database service instance is Ready For Query; if the judgment result is no, the query result from the external database service instance is returned to the user end; if the judgment result is yes, the database service instance exits the routing mode and ends the query process.
[0074] In some optional embodiments of the present disclosure, when a user end is connected to a first database service instance end through an extended query protocol, step S204 is executed in which the first database service instance end determines whether the structured query statement has the ability to be sent to the second database service instance end, and the following steps are also included: the first database service instance end receives a parsing message, wherein the parsing message carries a structured query statement; the first database service instance end parses the structured query statement into a parse tree data structure; the first database service instance end analyzes and verifies the database objects in the parse tree data structure to generate a query tree data structure; the database service instance end analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance end.
[0075] Figure 5a illustrates the execution path for connecting to a database using the extended query protocol. To reduce the need for repeated query optimization on the database server side in the simple query protocol, the extended query protocol breaks the query process into several steps, reusing the optimization results multiple times to avoid repeated query optimization. This typically includes messages such as Parse, Describe, Bind, and Execute. The Describe statement is used to view table structure information, including column names, data types, and constraints. The Bind message is used to bind the SQL statement to the database server instance.
[0076] As shown in Figure 5a, the entire execution process includes the following steps:
[0077] The user sends a Parse message containing SQL to the database service instance. After receiving the Parse message, the database service instance executes the Parse and Analyze commands, then sends a Parse Complete command to the user. The user sends a Bind message to the database service instance. After receiving the Bind message, the database service instance executes the Plan command, then sends a Bind Complete command to the user. The user sends a Describe message to the database service instance. After receiving the Describe message, the database service instance sends a Row Description message back to the user. The user sends an Execute message to the database service instance. The database service instance executes the Execute command and returns the query result, Data Row, to the user. The user sends a Sync message to the database service instance. After receiving the Sync message, the database service instance sends a Ready For Query message back to the user, completing the query.
[0078] Figure 5b is a schematic diagram of the execution path in the related art where the user uses the extended query protocol to connect to the database for cross-instance data access. Under the extend query protocol, the database service instance inevitably needs to unpack and pack the data in the external database and process the data during the execution phase (that is, the external database service instance executes the steps shown in Figure 5a). At the same time, the database instance service process needs to cache the entire execution plan, which occupies more resources.
[0079] In some other optional embodiments of the present disclosure, executing step S206 to forward the query statement to the second database service instance end for execution includes the following steps: the first database service instance end deletes the query tree data structure and enters routing mode; after entering routing mode, the first database service instance end forwards the parsed message to the second database service instance end for execution; the first database service instance end forwards the binding message to the second database service instance end for execution, and stores the name of the structured query statement bound to the binding message and the association between the structured query statement and the second database service instance end; the first database service instance end searches for a port listening on the second database service instance end, establishes a connection with the port, and returns a query result received from the second database service instance end through the port to the user end, wherein the query result is found by the second database service instance end based on the structured query statement; and when the target message is received from the second database service instance end through the port, the first database service instance end exits routing mode.
[0080] Figure 5c is a schematic diagram of the execution path of a user terminal using an extended query protocol to connect to a database for cross-instance data access according to an embodiment of the present disclosure. As shown in Figure 5c, to solve the above technical problems, the technical solution provided by the embodiment of the present disclosure adopts the method of analyzing the query tree after parse and analyze in the database service instance to determine whether the SQL can be completely sent to the external database service instance (check and push in Figure 5c). If the SQL can be completely sent to the external database service instance, the corresponding external data source connection is selected, and the current Parse message is directly routed to the external data service instance for execution (i.e., the steps shown in Figure 5a are executed in the external database service instance). At the same time, the database service instance enters routing mode (enter router mode in Figure 5c) and clears the internal cached QueryTree. At the same time, the subsequent Bind message is directly routed to the external database service instance and records the name of the corresponding SQL and the connection information of the corresponding external database service instance for subsequent repeated execution to find and route. At this time, the database service instance directly connected to the client enters routing mode, and the instance acts as a routing function. When the external data database service instance completes the query and sends the Ready For Query message, the data service instance processes the message and stops routing. This solution avoids redundant query optimization and execution in the database service instance through direct routing, thereby improving execution efficiency.
[0081] As an optional embodiment of the present disclosure, when a binding message is detected, the first database service instance end searches locally to see whether a name identical to the structured query statement bound to the binding message is stored; if a name identical to the structured query statement bound to the binding message is stored on the first database service instance end, the first database service instance end determines the second database service instance end corresponding to the name of the structured query statement based on the association relationship; the first database service instance end enters routing mode, searches for a port listening to the second database service instance end, establishes a connection with the port, and returns the query result received from the second database service instance end through the port to the user end; when the target message is received through the port, the first database service instance end exits routing mode.
[0082] Figure 5d is a schematic diagram of the execution path of a user terminal using an extended query protocol to connect to a database and repeatedly access data across instances according to an embodiment of the present disclosure. As shown in Figure 5d, when the user terminal repeatedly executes SQL, it only needs to resend the Bind message and carry the SQL name set during the first Bind (Bind with name in Figure 5d). The database server checks whether the name recorded during the first execution exists (check in Figure 5d). If so, it finds the corresponding external database service instance based on its information, and then enters the routing mode (enter router mode in Figure 5d). When the external data database service instance completes the query and returns Ready For Query, the database service instance stops the routing mode and resumes normal execution.
[0083] According to another optional embodiment of the present disclosure, when it is determined that the structured query statement cannot be sent to the second database service instance, the first database service instance executes the structured query statement locally.
[0084] In the embodiments of the present disclosure, not all SQL statements need to be routed to an external database service instance for execution. For example, some SQL statements may require data that can be found in the local database service instance. In this case, the SQL statement does not need to be routed to an external database service instance for execution. Therefore, in the embodiments of the present disclosure, the database service instance is responsible for receiving user-side messages and, based on the message type, determining whether to process the message locally or route it to an external database service instance for processing.
[0085] The technical solution provided by the embodiments of the present disclosure forwards queries that can be completely pushed down to external data sources to external database service instances through direct routing in the database service instance directly connected to the client, thereby avoiding redundant query optimization and execution processes in the local database service instance, as well as the unpacking and repackaging processes required for data transfer. While being compatible with local queries of the directly connected database instance, the efficiency of cross-instance data access is greatly improved.
[0086] It is understandable that the technical solution provided by the present disclosure can be applied to a stand-alone database as well as a distributed database.
[0087] Based on the above-mentioned method for implementing cross-instance routing of structured query statements provided by an embodiment of the present invention, an embodiment of the present invention further provides an apparatus for implementing cross-instance routing of structured query statements, the apparatus comprising:
[0088] The receiving module 60 is configured to receive a structured query statement at the first database service instance end.
[0089] The judgment module 62 is used for the first database service instance to judge whether the structured query statement has the ability to be sent to the second database service instance.
[0090] The processing module 64 is configured to establish a connection with the second database service instance end and forward the structured query statement to the second database service instance end for execution if it is determined that the structured query statement has the ability to be sent to the second database service instance end.
[0091] The above-mentioned device for implementing cross-instance routing of structured query statements provided by an embodiment of the present invention optimizes intermediate redundant and invalid operations by forwarding SQL query statements that can be completely pushed down to external data sources to external database instances through direct routing in database service instances directly connected to customers, realizes statement-level routing, and saves resources in service instances, thereby achieving the technical effect of improving the efficiency of cross-instance access to data.
[0092] It should be noted that the preferred implementation of the embodiment shown in FIG6 can refer to the relevant description of the embodiment shown in FIG2 , which will not be repeated here.
[0093] FIG7 is a structural block diagram of a system for implementing cross-instance routing of structured query statements according to an embodiment of the present disclosure. As shown in FIG7 , the system includes: a first database service instance end 70 and at least one second database service instance end 72, wherein:
[0094] The first database service instance end 70 is used to run a database service instance and is configured to execute the method for implementing cross-instance routing of structured query statements in any of the above embodiments, wherein the database service instance is used to directly provide data services to the client; at least one second database service instance end 72 is used to run an external database service instance, wherein the external database service instance is used to provide external data services for the database service instance.
[0095] The database service instance end 70 and the at least one second database service instance end 72 are both hardware devices for running database service instances, including but not limited to computer devices.
[0096] An embodiment of the present invention further provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, wherein the computer program, when executed by the at least one processor, causes the electronic device to perform the method of an embodiment of the present invention.
[0097] An embodiment of the present invention further provides a non-transitory machine-readable medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform the method of the embodiment of the present invention.
[0098] An embodiment of the present invention further provides a computer program product, including a computer program, wherein when the computer program is executed by a processor of a computer, it is used to enable the computer to perform the method of the embodiment of the present invention.
[0099] With reference to Figure 8, the structural block diagram of the electronic device that can be used as the server or client of an embodiment of the present invention will now be described, which is an example of a hardware device that can be applied to various aspects of the present invention. The electronic device is intended to represent various forms of digital electronic computer equipment, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0100] As shown in Figure 8, the electronic device includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device can also be stored. The computing unit 801, ROM 802, and RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0101] Multiple components within the electronic device are connected to the I / O interface 805, including an input unit 806, an output unit 807, a storage unit 808, and a communication unit 809. The input unit 806 can be any type of device capable of inputting information into the electronic device. The input unit 806 can receive input digital or character information and generate key signal inputs related to user settings and / or function control of the electronic device. The output unit 807 can be any type of device capable of presenting information and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 808 may include, but is not limited to, a magnetic disk or an optical disk. The communication unit 809 allows the electronic device to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0102] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a CPU, a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above. For example, in some embodiments, the method embodiments of the present invention may be implemented as a computer program, which is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on an electronic device via ROM 802 and / or communication unit 809. In some embodiments, the computing unit 801 may be configured to perform the above-described method in any other appropriate manner (e.g., by means of firmware).
[0103] The computer programs for implementing the methods of the embodiments of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer programs are executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer programs may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0104] In the context of an embodiment of the present invention, a machine-readable medium can be a tangible medium that can contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable signal medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0105] It should be noted that the term "including" and its variations used in the embodiments of the present invention are open-ended, i.e., "including but not limited to." The term "based on" means "based at least in part on." The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; and the term "some embodiments" means "at least some embodiments." The modifications of "one" and "a plurality of" mentioned in the embodiments of the present invention are illustrative and non-restrictive. Those skilled in the art should understand that, unless the context clearly indicates otherwise, they should be understood as "one or more."
[0106] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0107] The various steps described in the method implementation scheme provided in the embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method implementation scheme may include additional steps and / or omit the steps shown. The scope of protection of the present invention is not limited in this respect.
[0108] The term "embodiment" in this specification refers to specific features, structures, or characteristics described in conjunction with the embodiment that can be included in at least one embodiment of the present invention. The appearance of this phrase in various places in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. The various embodiments in this specification are described in a related manner, and the same or similar parts between the various embodiments are referenced to each other. In particular, for the embodiments of the device, equipment, and system, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts are referred to the partial description of the method embodiment.
[0109] The above-described embodiments merely illustrate several implementations of the present invention. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, all of which fall within the scope of the present invention. Therefore, the scope of the present invention shall be determined by the appended claims.
Claims
1. A method for implementing cross-instance routing of structured query statements, comprising: The first database service instance receives a structured query statement; The first database service instance determines whether the structured query statement has the ability to be sent to the second database service instance; When it is determined that the structured query statement has the ability to be sent to the second database service instance end, the first database service instance end establishes a connection with the second database service instance end and forwards the structured query statement to the second database service instance end for execution.
2. The method according to claim 1, wherein: When the user end is connected to the first database service instance end through a simple query protocol, the first database service instance end determines whether the structured query statement has the ability to be sent to the second database service instance end, including: The first database service instance receives a query message, wherein the query message carries the structured query statement; The first database service instance parses the structured query statement into a parse tree data structure; The first database service instance end analyzes and verifies the database objects in the parse tree data structure to generate a query tree data structure; The first database service instance analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance.
3. The method according to claim 2, wherein: The first database service instance analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance, including: If the first database service instance does not store the data to be queried by the structured query statement, determining that the structured query statement has the ability to be sent to the second database service instance; If the first database service instance stores data that needs to be queried by the structured query statement, it is determined that the structured query statement does not have the ability to be sent to the second database service instance.
4. The method according to claim 2, wherein: Forwarding the query statement to the second database service instance for execution includes: The first database service instance deletes the query tree data structure and enters routing mode; After entering the routing mode, the first database service instance end forwards the query message to the second database service instance end for execution; The first database service instance end searches for a port listening to the second database service instance end, establishes a connection with the port, and returns a query result received from the second database service instance end through the port to the user end, wherein the query result is obtained by the second database service instance end according to the structured query statement; In case of receiving a target message from the second database service instance end through the port, the first database service instance end exits the routing mode.
5. The method according to claim 1, wherein: When the user end is connected to the first database service instance end through the extended query protocol, the first database service instance end determines whether the structured query statement has the ability to be sent to the second database service instance end, including: The first database service instance receives a parsing message, wherein the parsing message carries the structured query statement; The first database service instance parses the structured query statement into a parse tree data structure; The first database service instance end analyzes and verifies the database objects in the parse tree data structure to generate a query tree data structure; The first database service instance analyzes the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance.
6. The method according to claim 5, wherein: Forwarding the query statement to the second database service instance for execution includes: The first database service instance deletes the query tree data structure and enters routing mode; After entering the routing mode, the first database service instance end forwards the parsing message to the second database service instance end for execution; The first database service instance end forwards the binding message to the second database service instance end for execution, and stores the name of the structured query statement bound to the binding message and the association relationship between the structured query statement and the second database service instance end; The first database service instance end searches for a port listening to the second database service instance end, establishes a connection with the port, and returns a query result received from the second database service instance end through the port to the user end, wherein the query result is obtained by the second database service instance end according to the structured query statement; In case of receiving a target message from the second database service instance end through the port, the first database service instance end exits the routing mode.
7. The method according to claim 6, wherein: The method further comprises: When a binding message is detected, the first database service instance searches locally to see whether a name identical to the structured query statement name bound to the binding message is stored; If a name identical to the name of the structured query statement bound to the binding message is stored in the first database service instance end, the first database service instance end determines a second database service instance end corresponding to the name of the structured query statement according to the association relationship; The first database service instance end enters the routing mode, searches for the port listening to the second database service instance end, establishes a connection with the port, and returns the query result received from the second database service instance end through the port to the user end; When the target message is received through the port, the first database service instance end exits the routing mode.
8. The method according to any one of claims 1 to 7, wherein: The method further comprises: In the case where it is determined that the structured query statement does not have the capability of being sent to the second database service instance end, The first database service instance locally executes the structured query statement.
9. The method according to claim 1, wherein: The first database service instance end is a hardware device that runs a database service instance.
10. The method according to claim 1, wherein: The second database service instance end is a hardware device that runs an external database service instance, wherein the external database service instance is used to provide external data services for the database service instance.
11. A device for implementing cross-instance routing of structured query statements, comprising: A receiving module, configured to receive a structured query statement at the first database service instance end; A judgment module, used for the first database service instance to judge whether the structured query statement has the ability to be sent to the second database service instance; The processing module is used to establish a connection between the first database service instance end and the second database service instance end when it is determined that the structured query statement has the ability to be sent to the second database service instance end, and forward the structured query statement to the second database service instance end for execution.
12. The device according to claim 11, wherein: The judgment module includes: The first receiving unit is configured to control the first database service instance to receive a query message, wherein the query message carries the structured query statement; The first parsing unit is configured to control the first database service instance end to parse the structured query statement into a parse tree data structure; The first verification unit is configured to control the first database service instance end to analyze and verify the database objects in the parse tree data structure to generate a query tree data structure; The first determination unit is configured to control the first database service instance to analyze the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance.
13. The device according to claim 12, wherein: The analysis unit is configured to determine that the structured query statement has the ability to be sent to the second database service instance end if the first database service instance end does not store the data that the structured query statement needs to query; and to determine that the structured query statement does not have the ability to be sent to the second database service instance end if the first database service instance end stores the data that the structured query statement needs to query.
14. The device according to claim 12, wherein: Processing module, including: The first deletion unit is configured to control the first database service instance to delete the query tree data structure and enter a routing mode; The first forwarding unit is configured to control the first database service instance end to forward the query message to the second database service instance end for execution after entering the routing mode; The first establishing unit is configured to control the first database service instance end to search for a port that monitors the second database service instance end, establish a connection with the port, and return a query result received from the second database service instance end through the port to the user end, wherein the query result is obtained by the second database service instance end according to the structured query statement; The first exit unit is configured to control the first database service instance end to exit the routing mode when a target message is received from the second database service instance end through the port.
15. The device according to claim 11, wherein The judgment module includes: The second receiving unit is configured to control the first database service instance to receive a parsing message, wherein the parsing message carries the structured query statement; The second parsing unit is configured to control the first database service instance end to parse the structured query statement into a parse tree data structure; The second verification unit is configured to control the first database service instance end to analyze and verify the database objects in the parse tree data structure to generate a query tree data structure; The second determination unit is configured to control the first database service instance to analyze the query tree data structure to determine whether the structured query statement has the ability to be sent to the second database service instance.
16. The device according to claim 15, wherein: Processing module, including: The entry unit is configured to control the first database service instance end to delete the query tree data structure and enter a routing mode; The second forwarding unit is configured to control the first database service instance end to forward the parsing message to the second database service instance end for execution after entering the routing mode; The execution unit is configured to control the first database service instance end to forward the binding message to the second database service instance end for execution, and store the name of the structured query statement bound to the binding message and the association relationship between the structured query statement and the second database service instance end; The monitoring unit is configured to control the first database service instance end to search for a port that monitors the second database service instance end, establish a connection with the port, and return a query result received from the second database service instance end through the port to the user end, wherein the query result is obtained by the second database service instance end according to the structured query statement; The second exit unit is configured to cause the first database service instance end to exit the routing mode when a target message is received from the second database service instance end through the port.
17. The device according to claim 16, wherein: The device also includes: A binding module, configured to, when a binding message is detected, enable the first database service instance to search locally whether a name identical to the name of the structured query statement bound to the binding message is stored; A storage module, configured to store a name identical to the name of the structured query statement bound to the binding message in the first database service instance end, and control the first database service instance end to determine a second database service instance end corresponding to the name of the structured query statement according to the association relationship; A search module, used to control the first database service instance end to enter a routing mode, search for a port listening to the second database service instance end, establish a connection with the port, and return a query result received from the second database service instance end through the port to the user end; An exit module is used to control the first database service instance end to exit the routing mode when the target message is received through the port.
18. A system for implementing cross-instance routing of structured query statements, comprising: A first database service instance end and at least one second database service instance end, wherein: The first database service instance terminal is used to run the database service instance and is configured to execute the The method for implementing cross-instance routing of structured query statements as described in any one of 10, wherein the database service instance is used to directly provide data services to the client; The at least one second database service instance end is used to run an external database service instance, wherein the external database service instance is used to provide external data services for the database service instance.
19. An electronic device comprising: A processor, and a memory storing a program, wherein the program includes instructions, and when the instructions are executed by the processor, the processor executes the method for implementing cross-instance routing of structured query statements according to any one of claims 1 to 10.
20. A non-transitory machine-readable medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the method for implementing cross-instance routing of structured query statements according to any one of claims 1 to 10.
Citation Information
Patent Citations
Data query method and device, equipment and storage medium
CN110032575A
Data processing method and device
CN111475588A
Data processing method and device
CN111897891A
Information processing method, information processing device, storage medium and electronic equipment
CN112527817A
System and method for the optimization of database acess in data base networks
US20060167883A1
Cited By
Query statement processing method and device, vehicle and storage medium
CN120804139A