Query method, device, system, electronic device and storage medium

Through the database proxy server, the adaptation communication protocol is used to convert the source query statement as the target query statement during the migration process, the application adaptation problem in database migration is solved, and concise application transformation and performance detection is achieved.

CN116166700BActive Publication Date: 2025-08-26ALIBABA CLOUD COMPUTING CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310127733.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-01
Publication Date
2025-08-26
Estimated Expiration
2043-02-01

AI Technical Summary

Technical Problem

During the database migration process, due to the structured query language (SQL) syntax and semantic differences between the source and target databases, a large number of applications on the application server need to be adapted after migration, including database driver adaptation and syntax differential adaptation.

Method used

Through the database proxy server, the source query statement is obtained using the communication protocol adapted to the target database, converted into the target query statement, and the query result is returned, so that the source application can access the target database without modification.

Benefits of technology

It realizes zero-aware application transformation for heterogeneous database migration, simplifies the application transformation process, and provides double-write verification function to quickly detect performance problems caused by migration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116166700B_ABST
    Figure CN116166700B_ABST
Patent Text Reader

Abstract

The present application provides a query method, device, system, electronic device and storage medium, which relate to the field of database migration technology. The method includes: obtaining a source query statement from a source application based on a first communication protocol, wherein the first communication protocol is adapted to the target database, and the source application is adapted to the source database; determining a target query statement adapted to the target database based on the source query statement; sending a target query statement to the target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result; returning the first query result returned by the target database to the source application based on the first communication protocol. According to the technical solution of the present application, an application proxy service can be provided for the application server to access the target database without any modification to the source application, thereby realizing zero-perception application transformation of heterogeneous database migration, making application transformation more concise and intelligent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database migration technology, and in particular to a query method, device, system, electronic device and storage medium. Background Art

[0002] With the rise of domestic databases and the development of cloud computing, more and more companies are choosing to replace their traditional offline databases with cloud-based ones, necessitating database migration. While database migration technology (including data migration and heterogeneous database structure migration) is highly mature, migrating heterogeneous databases often involves significant differences in the syntax and semantics of Structured Query Language (SQL). This requires extensive adaptation of server-side applications (APPs) after migration, including database driver adaptation and syntax differences. Summary of the Invention

[0003] Embodiments of the present application provide a query method, apparatus, system, electronic device, and storage medium to provide a zero-code application transformation method for database migration.

[0004] In a first aspect, an embodiment of the present application provides a query method, comprising: obtaining a source query statement from a source application based on a first communication protocol, wherein the first communication protocol is adapted to a target database, and the source application is adapted to the source database; determining a target query statement adapted to the target database based on the source query statement; sending the target query statement to the target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result; and returning the first query result returned by the target database to the source application based on the first communication protocol.

[0005] In a second aspect, an embodiment of the present application provides a query device, comprising: a source query statement acquisition module, used to acquire a source query statement from a source application based on a first communication protocol, wherein the first communication protocol is adapted to a target database, and the source application is adapted to the source database; a target query statement determination module, used to determine a target query statement adapted to the target database based on the source query statement; a target query statement sending module, used to send the target query statement to the target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result; a first query result return module, used to return the first query result returned by the target database to the source application based on the first communication protocol.

[0006] In a third aspect, an embodiment of the present application provides a query system, comprising: an application server, on which a source application is installed, the source application being adapted to a source database; a database proxy server, for implementing the method provided in any embodiment of the present application to return a first query result to the source application; a target database, for executing the target query statement returned by the database proxy server to generate a first query result, and returning the first query result to the database proxy server.

[0007] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor implements the method provided in any embodiment of the present application when executing the computer program.

[0008] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the method provided in any embodiment of the present application is implemented.

[0009] Compared with the existing technology, the technical solution of the embodiment of the present application has the following advantages: after completing data migration and structural migration, the source application does not need to make any modifications. It can send database query requests in the same way as before the data migration and structural migration. The database proxy server performs communication protocol adaptation, query statement syntax adaptation, and other processing, thereby providing the application server with an application proxy service to access the target database, thereby achieving zero-perception application transformation for heterogeneous database migration, making application transformation more concise and intelligent. Furthermore, the database proxy server can also provide a dual-write verification scenario, that is, after completing data migration and structural migration, it helps users view performance issues caused by heterogeneous database migration.

[0010] The above summary is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments and features described above, further aspects, embodiments and features of the present application will be readily apparent by reference to the accompanying drawings and the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar components or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments disclosed in this application and should not be construed as limiting the scope of this application.

[0012] Figure 1 A schematic diagram of the system architecture of the query method provided in Example 1 of the present application;

[0013] Figure 2 A flowchart of the query method provided in Example 1 of the present application;

[0014] Figure 3 This is an example diagram of the query method provided in Example 1 of the present application;

[0015] Figure 4 A flowchart of the query method provided in Example 2 of this application;

[0016] Figure 5 This is an example diagram of dual-write verification provided in Example 2 of this application;

[0017] Figure 6 This is an example diagram of dual-write verification provided in Example 2 of this application;

[0018] Figure 7 This is an example diagram of the application of the query method provided in Example 2 of this application;

[0019] Figure 8 A block diagram of a query device provided in Example 3 of the present application;

[0020] Figure 9 This is a block diagram of the electronic device provided in Example 3 of the present application. DETAILED DESCRIPTION

[0021] Hereinafter, only certain exemplary embodiments are briefly described. As will be appreciated by those skilled in the art, the described embodiments may be modified in various ways without departing from the spirit or scope of the present application. Therefore, the drawings and description are to be regarded as illustrative in nature and not restrictive.

[0022] To facilitate understanding of the technical solutions of the embodiments of the present application, the relevant technologies of the embodiments of the present application are described below. The following relevant technologies can be arbitrarily combined with the technical solutions of the embodiments of the present application as optional solutions, and they all fall within the protection scope of the embodiments of the present application.

[0023] The following terms are used in this article

[0024] Database migration: Any form of data movement from a source database to a target database, including data migration and heterogeneous database structure migration.

[0025] Heterogeneous database migration: The source and target databases for database migration are of different types and structures.

[0026] Source database: In a database migration scenario, the database to be migrated is called the source database.

[0027] Target database: In a database migration scenario, the database to which data is migrated is called the target database.

[0028] Source Application: An application (APP) installed on an application server allows the application server to access the database. In database migration scenarios, this application must be compatible with the source database. This means that the application's communication protocol, driver, and SQL syntax and semantics are compatible with the source database. Therefore, in database migration scenarios, the application installed on the application server is called the source application and is used to access the source database. Through application transformation, the application server can access the target database based on the source application.

[0029] Application transformation: This refers to application modification. When migrating heterogeneous databases, there are significant differences in the Structured Query Language (SQL) syntax and database drivers between the source and target databases. Therefore, after data and structure migration, the source application on the application server needs to be modified. This includes adapting the database driver and syntax differences, so that the application server can successfully access the target database through the source application installed on it.

[0030] Database proxy: Provides network proxy services between the database and the application server, and is used to proxy all requests when the application server accesses the database.

[0031] System and application scenarios

[0032] Figure 1 The following is an architectural diagram of a query system according to an embodiment of the present application. Figure 1 As shown, the system may include an application server 101 , a database proxy server 102 and a target database 103 .

[0033] The application server 101 is used to provide application services for accessing the database. The application server 101 can be deployed on a physical server including an independent host, or on a virtual server (such as a cloud server) hosted by a host cluster, which is not limited in this embodiment of the present application.

[0034] An application is installed on the application server 101, which is used to send requests to the database and return the request results to the user. In the database migration scenario, the system also includes a source database 104. The application installed on the application server 101 is adapted to the source database 104, that is, the communication protocol, driver, and SQL syntax semantics of the application are adapted to the source database 103. Therefore, the application installed on the application server 101 can also be called a source application. After the data migration and structure migration are completed, there may be incompatibility between the target database 103 and the source application on the application server 101, such as the database driver of the source application cannot adapt to the target database 103, or the SQL syntax in the query request sent by the source application is incompatible with the target database 103, which may result in the application server 101 being unable to access the target database 103 based on the source application.

[0035] The database proxy server 102 can be deployed on a physical server including an independent host, or on a virtual server (such as a cloud server) carried by a host cluster, and the embodiment of the present application does not limit this.

[0036] The database proxy server 102 is located between the database (including the source database 104 and the target database 103) and the application server 101, and is used to execute the query method provided in the embodiment of the present application, including: based on a first communication protocol adapted to the target database, obtaining a source query statement from the source application, and determining a target query statement adapted to the target database based on the source query statement, further, sending the target query statement to the target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result, and returning the first query result returned by the target database to the source application.

[0037] Therefore, in the database migration scenario, the database proxy server 102 acts as the middleware between the application server 101 and the target database 103. It can provide the application proxy service for the application server 101 to access the target database 103 without making any modifications to the source application, thereby achieving zero-perception application transformation of heterogeneous database migration, making application transformation simpler and smarter.

[0038] Example 1

[0039] Figure 2 A flowchart of a query method according to an embodiment of the present application is shown. The query method can be applied to the database proxy server 102. For example, the database proxy server 102 can execute the method of the embodiment of the present application by starting a process or instance.

[0040] like Figure 2 As shown, the query method includes:

[0041] Step S201: obtaining a source query statement from a source application based on a first communication protocol, wherein the first communication protocol is adapted to the target database, and the source application is adapted to the source database.

[0042] As mentioned above, in the database migration scenario, the source application is adapted to the source database, for example, the communication protocol, driver, and SQL syntax and semantics of the source application are adapted to the source database.

[0043] Furthermore, the first communication protocol is adapted to the target database, thereby enabling normal communication with the target database. In other words, the first communication protocol can be determined according to the type of the target database. For example, if the target database is the relational database MySQL, the first communication protocol can be the MySQL network protocol; or if the target database is the open source relational database PostgreSQL, the first communication protocol can be the PostgreSQL network protocol (referred to as the PG protocol). The embodiment of the present application does not limit the type of the first communication protocol, as long as the first communication protocol is adapted to the target database.

[0044] In a database migration scenario, after completing data and structure migration, the source application can remain unchanged and continue to send query requests in the same manner as accessing the source database. The database proxy server can communicate with the source application and parse the query request sent by the source application based on the first communication protocol to obtain the source query statement, such as the source SQL statement.

[0045] Step S202: Determine a target query statement that is compatible with the target database based on the source query statement.

[0046] It should be noted that since the source application is adapted to the source database and has not been modified, the source query statement obtained based on the source application is compatible with the source database, but the source query statement may not be compatible with the target database.

[0047] For example, if the source query statement is compatible with the target database, the database proxy server can directly use the source query statement as the target query statement and forward it to the target database, which is equivalent to copying the source query statement and forwarding it to the target database. If the source query statement is incompatible with the target database, the database proxy server converts the source query statement to obtain the target query statement and then forwards the target query statement to the target database.

[0048] Step S203: sending a target query statement to a target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result.

[0049] Since the first communication protocol and the target query statement are both adapted or compatible with the target database, the target database executes the target query statement after receiving it from the database proxy server, and returns the first query result generated after executing the target query statement to the database proxy server.

[0050] Step S204: Based on the first communication protocol, the first query result returned by the target database is returned to the source application.

[0051] That is, the database proxy server sends the first query result received from the target database to the source application, so that the source application can obtain the query result returned by the target database based on its own query request without making any modifications.

[0052] According to the technical solution of the embodiment of the present application, after completing the data migration and structure migration, the source application does not need to make any modifications. It can send a database query request in the same way as before the data migration and structure migration, and the database proxy server performs communication protocol adaptation, query statement syntax adaptation and other processing, thereby providing the source application with an application proxy service to access the target database, thereby realizing zero-perception application transformation of heterogeneous database migration, making application transformation more concise and intelligent.

[0053] In one embodiment, in step S201, obtaining a source query statement from a source application based on a first communication protocol may include: obtaining a first query request from the source application based on the first communication protocol; and parsing the first query request according to the first communication protocol to obtain a source query statement.

[0054] In an embodiment of the present application, the first communication protocol is adapted to the target database, i.e., the first communication protocol is a database network protocol, such as the MySQL network protocol or the PostgreSQL network protocol. A network protocol is a set of conventions that must be followed by both communicating parties, and includes three elements: syntax, semantics, and timing. Syntax specifies the organizational structure of data and information; semantics defines the information content of data transmission and controls the execution and response methods of information; and timing specifies the order in which data and information are sent. Database network protocols generally include rules for messages, handshakes, and queries.

[0055] Therefore, based on the rules agreed upon in the first communication protocol, the database proxy server can obtain the first query request from the source application, and based on the rules agreed upon in the first communication protocol, parse the first query request to obtain the source query statement, and further based on the rules agreed upon in the first communication protocol, send the first query result corresponding to the first query request returned by the target database to the source application.

[0056] It should be noted that, by parsing the first query request, in addition to obtaining the source query statement, such as the source SQL, corresponding request parameter information, such as variable parameters such as an identifier and a query position, can also be obtained.

[0057] For example, Figure 3 As shown, the database proxy server provides a socket (SOCKET) to provide an interface for the database proxy server to communicate interactively with the source application (APP) using the first communication protocol. Furthermore, the database proxy server can establish a connection with the target database through the first communication protocol data stream (stream), and then send the target query statement to the target database in the form of the first communication protocol data stream, and receive the first query result returned by the target database through the first communication protocol data stream. Taking the target database as a PostgreSQL database and the first communication protocol as the PostgreSQL network protocol as an example, the database proxy server can establish a connection with the target database through the PG stream (Postgre Stream), and then send the target query statement to the target database, and receive the first query result returned by the target database through the PG stream.

[0058] Based on this, after completing the data migration and structure migration, the source application does not need to make any modifications. It can send the first query request in the same way as before the data migration and structure migration, and the database proxy server will perform the communication protocol adaptation processing to realize the communication between the source application and the target database.

[0059] In one embodiment, in step S202, determining a target query statement compatible with the target database based on the source query statement may include: using the source query statement as the target query statement if the target database is compatible with the source query statement; or parsing the source query statement and converting the source query statement into a target query statement if the target database is not compatible with the source query statement.

[0060] For example, for the source query statement, the database proxy server can first perform a compatibility check, that is, check whether the source query statement is compatible with the target database, such as whether the syntax of the source SQL is compatible with the target database; then, based on the check result, determine whether the source query statement needs to be converted. Figure 3 As shown, if the source query statement (e.g., source SQL) is compatible with the target database, for example, if the syntax of the source query statement and the target database is the same, the database proxy server can directly forward the source query statement as the target query statement to the target database, which is equivalent to copying the source query statement and forwarding it to the target database. If the source query statement is incompatible with the target database, the database proxy server converts the source query statement to obtain the target query statement and then forwards the target query statement to the target database.

[0061] Based on this, for source query statements with the same syntax as the target database, syntax conversion is not repeated, thereby improving the conversion efficiency of the query statements.

[0062] For example, Figure 3 As shown, conversion efficiency can be further improved based on a secondary cache, including caching source query statements (such as source SQL) obtained through protocol parsing and formatting the source query statements for caching. Protocol parsing can be understood as: obtaining a first query request from a source application based on a first communication protocol; parsing the first query request according to the first communication protocol to obtain the source query statement.

[0063] In one embodiment, parsing a source query statement and converting the source query statement into a target query statement may include: performing grammatical parsing on the source query statement to obtain a corresponding abstract syntax tree; performing semantic analysis on the source query statement based on the abstract syntax tree to obtain an abstract syntax tree with semantic tags; and converting the source query statement into a target query statement based on the abstract syntax tree with semantic tags.

[0064] That is, the database proxy server uses a unique query statement (such as SQL) parser to build an abstract syntax tree in real time, and performs syntax conversion based on syntax parsing and semantic parsing to convert the originally incompatible source query statements into target query statements that can be executed by the target database.

[0065] Based on this, after completing the data migration and structure migration, the source application does not need to be modified. The database proxy server performs the query statement syntax adaptation processing to enable the source application to access the target database normally.

[0066] In one embodiment, parsing the source query statement and converting the source query statement into the target query statement may include: converting the source query statement into the target query statement according to a configured conversion rule.

[0067] That is, the database proxy server has a built-in manual customization function, and users can manually and dynamically configure custom conversion rules for query statements to make syntax conversion more flexible.

[0068] For example, Figure 3As shown, the database proxy server can provide query statement mapping services, such as automatically capturing SQL statements on the target database side that do not conform to the target database's syntax specifications, i.e., incorrect SQL statements, and automatically completing SQL intelligent syntax conversion (mapping incorrect SQL statements into correct SQL statements). If there is SQL statement that cannot be intelligently converted, it can also be converted by manually configuring custom conversion rules to prevent incorrect SQL statements from affecting the return of correct query results. Furthermore, the target query statement after syntax conversion is reconstructed through the protocol, such as performing message format conversion based on the first communication protocol, and then forwarded to the target database via the first communication protocol data stream.

[0069] Through the technical solution provided in the embodiments of the present application, more than 99% of SQL can be automatically forwarded for heterogeneous database migration scenarios.

[0070] Example 2

[0071] The present embodiment provides a query method that can be applied to a database proxy server 102. For example, the database proxy server 102 can execute the method of the present embodiment by starting a process or instance. The technical solution in the first embodiment can be partially or fully incorporated into the present embodiment.

[0072] like Figure 4 As shown, the query method may include:

[0073] Step S401: obtaining a source query statement from a source application based on a first communication protocol, wherein the first communication protocol is adapted to the target database, and the source application is adapted to the source database;

[0074] Step S402: Determine a target query statement that is compatible with the target database based on the source query statement;

[0075] Step S403: sending a target query statement to a target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result;

[0076] Step S404: sending a source query statement to the source database based on the second communication protocol, so that the source database executes the source query statement and generates a query result, wherein the second communication protocol is adapted to the source database;

[0077] Step S405: using the conversion rules between the first communication protocol and the second communication protocol, parsing the query result returned by the source database to obtain a second query result;

[0078] Step S406: Compare and verify the first query result and the second query result.

[0079] Among them, step S401 can adopt the same or similar implementation as step S201, step S402 can adopt the same or similar implementation as step S202, and step S403 can adopt the same or similar implementation as step S203. In addition, the execution order of step S403 and steps S404 to S405 is not limited in this embodiment of the application. For example: step S403 can be executed first, and then steps S404 to S405; or, steps S404 to S405 and step S403 can be executed first, and then step S403; or, step S403 and steps S404 to S405 can be executed in parallel.

[0080] Furthermore, the second communication protocol is adapted to the source database. Thus, the database proxy server can also provide proxy services for source applications to access the source database. After receiving the source query statement (e.g., source SQL), the source database executes the source query statement and returns the generated query result to the database proxy server. The database proxy server uses the conversion rules between the first communication protocol and the second communication protocol to parse the query result returned by the source database, obtain a second query result, and verify the first query result by comparing the first query result with the second query result.

[0081] It should be noted that, according to user needs, the database proxy server can return the query results returned by the source database to the source application, and this embodiment of the present application does not limit this.

[0082] According to the technical solution of the embodiment of the present application, the database proxy server can use a double-write verification scenario, that is, through communication protocol conversion, send the source query statement to the source database, and use the source database to execute the source query statement to generate a query result, verify the query result (first query result) returned by the target database, and then verify the performance of the application transformation, that is, after completing the data migration and structure migration and without any modification to the source application, verify the performance of the application proxy service provided by the database proxy server to quickly help users view the performance problems caused by heterogeneous database migration.

[0083] In one embodiment, in step S404, sending a source query statement to a source database based on a second communication protocol may include: utilizing conversion rules between the first communication protocol and the second communication protocol to convert the source query statement into a second query request executable by a database interface; and sending the second query request to the source database by simulating a database interface, so that the source database parses the second query request based on the second communication protocol to obtain the source query statement.

[0084] The database interface is compatible with the source application, i.e., the simulated database interface can simulate the driver of the source application. For example, if the source application is a Java application, the data interface can be a Java Database Connectivity (JDBC) interface; if the source application is a C / C# application, the data interface can be an Open Database Connectivity (ODBC) interface.

[0085] By simulating the database interface, the database proxy server can simulate the driver of the source application accessing the source database, thereby providing proxy services for the source application to access the source database. It can then verify the query results of the target database based on the query results of the source database and test the performance of the application transformation.

[0086] For example, Figure 5 As shown, through protocol parsing, such as executing step S201 or step S401, the source query statement is obtained. Since the first communication protocol is incompatible with the source database, it is necessary to convert the source query statement through protocol, that is, using the conversion rules between the first communication protocol and the second communication protocol, to convert the source query statement into a second query request executable by the simulated database interface, such as JDBC executable SQL, and then send it to the source database through the data interface (such as JDBC), so that the source database parses the second query request based on the second communication protocol to obtain the source query statement, and generates a query result and returns it to the database interface. The database interface (such as JDBC) parses the query result returned by the source database (parsing result), and reconstructs the parsing result to obtain a second query result, and then the second query result has the same format as the first query result, which is convenient for comparison and verification. Among them, Figure 3 The same parts have been introduced in the first embodiment and will not be repeated here.

[0087] The following combination Figure 6 and Figure 7 An application example of the dual write verification scenario provided by the embodiment of the present application is given. In this application example, the source database is a relational database MySQL database, and the target database is a relational database PostgreSQL database. Figure 6 and Figure 7As shown, the database proxy server obtains the source query statement MySQL based on the communication with the source application. Since the source query statement MySQL is incompatible with the target database PostgreSQL database, the database proxy server needs to perform syntax conversion, that is, SQL conversion, to convert the source query statement MySQL into the target query statement PostgreSQL, and forward it to the target database PostgreSQL database. The query result corresponding to the target database PostgreSQL is the first query result. Furthermore, according to the conversion rules between the first communication protocol PG protocol and the second communication protocol MySQL network protocol, protocol conversion is performed to convert the source query statement MySQL into a query statement executable by the simulated database interface JDBC, and forward it to the source database MySQL database through JDBC. The query result corresponding to the source database MySQL database is the first query result. Then, by comparing and verifying the first query result and the second query result, the performance of the application proxy service of the database proxy server is tested.

[0088] It should be noted that the conversion efficiency can be further improved based on the secondary cache (Statement cache), including caching the source query statements (such as source SQL) obtained through protocol analysis and caching the source query statements formatted, that is, Figure 7 SQL caching in the SQL conversion process. Furthermore, during the SQL conversion process, when the source query statement is incompatible with the target query statement, interactive corrections can be made using configured rules, and these rules can be modified by the user (rule modification). Furthermore, information recorded during the service process is captured, allowing users to view the service conversion content in real time. Furthermore, the database proxy server can also provide stress testing services, such as evaluating the impact of database interfaces and hardware performance on the service during the application of proxy services.

[0089] According to the technical solutions of Examples 1 and 2 of the present application, a database proxy server is provided as an application proxy between the application server and the database, providing communication protocol adaptation and syntax adaptation, thereby achieving compatibility of the source application with the target database without modifying the source application of the application server, and enabling the application server to access the target database normally, helping to quickly resolve zero-code application transformation for database migration.

[0090] Example 3

[0091] Corresponding to the method provided in the embodiment of the present application, the embodiment of the present application further provides a query device, which can be deployed on the database proxy server 102.

[0092] like Figure 8As shown, the query device may include: a source query statement acquisition module 801, used to acquire a source query statement from a source application based on a first communication protocol, wherein the first communication protocol is adapted to the target database, and the source application is adapted to the source database; a target query statement determination module 802, used to determine a target query statement adapted to the target database based on the source query statement; a target query statement sending module 803, used to send the target query statement to the target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result; a first query result returning module 804, used to return the first query result returned by the target database to the source application based on the first communication protocol.

[0093] In one embodiment, the target query statement determination module 802 is specifically used to: when the target database is compatible with the source query statement, use the source query statement as the target query statement; or, when the target database is not compatible with the source query statement, parse the source query statement and convert the source query statement into the target query statement.

[0094] In one embodiment, the target query statement determination module 802 is specifically used to: perform grammatical parsing on the source query statement to obtain a corresponding abstract syntax tree; perform semantic analysis on the source query statement based on the abstract syntax tree to obtain an abstract syntax tree with semantic tags; and convert the source query statement into the target query statement based on the abstract syntax tree with semantic tags.

[0095] In one embodiment, the target query statement determining module 802 is specifically configured to convert the source query statement into the target query statement according to a configured conversion rule.

[0096] In one embodiment, the source query statement acquisition module 801 is specifically configured to: acquire a first query request from the source application based on the first communication protocol; and parse the first query request according to the first communication protocol to obtain the source query statement.

[0097] In one embodiment, the query device of the embodiment of the present application also includes: a source query statement sending module, used to send the source query statement to the source database based on a second communication protocol, so that the source database executes the source query statement to generate a query result, wherein the second communication protocol is adapted to the source database; a second query result determination module, used to use the conversion rules between the first communication protocol and the second communication protocol to parse the query result returned by the source database to obtain a second query result; a comparison and verification module, used to compare and verify the first query result and the second query result.

[0098] In one embodiment, the source query statement sending module is specifically used to: utilize the conversion rules between the first communication protocol and the second communication protocol to convert the source query statement into a second query request executable by a database interface, wherein the database interface is adapted to the source application; and send the second query request to the source database by simulating the database interface, so that the source database parses the second query request based on the second communication protocol to obtain the source query statement.

[0099] The functions of each module in each device in the embodiments of the present application can be found in the corresponding description in the above method, and have corresponding beneficial effects, which will not be repeated here.

[0100] It should be noted that the user information (including but not limited to user device information, user personal information, user operation information, etc.) and data (including but not limited to data used for processing, analysis, storage, display, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant information and 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.

[0101] Figure 9 FIG. 1 is a block diagram of an electronic device for implementing an embodiment of the present application. Figure 9 As shown, the electronic device includes: a memory 901 and a processor 902. The memory 901 stores a computer program that can be run on the processor 902. When the processor 902 executes the computer program, the method in the above embodiment is implemented. The number of the memory 901 and the processor 902 can be one or more.

[0102] The electronic device further includes a communication interface 903 for communicating with external devices and performing data exchange transmission.

[0103] If the memory 901, processor 902, and communication interface 903 are implemented independently, the memory 901, processor 902, and communication interface 903 can be connected to each other via a bus and communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 9Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.

[0104] Optionally, in a specific implementation, if the memory 901 , the processor 902 , and the communication interface 903 are integrated on a chip, the memory 901 , the processor 902 , and the communication interface 903 may communicate with each other through an internal interface.

[0105] An embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method provided in any embodiment of the present application.

[0106] An embodiment of the present application also provides a chip, which includes a processor for calling and executing instructions stored in the memory from the memory, so that a communication device equipped with the chip executes the method provided in any embodiment of the present application.

[0107] An embodiment of the present application also provides a chip, including: an input interface, an output interface, a processor and a memory. The input interface, the output interface, the processor and the memory are connected through an internal connection path. The processor is used to execute the code in the memory. When the code is executed, the processor is used to execute the method provided in any embodiment of the application.

[0108] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. It is worth noting that the processor may be a processor that supports the Advanced RISC Machines (ARM) architecture.

[0109] Optionally, the above-mentioned memory may include read-only memory and random access memory, and may also include non-volatile random access memory. The memory may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Among them, the non-volatile memory may include read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM) or flash memory. The volatile memory may include random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available. For example: Static RAM (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced SDRAM (ESDRAM), Sync Link DRAM (SLDRAM) and Direct Rambus RAM (DRRAM).

[0110] In the above embodiments, all or part of the embodiments may be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another.

[0111] In the description of this specification, the reference terms "one embodiment," "some embodiments," "example," "specific example," or "some examples" mean that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. Moreover, the specific features, structures, materials, or characteristics described may be combined in any appropriate manner in any one or more embodiments or examples. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification, as well as features of different embodiments or examples, unless they are mutually inconsistent.

[0112] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. Throughout the description of this application, "plurality" means two or more, unless otherwise specifically defined.

[0113] Any process or method description in a flow chart or otherwise described herein can be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a specific logical function or process. The scope of the preferred embodiments of the present application includes additional implementations in which the functions may be performed in a different order than shown or discussed, including in a substantially simultaneous manner or in a reverse order depending on the functions involved.

[0114] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, apparatus or device (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, apparatus or device and execute instructions), or used in conjunction with such instruction execution systems, apparatuses or devices.

[0115] It should be understood that various parts of the present application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the above embodiment method can be completed by instructing the relevant hardware through a program, which can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.

[0116] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing module, or each unit may exist physically separately, or two or more units may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or in the form of software functional modules. If the aforementioned integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may also be stored in a computer-readable storage medium. The storage medium may be a read-only memory, a magnetic disk, or an optical disk, etc.

[0117] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various modifications or substitutions within the technical scope disclosed in this application, and such modifications or substitutions should be included within the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A query method, applied to a database proxy server, comprising: A source query statement is obtained from a source application based on a first communication protocol, the first communication protocol being adapted to a target database, and the source application being adapted to a source database. After completing data migration and structure migration, the source application can send a first query request in the same manner as before the data migration and structure migration, and the database proxy server performs first communication protocol adaptation processing on the first query request to obtain the source query statement. The database proxy server obtains a cache of the source query statement through parsing the first communication protocol and formats the cache of the source query statement based on a secondary cache method. Determining a target query statement adapted to the target database according to the source query statement; sending the target query statement to the target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result; Returning, based on the first communication protocol, a first query result returned by the target database to the source application; Also includes: sending the source query statement to the source database based on a second communication protocol, so that the source database executes the source query statement and generates a query result, wherein the second communication protocol is adapted to the source database; parsing the query result returned by the source database using a conversion rule between the first communication protocol and the second communication protocol to obtain a second query result; and comparing and verifying the first query result and the second query result; The sending of the source query statement to the source database based on the second communication protocol includes: The source query statement is converted into a second query request executable by a database interface using conversion rules between the first communication protocol and the second communication protocol, wherein the database interface is adapted to the source application; the second query request is sent to the source database by simulating the database interface, so that the source database parses the second query request based on the second communication protocol to obtain the source query statement.

2. The method according to claim 1, wherein Determining, based on the source query statement, a target query statement adapted to the target database, including: If the target database is compatible with the source query statement, use the source query statement as the target query statement; or In the case that the target database is not compatible with the source query statement, the source query statement is parsed and converted into the target query statement.

3. The method according to claim 2, wherein: Parsing the source query statement and converting the source query statement into the target query statement includes: Parsing the source query statement to obtain a corresponding abstract syntax tree; Performing semantic analysis on the source query statement based on the abstract syntax tree to obtain an abstract syntax tree with semantic tags; The source query statement is converted into the target query statement according to the abstract syntax tree with semantic tags.

4. The method according to claim 2, wherein: Converting the source query statement into the target query statement includes: The source query statement is converted into the target query statement according to the configured conversion rule.

5. The method according to claim 1, wherein Obtaining a source query statement from a source application on an application server based on a first communication protocol includes: Obtaining a first query request from the source application based on the first communication protocol; The first query request is parsed according to the first communication protocol to obtain the source query statement.

6. A query device, applied to a database proxy server, comprising: A source query statement acquisition module is used to obtain a source query statement from a source application based on a first communication protocol, wherein the first communication protocol is adapted to the target database, and the source application is adapted to the source database. After completing data migration and structure migration, the source application can send a first query request in the same manner as before the data migration and structure migration, and the database proxy server performs first communication protocol adaptation processing on the first query request to obtain the source query statement; wherein the database proxy server obtains a cache of the source query statement through the first communication protocol parsing based on a secondary cache method and formats the cache of the source query statement; A target query statement determination module, configured to determine a target query statement adapted to the target database based on the source query statement; a target query statement sending module, configured to send the target query statement to the target database based on the first communication protocol, so that the target database executes the target query statement to generate a first query result; A first query result returning module, configured to return the first query result returned by the target database to the source application based on the first communication protocol; The system further includes: a source query statement sending module, configured to send the source query statement to the source database based on a second communication protocol, so that the source database executes the source query statement to generate a query result, wherein the second communication protocol is adapted to the source database; a second query result determining module, configured to parse the query result returned by the source database using a conversion rule between the first communication protocol and the second communication protocol to obtain a second query result; and a comparison and verification module, configured to compare and verify the first query result and the second query result; The source query statement sending module is specifically used to: use the conversion rules between the first communication protocol and the second communication protocol to convert the source query statement into a second query request executable by a database interface, wherein the database interface is adapted to the source application; and send the second query request to the source database by simulating the database interface, so that the source database parses the second query request based on the second communication protocol to obtain the source query statement.

7. A query system comprising: An application server is installed with a source application, wherein the source application is adapted to the source database; A database proxy server, configured to implement the method according to any one of claims 1 to 5, so as to return a first query result to the source application; The target database executes the target query statement returned by the database proxy server to generate the first query result, and returns the first query result to the database proxy server.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory, wherein the processor implements the method according to any one of claims 1 to 5 when executing the computer program.

9. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Query method, apparatus, device and system of heterogeneous database, and medium

    CN110633292A

  • Language conversion method and device of database, electronic equipment and storage medium

    CN111061757A