Method, device and system for realizing cross-instance routing of structured query statements

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 savings are achieved, and query performance is improved.

CN120144602APending Publication Date: 2025-06-13ALIBABA CLOUD COMPUTING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311669510.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-06
Publication Date
2025-06-13

AI Technical Summary

Technical Problem

The existing technology has low efficiency in cross-instance access data, and cannot meet the online transaction processing (OLTP) query scenarios that have high requirements for query performance.

Method used

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.

Benefits of technology

Optimize the intermediate redundancy invalid operation, implement statement-level routing, save resources in service instances, and improve the efficiency of data access across instances.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120144602A_ABST
    Figure CN120144602A_ABST
Patent Text Reader

Abstract

The invention relates to a method, a device and a system for realizing cross-instance routing of structured query statements. The method comprises the steps that a first database service instance end receives a structured query statement; the first database service instance side judges whether the structured query statement has the capability of being sent to a second database service instance side or not; and under the condition that the structured query statement is judged to have the capability of sending to the second database service instance end, establishing connection between the first database service instance end and the second database service instance end, and forwarding the structured query statement to the second database service instance end for execution. The technical problem of low cross-instance data access efficiency in related technologies is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application 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 exists in other data sources, access to data in other data sources is generally achieved through the foreign table mechanism. At the same time, in some distributed databases, a coordinating node and data nodes are introduced. The coordinating node is responsible for summarizing and calculating the data of the data nodes and then returning it to the user. There is also a situation of cross-instance data access. However, this kind of cross-instance access is usually relatively inefficient and cannot meet the requirements of online transaction processing (OLTP) query scenarios with high requirements for query performance.

[0003] Regarding the problem of low efficiency of cross-instance data access in related technologies, no effective solution has been proposed yet. Summary of the Invention

[0004] A method, device, and system for implementing cross-instance routing of structured query statements provided by an embodiment of this application can at least solve the problem of low efficiency of cross-instance data access in related technologies.

[0005] According to one aspect of the embodiments of this application, a method for implementing cross-instance routing of structured query statements is provided, including: the 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 the second database service instance end; in the case where 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.

[0006] Optionally, in the case where 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 end receives a query message, where the query message carries the 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 validates 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.

[0007] Optionally, 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 data required to be queried by the structured query statement is not stored at the first database service instance, it is determined that the structured query statement has the ability to be sent to the second database service instance; if the data required to be queried by the structured query statement is stored at the first database service instance, it is determined that the structured query statement does not have the ability to be sent to the second database service instance.

[0008] Optionally, 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 the routing mode; after entering the routing mode, the first database service instance forwards the query message to the second database service instance for execution; the first database service instance finds the port listening to the second database service instance, establishes a connection with the port, and returns the query result received from the second database service instance through the port to the user side, where the query result is queried by the second database service instance according to the structured query statement; in the case of receiving a target message from the second database service instance through the port, the first database service instance exits the routing mode.

[0009] Optionally, when the user side is connected to the first database service instance through the extended query protocol, the first database service instance determines whether the structured query statement has the ability to be sent to the second database service instance, including: the first database service instance receives a parsing message from the user side, where the parsing message carries the structured query statement; the database service instance parses the structured query statement into a parsing tree data structure; the first database service instance analyzes and validates the database objects in the parsing 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.

[0010] Optionally, forwarding the query statement to the second database service instance for execution includes: the first database service instance deleting the query tree data structure and entering the routing mode; after entering the routing mode, the first database service instance forwarding the parsing message to the second database service instance for execution; the first database service instance forwarding the binding message to the second database service instance for execution and storing the name of the structured query statement bound by the binding message and the association relationship between the structured query statement and the second database service instance; the first database service instance looking up the port listening to the second database service instance, establishing a connection with the port, and returning the query result received from the second database service instance through the port to the user side, where the query result is queried by the second database service instance according to the structured query statement; in the case of receiving a target message from the second database service instance through the port, the first database service instance exits the routing mode.

[0011] Optionally, the above method further includes: when detecting a binding message, the first database service instance locally looking up whether there is a name that is the same as the name of the structured query statement bound by the binding message; if there is a name in the first database service instance that is the same as the name of the structured query statement bound by the binding message, the first database service instance determining the second database service instance corresponding to the name of the structured query statement according to the association relationship; the first database service instance entering the routing mode, looking up the port listening to the second database service instance, establishing a connection with the port, and returning the query result received from the second database service instance through the port to the user side; in the case of receiving a target message through the port, the first database service instance exits the routing mode.

[0012] Optionally, the above method further includes: in the case of determining that the structured query statement does not have the ability to be sent to the second database service instance, the first database service instance locally executes the structured query statement.

[0013] According to another aspect of the embodiments of the present application, there is also provided a device for implementing cross-instance routing of structured query statements, including: a receiving module for the first database service instance to receive a structured query statement; a judging module 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; a processing module for, in the case of judging that the structured query statement has the ability to be sent to the second database service instance, the first database service instance establishing a connection with the second database service instance and forwarding the structured query statement to the second database service instance for execution.

[0014] According to another aspect of the embodiments of the present application, there is also provided a system for implementing cross-instance routing of structured query statements, 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, and the database service instance is used to directly provide data services for the client; at least one second database service instance end is used to run an external database service instance, and the external database service instance is used to provide external data services for the database service instance.

[0015] According to yet another aspect of the embodiments of the present application, there is also provided an electronic device, including: a processor and a memory storing a program, the program including instructions that, when executed by the processor, cause the processor to execute the method for implementing cross-instance routing of structured query statements in any of the above embodiments.

[0016] According to yet another aspect of the embodiments of the present application, there is also provided a non-transitory machine-readable medium storing computer instructions, the computer instructions being used to cause a computer to execute the method for implementing cross-instance routing of structured query statements in any of the above embodiments.

[0017] Advantages of the embodiments of the present application:

[0018] In the embodiments of the present application, the first database service instance end is adopted to receive structured query statements; 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; in the case where 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. By directly routing the SQL query statements that can be fully pushed down to the external data source in the database service instance directly connected to the client to the external database instance, the purpose of optimizing the redundant and ineffective operations in the middle is achieved, the statement-level routing is realized, and the resources in the service instance are saved, thereby achieving the technical effect of improving the efficiency of cross-instance data access, and further solving the technical problem of low efficiency of cross-instance data access in the related art.

[0019] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more concise and understandable. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other embodiments can also be obtained based on these drawings.

[0021] Figure 1 It is a schematic diagram of the execution path for accessing data across instances in the related art;

[0022] Figure 2 It is a flowchart of a method for implementing cross-instance routing of structured query statements according to an embodiment of the present application;

[0023] Figure 3 It is a schematic diagram of the execution path for accessing data across instances according to an embodiment of the present application;

[0024] Figure 4a It is a schematic diagram of the execution path for the client to connect to the database using the simple query protocol;

[0025] Figure 4b It is a schematic diagram of the execution path for the client to connect to the database using the simple query protocol and access data across instances in the related art;

[0026] Figure 4c It is a schematic diagram of the execution path for the client to connect to the database using the simple query protocol and access data across instances according to an embodiment of the present application;

[0027] Figure 4d It is a flowchart of a program for the client to connect to the database using the simple query protocol and access data across instances according to an embodiment of the present application;

[0028] Figure 5a It is a schematic diagram of the execution path for the client to connect to the database using the extended query protocol;

[0029] Figure 5b It is a schematic diagram of the execution path for the client to connect to the database using the extended query protocol and access data across instances in the related art;

[0030] Figure 5c It is a schematic diagram of the execution path for the client to connect to the database using the extended query protocol and access data across instances according to an embodiment of the present application;

[0031] Figure 5d It is a schematic diagram of the execution path for the client to connect to the database using the extended query protocol and repeatedly access data across instances according to an embodiment of the present application;

[0032] Figure 6It is a structural block diagram of a device for implementing cross-instance routing of structured query statements according to an embodiment of the present application;

[0033] Figure 7 It is a structural block diagram of a system for implementing cross-instance routing of structured query statements according to an embodiment of the present application;

[0034] Figure 8 It is a schematic structural diagram of an electronic device in this embodiment. Detailed implementation manners

[0035] Embodiments of this embodiment will be described in more detail below with reference to the accompanying drawings. Although some embodiments of this embodiment are shown in the drawings, it should be understood that this embodiment can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand this embodiment. It should be understood that the drawings and embodiments of this embodiment are only for exemplary purposes and are not used to limit the protection scope of this embodiment.

[0036] To better understand the embodiments of the present application, the technical terms involved in the embodiments of the present application are explained as follows:

[0037] SQL, short for Structured Query Language, is a structured query language, which is a database query and programming language used to access data and query, update, and manage relational database systems.

[0038] External table mechanism, including two points. One point is to connect to an external data source. The external table query logic first needs to establish a connection with the external data source; the other point is to define query conditions. Before executing an external query, it is necessary to clarify the purpose of the query and the conditions of the required data.

[0039] OLTP, short for Online Transaction Processing, is online transaction processing, which is one of the ways to quickly respond to user operations.

[0040] Database service instance: A database instance used to directly serve customers.

[0041] External database service instance: Used to provide external data services for the database service instance.

[0042] simple query protocol: Simple query protocol, a client-database connection communication protocol,

[0043] extend query protocol: The extended query protocol splits the above-described simple protocol into several steps, and the results of the preparation steps can be reused multiple times to improve efficiency.

[0044] parse: The parsing process is responsible for parsing the SQL statement into a parse tree data structure.

[0045] analyze: The analysis process is responsible for analyzing and validating database objects in the parse tree and generating a query tree.

[0046] 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.

[0047] execute: The plan execution process is responsible for executing the query execution plan to obtain the execution result.

[0048] Figure 1 It is a schematic diagram of the execution path for accessing data across instances in the related art. As Figure 1 shown, the traditional cross-instance data access mainly includes the following execution steps:

[0049] The database service instance receives the SQL sent by the client and sequentially executes parse, analyze, plan, and execute. It performs query optimization on the access SQL in the database service instance and generates an execution plan tree. The access to the external data source in the plan tree is abstracted as SQL, and then the external data source is accessed through SQL during execution;

[0050] The external database service instance receives the SQL sent by the database service instance, sequentially executes parse, analyze, plan, and execute, obtains the data query result, and returns it to the user.

[0051] The disadvantage of traditional cross-instance data access is that when the SQL in the database service instance only accesses the external data source, that is, when the SQL can be fully pushed down to the external data source, the steps of parse, analyze, plan, and execute are all executed in both the local database service instance and the external database service instance. This process has redundant query optimization processes, and there are redundant data packing and unpacking processes when transferring data between the database service instance and the external data source.

[0052] 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 to which the user is connected is to be responsible for data transfer. Especially in the case of repeated execution, improving the transfer efficiency can significantly enhance the efficiency of accessing data across instances. In the technical solution provided in this application, when the SQL can be completely pushed down to the external data source, based on the cache caching technology, the transfer service in the database service instance is upgraded to the routing transfer of data packets, avoiding the execution expansion of the SQL in the database service instance. Instead, the query request is directly routed to the external data source, and the database service instance only receives the results from the external data source and directly routes them to the user side, which can greatly improve its execution efficiency. The following is a detailed description.

[0053] Figure 2 is a flowchart of a method for implementing cross-instance routing of structured query statements according to an embodiment of the present application, as Figure 2 shown, the method includes the following steps:

[0054] Step S202, the first database service instance end receives the structured query statement.

[0055] It should be noted that the first database service instance end is the hardware device running the database service instance.

[0056] Step S204, 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.

[0057] Step S206, in the case where 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.

[0058] The second database service instance end is the hardware device running the external database service instance.

[0059] Figure 3 is a schematic diagram of the execution path for accessing data across instances according to an embodiment of the present application. In the technical solution provided in this application, the execution plan obtained by optimizing the SQL through query in the database service instance, by judging if it can be completely pushed down ( Figure 3 check push in), marks this SQL as a routing SQL in memory ( Figure 3In the (mark asroute), a connection to an external data source is established, the query message is routed to an external database instance, the result from the external database instance is monitored and directly routed to the user, and the external database instance performs parse, analyze, plan, and execute without any intermediate parsing. The database service instance is responsible for receiving messages from the user side and determining whether to process locally or route to the external data instance based on the message type.

[0060] Through the above technical solution, in the database service instance directly connected to the customer, the SQL query statements that can be fully pushed down to the external data source are forwarded to the external database instance through direct routing, achieving the purpose of optimizing redundant and ineffective intermediate operations, realizing statement-level routing, and saving resources in the service instance, thereby achieving the technical effect of improving the efficiency of cross-instance data access.

[0061] 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 detailed designs under the two different protocols are described separately below.

[0062] According to an optional embodiment of the present application, when the user side and the first database service instance side are connected through the simple query protocol, step S204 is executed. The first database service instance side determines whether the structured query statement has the ability to be sent to the second database service instance side, including the following steps: The first database service instance side receives a query message, where the query message carries the structured query statement; the first database service instance side parses the structured query statement into a parse tree data structure; the first database service instance side analyzes and validates the database objects in the parse tree data structure to generate a query tree data structure; the first database service instance side 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 side.

[0063] As an optional embodiment of the present application, the first database service instance side 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 side, which is achieved through the following method: If the first database service instance side does not store the data to be queried by the structured query statement, it is determined that the structured query statement has the ability to be sent to the second database service instance side; if the first database service instance side stores the data 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 side.

[0064] Figure 4aIt is a schematic diagram of the execution path for the client to connect to the database using the simple query protocol. As Figure 4a shown, under the simple query protocol, the client only sends a query message (i.e., the Query message in Figure 4a , hereinafter simply referred to as the Q message) and carries the SQL statement in the message. The database service instance is responsible for receiving the Q message and processing it, that is, performing parse, analyze, plan, execute, and then sending the data row (Data Row) as the return result to the client. It can also be seen from Figure 4a that before the database service instance returns the data row (Data Row) to the client, it first sends a data description message (Row Description) to the client. After sending the data row (Data Row), it also needs to send a command completion message (Command Complete) to the client. When the client receives the Ready For Query message sent by the database instance, the query step ends.

[0065] Figure 4b It is a schematic diagram of the execution path for the client to connect to the database using the simple query protocol to access data across instances in the related art. Under the simple query protocol, the database cannot effectively cache the query optimization results. Therefore, for each execution, the database service instance needs to perform parse, analyze, plan, and execute. In the case of accessing data across instances, the external database service instance also needs to perform 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, be responsible for parsing the data transmitted from the external database service instance according to the execution plan, and then repackage and send it to the client. In the database service instance, the query optimization and execution are the most time-consuming stages, and this redundant operation brings performance loss.

[0066] Figure 4c It is a schematic diagram of the execution path for the client to connect to the database using the simple query protocol to access data across instances according to an embodiment of the present application. As Figure 4c shown, to solve the above technical problems, the technical solution provided by the embodiment of the present application is to analyze the result 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 ( Figure 4c check and push in). If the SQL can be completely sent to the external database service instance, the database service instance enters the routing mode ( Figure 4cIn the enter router mode), select the corresponding external data source connection, and directly route the current Q message to the external data service library service instance for execution, that is, execute parse, analyze, plan, and execute in the external database service instance. At this time, the database service instance of the direct connection client acts as a routing function. Direct routing avoids redundant query optimization and execution in the database service instance, improving the execution efficiency.

[0067] According to an optional embodiment of the present application, step S206 is executed to forward the query statement to the second database service instance for execution, which is implemented by the following method: the first database service instance deletes the query tree data structure and enters the routing mode; after entering the routing mode, the first database service instance forwards the query message to the second database service instance for execution; the first database service instance searches for the port listening to the second database service instance, establishes a connection with the port, and returns the query result received from the second database service instance through the port to the user end, where the query result is queried by the second database service instance according to the structured query statement; in the case of receiving the target message (Ready For Query) from the second database service instance through the port, the first database service instance exits the routing mode.

[0068] Figure 4d It is a program flowchart of a user end connecting to a database using a simple query protocol to access data across instances according to an embodiment of the present application, as Figure 4d shown, and the entire program flow includes the following steps:

[0069] S1, the user end sends a Q message to the database service instance, and the Q message carries SQL;

[0070] S2, after the database receives the Q message, it executes parse and analyze on the SQL to obtain a Query Tree;

[0071] S3, the database service instance analyzes the Query Tree to determine whether the SQL can be pushed down to the external database service instance; if the judgment result is no, execute the SQL in the local database service instance; if the judgment result is yes, clear the Query Tree, enter the routing mode, and search for and establish a connection with the port listening to the external database service instance;

[0072] S4, the database service instance determines whether the message from the external database service instance is "Ready For Query"; if the determination result is no, the query result from the external database service instance is returned to the client; if the determination result is yes, the database service instance exits the routing mode and ends the query process.

[0073] In some alternative embodiments of the present application, when the client is connected to the first database service instance through the extended query protocol, when performing step S204, the first database service instance determines whether the structured query statement has the ability to be sent to the second database service instance, and further includes the following steps: The first database service instance receives a parsing message, where 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 analyzes and validates the database objects in the parse tree data structure to generate a query tree data structure; the 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.

[0074] Figure 5a This is a schematic diagram of the execution path for the client to connect to the database using the extended query protocol. As Figure 5a shown, in order to reduce the need for the database server to repeatedly execute the query optimization process in the simple query protocol, the extended query protocol divides the query process into several steps and reuses the query optimization results multiple times to avoid the repeated query optimization process. It usually includes messages such as Parse, Describe, Bind, and Execute. The Describe statement is used to view the structure information of the table, including column names, data types, constraint information, etc. The Bind message is used to bind the connection relationship between the SQL and the database service instance.

[0075] As Figure 5a shown, the entire execution process includes the following steps:

[0076] The client sends a Parse message to the database service instance, and the SQL is carried in the Parse message. After receiving the Parse message, the database service instance executes parse, analyze, and then sends a Parse Complete instruction to the client. The client sends a Bind message to the database service instance. After receiving the Bind message, the database service instance executes plan and then sends a Bind Complete instruction to the client. The client sends a Describe message to the database service instance. After receiving the Describe message, the database service instance sends a Row Description message to the client. The client sends an Execute message to the database service instance. The database service instance executes execute and returns the query result Data Row to the client. The client sends a Sync synchronization message to the database service instance. After receiving the Sync synchronization message, the database service instance sends a Ready For Query message to the client, and the query process ends.

[0077] Figure 5b It is a schematic diagram of the execution path for the client to connect to the database using the extended query protocol to access data across instances in the related art. Under the extend query protocol, the database service instance inevitably needs to unpack and repack the data of the external database and perform data processing during the execution phase (i.e., execute the steps shown Figure 5a ), and at the same time, the database instance service process needs to cache the entire execution plan, occupying more resources.

[0078] In some other alternative embodiments of the present application, forwarding the query statement to the second database service instance in step S206 includes the following steps: the first database service instance deletes the query tree data structure and enters the routing mode; after entering the routing mode, the first database service instance forwards the parse message to the second database service instance for execution; the first database service instance forwards the unbound message to the second database service instance for execution, and stores the name of the structured query statement bound by the bound message and the association relationship between the structured query statement and the second database service instance; the first database service instance searches for the port listening to the second database service instance, establishes a connection with the port, and returns the query result received from the second database service instance through the port to the client, where the query result is the result queried by the second database service instance according to the structured query statement; in the case of receiving the target message from the second database service instance through the port, the first database service instance exits the routing mode.

[0079] Figure 5cIt is a schematic diagram of the execution path for a client to access data across instances by connecting to a database using an extended query protocol according to an embodiment of the present application. As Figure 5c shown, to solve the above technical problems, the technical solution provided by the embodiment of the present application analyzes the Query Tree after parse and analyze in the database service instance to determine whether the SQL can be fully sent to the external database service instance ( Figure 5c check and push in). If the SQL can be fully 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., execute the steps shown in Figure 5a ). At the same time, the database service instance enters the routing mode ( Figure 5c enter router mode in), clears the QueryTree cached internally, and directly routes the subsequent Bind message 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 search and routing when repeating the execution. At this time, the database service instance directly connected to the client enters the routing mode, and the instance acts as a routing function. After the external data database service instance sends a Ready For Query message after completing the query, the data service instance processes the message and stops the routing function. This solution avoids redundant query optimization and execution in the database service instance through direct routing, improving the execution efficiency.

[0080] As an optional embodiment of the present application, when a binding message is detected, the first database service instance checks locally whether there is a name that is the same as the name of the structured query statement bound to the binding message stored; if there is a name that is the same as the name of the structured query statement bound to the binding message stored at the first database service instance, the first database service instance determines the second database service instance corresponding to the name of the structured query statement according to the association relationship; the first database service instance enters the routing mode, searches for the port listening to the second database service instance, establishes a connection with the port, and returns the query result received from the second database service instance through the port to the client; in the case of receiving a target message through the port, the first database service instance exits the routing mode.

[0081] Figure 5d It is a schematic diagram of the execution path for a client to repeatedly access data across instances by connecting to a database using an extended query protocol according to an embodiment of the present application. As Figure 5d shown, when the client repeats the execution of the SQL, it only needs to resend the Bind message and carry the name of the SQL set during the first BindFigure 5d (Bind with name), the database server checks whether the name recorded during the first execution exists ( Figure 5d (check in), if it exists, find the corresponding externally connected database service instance according to its information, and then enter the routing mode ( Figure 5d (enter routermode in). When the external data database service instance finishes the query and returns "Ready For Query", the database service instance stops the routing mode and resumes normal execution.

[0082] According to another optional embodiment of the present application, when it is determined that the structured query statement does not have the ability to be sent to the second database service instance side, the first database service instance side executes the structured query statement locally.

[0083] In the embodiments of the present application, not all SQLs need to be routed to the external database service instance for execution. For example, some data that needs to be queried by SQL can be queried in the local database service instance. At this time, the SQL does not need to be routed to the external database service instance for execution. Therefore, in the embodiments of the present application, the database service instance is responsible for receiving the user-side message and determining whether to perform local processing or route it to the external database service instance for processing according to the message type.

[0084] The technical solution provided by the embodiments of the present application forwards the query that can be fully pushed down to the external data source to the external database service instance by direct routing in the database service instance directly connected to the client, avoiding redundant query optimization and execution processes in the local database service instance, as well as the processes of unpacking and repackaging required for data transfer. While being compatible with the local query of the directly connected database instance, the efficiency of cross-instance data access is greatly improved.

[0085] It can be understood that the technical solution provided by the present application can be applied to a single-machine database or a distributed database.

[0086] Based on the above method for realizing cross-instance routing of structured query statements provided by the embodiments of the present invention, the embodiments of the present invention further provide a device for realizing cross-instance routing of structured query statements, and the device includes:

[0087] A receiving module 60, configured to receive a structured query statement by the first database service instance side.

[0088] A judging module 62, configured to judge whether the structured query statement has the ability to be sent to the second database service instance side by the first database service instance side.

[0089] A processing module 64, configured to establish a connection with a 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, and forward the structured query statement to the second database service instance for execution.

[0090] The apparatus for implementing cross-instance routing of structured query statements provided by the embodiments of the present invention forwards the SQL query statements that can be fully pushed down to an external data source to an external database instance in a direct routing manner in the database service instance directly connected to the client, achieving the purpose of optimizing the redundant and ineffective operations in the middle, implementing statement-level routing, and saving resources in the service instance, thereby achieving the technical effect of improving the efficiency of cross-instance data access.

[0091] It should be noted that Figure 6 The preferred implementation manners of the illustrated embodiments can be referred to Figure 2 the relevant descriptions of the illustrated embodiments, which will not be elaborated here.

[0092] Figure 7 is a structural block diagram of a system for implementing cross-instance routing of structured query statements according to an embodiment of the present application. As Figure 7 shown, the system includes: a first database service instance end 70 and at least one second database service instance end 72, where

[0093] The first database service instance end 70 is configured to run a database service instance and is set to execute the method for implementing cross-instance routing of structured query statements in any of the above embodiments. Among them, the database service instance is used to directly provide data services for the client; at least one second database service instance end 72 is configured to run an external database service instance, where the external database service instance is used to provide external data services for the database service instance.

[0094] The database service instance end 70 and at least one second database service instance end 72 are both hardware devices running database service instances, including but not limited to computer devices.

[0095] The embodiments of the present invention further provide an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The above memory stores a computer program that can be executed by the at least one processor. When the computer program is executed by the at least one processor, it is used to cause the electronic device to execute the method of the embodiments of the present invention.

[0096] The embodiments of the present invention further provide a non-transitory machine-readable medium storing a computer program, where the computer program is used to cause the computer to execute the method of the embodiments of the present invention when executed by a processor of the computer.

[0097] An embodiment of the present invention also provides a computer program product, including a computer program, where the computer program, when executed by a processor of a computer, is used to cause the computer to execute the method of the embodiment of the present invention.

[0098] Reference Figure 8 , a structural block diagram of an electronic device that can be a server or a client according to an embodiment of the present invention will now be described. It 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 devices, such as, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, a personal digital processor, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are only examples and are not intended to limit the implementation of the present invention described herein and / or claimed.

[0099] As Figure 8 shown, the electronic device includes a computing unit 801, which can execute 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, the ROM 802, and the RAM 803 are connected to each other through a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0100] Multiple components in 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 that can input information into the electronic device. The input unit 806 can receive input digital or character information, and generate key signal inputs related to the user settings and / or function controls of the electronic device. The output unit 807 can be any type of device that can present information, and can 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 can include but is not limited to a magnetic disk, an optical disk. The communication unit 809 allows the electronic device to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and can 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.

[0101] The computing unit 801 can be various general-purpose and / or special-purpose 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 running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 executes the various methods and processes described above. For example, in some embodiments, the method embodiments of the present invention can be implemented as a computer program, which is tangibly contained in a machine-readable medium, such as the storage unit 808. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device via the ROM 802 and / or the communication unit 809. In some embodiments, the computing unit 801 can be configured to execute the above-described method in any other suitable way (e.g., by means of firmware).

[0102] The computer program for implementing the method of the embodiments of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to the processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer programs are executed by the processor or controller, the functions / operations specified in the flowchart and / or block diagram are implemented. The computer program can be executed entirely on the machine, partially on the machine, as an independent software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0103] In the context of the embodiments of the present invention, the machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. The machine-readable signal medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0104] It should be noted that the term "including" and its variants used in the embodiments of the present invention are open-ended, that is, "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The modifications of "one" and "multiple" mentioned in the embodiments of the present invention are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly specified in the context, it should be understood as "one or more".

[0105] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the embodiments of the present invention are all information and data that have been authorized by the user or fully authorized by all parties. And the collection, use, and processing of the relevant data need to comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding operation entrances are provided for the user to choose to authorize or refuse.

[0106] The various steps described in the method implementation manners provided by the embodiments of the present invention can be executed in different orders and / or executed in parallel. In addition, the method implementation manners may include additional steps and / or omit the steps shown. The protection scope of the present invention is not limited in this regard.

[0107] The term "embodiment" in this specification means that the specific features, structures, or characteristics described in combination with the embodiment may be included in at least one embodiment of the present invention. The phrase appears in various positions in the specification does not necessarily mean the same embodiment, nor does it mean being independent or alternative to other embodiments and mutually exclusive. The various embodiments in this specification are described in a related manner, and the same or similar parts between the various embodiments are referred to each other. In particular, for the device, equipment, and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts refer to the partial description of the method embodiments.

[0108] The above-described embodiments only represent several implementation manners of the present invention, and their descriptions are relatively specific and detailed, but should not be construed as a limitation on the scope of patent protection. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present invention, several modifications and improvements can still be made, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the appended claims.

Claims

1. A method for implementing cross-instance routing of structured query statements, characterized in that, it includes: The 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 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, 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, characterized in that, 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 end receives a query message, where the structured query statement is carried in the query message; 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 validates 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.

3. The method according to claim 2, characterized in that, 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 required by the structured query statement for querying, 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 required by the structured query statement for querying, it is determined that the structured query statement does not have the ability to be sent to the second database service instance end.

4. The method according to claim 2, characterized in that, Forwarding the query statement to the second database service instance end for execution includes: The first database service instance end deletes the query tree data structure and enters the 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 finds 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, where the query result is queried by the second database service instance end according to the structured query statement. In the case of a target message received 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 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, wherein the parsing message carries the 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 validates 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.

6. The method according to claim 5, wherein, forwarding the query statement to the second database service instance end for execution includes: The first database service instance end deletes the query tree data structure and enters the 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 by 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 finds 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, wherein the query result is queried by the second database service instance end according to the structured query statement; In the case of a target message received 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 includes: When detecting a binding message, the first database service instance end locally looks up whether there is a name identical to the name of the structured query statement bound by the binding message; If there is a name identical to the name of the structured query statement bound by the binding message stored in 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 according to the association relationship; The first database service instance enters the routing mode, searches for the port listening to the second database service instance, establishes a connection with the port, and returns the query result received from the second database service instance through the port to the user end; When the target message is received through the port, the first database service instance exits the routing mode.

8. The method according to any one of claims 1 to 7, characterized in that, the method further includes: When it is determined that the structured query statement does not have the ability to be sent to the second database service instance, the first database service instance executes the structured query statement locally.

9. An apparatus for realizing cross-instance routing of structured query statements, characterized in that, it includes: a receiving module, configured to receive a structured query statement by the first database service instance; a judging module, configured to judge by the first database service instance whether the structured query statement has the ability to be sent to the second database service instance; a processing module, configured to, when it is determined that the structured query statement has the ability to be sent to the second database service instance, establish a connection between the first database service instance and the second database service instance, and forward the structured query statement to the second database service instance for execution.

10. A system for realizing cross-instance routing of structured query statements, characterized in that, it includes: a first database service instance and at least one second database service instance, wherein, the first database service instance is configured to run a database service instance and is set to execute the method for realizing cross-instance routing of structured query statements according to any one of claims 1 to 8, wherein the database service instance is used to directly provide data services for the client; the at least one second database service instance is configured 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.

11. An electronic device, including: a processor and a memory storing a program, characterized in that the program includes instructions that, when executed by the processor, cause the processor to execute the method for realizing cross-instance routing of structured query statements according to any one of claims 1 to 8.

12. A non-transitory machine-readable medium storing computer instructions, characterized in that, the computer instructions are used to cause the computer to execute the method for realizing cross-instance routing of structured query statements according to any one of claims 1 to 8.