Search

EP-3989064-B1 - DISTRIBUTED DATABASE PREPROCESSING METHOD, AGENT LAYER, SYSTEM AND STORAGE MEDIUM

EP3989064B1EP 3989064 B1EP3989064 B1EP 3989064B1EP-3989064-B1

Inventors

  • ZHANG, JUN

Dates

Publication Date
20260506
Application Date
20200713

Claims (10)

  1. A distributed database preprocessing method, applied to a database proxy layer, the distributed database preprocessing method comprising: receiving (S101) a request corresponding to a prepared statement; and performing processing (S102) according to the request corresponding to the prepared statement and a session identifier cached in a prepared statement cache library, wherein a session corresponding to the session identifier cached in the prepared statement cache library is a prepared statement session where a connection is successfully established between a client and a database; characterized in that , in response to the received request corresponding to the prepared statement being a prepare request, performing processing (S102) according to the request corresponding to the prepared statement and a session identifier cached in a prepared statement cache library comprises: in response to a session identifier corresponding to a current prepare request session being found in the prepared statement cache library, sending a response message of the prepare request to the client; and in response to the session identifier corresponding to the current prepare request session being not found in the prepared statement cache library, sending the prepare request to the database, and performing, by the database, processing and sending the response message of the prepare request to the client.
  2. The distributed database preprocessing method of claim 1, wherein after sending the prepare request to the database, and performing, by the database, processing and sending the response message of the prepare request to the client, the method further comprises: caching the session identifier corresponding to the current prepare request session into the prepared statement cache library.
  3. The distributed database preprocessing method of any one of claims 1 to 2, wherein, in response to the received request corresponding to the prepared statement being an execute request, performing processing (S102) according to the request corresponding to the prepared statement and a session identifier cached in a prepared statement cache library comprises: in response to a session identifier corresponding to an idle prepare request session being found in the prepared statement cache library, sending the execute request to the database, and performing, by the database, processing and sending a response message of the execute request to the client; and in response to the session identifier corresponding to the idle prepare request session being not found in the prepared statement cache library, waiting until an idle prepare request session is available, sending the execute request to the database, and performing, by the database, processing and sending the response message of the execute request to the client.
  4. The distributed database preprocessing method of claim 3, wherein performing, by the database, processing and sending the response message of the execute request to the client comprises: receiving a result set or failure message generated after execution of the execute request by the database, and sending the result set or failure message to the client.
  5. The distributed database preprocessing method of claim 4, wherein after sending the result set or failure message to the client, the method further comprises: in response to the received request corresponding to the prepared statement being a deallocate request, processing and sending a response message of the deallocate request to the client.
  6. The distributed database preprocessing method of claim 5, wherein processing and sending a response message of the deallocate request to the client comprises: deallocating a session corresponding to the prepared statement currently established with the client, and sending the response message of the deallocate request to the client.
  7. A database proxy layer apparatus, comprising a receiving module (301) and a processing module (302), the receiving module (301) being configured to receive a request corresponding to a prepared statement; and the processing module (302) being configured to perform processing according to the request corresponding to the prepared statement and a session identifier cached in a prepared statement cache library, wherein a session corresponding to the session identifier cached in the prepared statement cache library is a prepared statement session where a connection is successfully established between a client and a database; characterized in that , the processing module (302) is configured to: in response to a session identifier corresponding to a current prepare request session being found in the prepared statement cache library, send a response message of the prepare request to the client; and in response to the session identifier corresponding to the current prepare request session being not found in the prepared statement cache library, send the prepare request to the database, and perform, by the database, processing and send the response message of the prepare request to the client.
  8. The database proxy layer apparatus of claim 7, further comprising a cache module (303) configured to: cache the session identifier corresponding to the current prepare request session into the prepared statement cache library after the processing module (302) sends the prepare request to the database and the database performs processing and sends the response message of the prepare request to the client.
  9. The database proxy layer apparatus of claim 8, wherein the processing module (302) is configured to: in response to a session identifier corresponding to an idle prepare request session being found in the prepared statement cache library, send the execute request to the database, and perform, by the database, processing and send a response message of the execute request to the client; and in response to the session identifier corresponding to the idle prepare request session being not found in the prepared statement cache library, wait until an idle prepare request session is available, send the execute request to the database, and perform, by the database, processing and send the response message of the execute request to the client.
  10. A storage medium, storing one or more programs which, when executed by one or more processors, cause the one or more processors to perform the distributed database preprocessing method of any one of claims 1 to 6.

Description

TECHNICAL FIELD The present disclosure relates to the field of database technologies, and more particularly, to a distributed database preprocessing method, a database proxy layer, a system and a storage medium. BACKGROUND A prepared statement is a general term for prepare, execute, and deallocate statements, which is similar to a storage process and is a collection of SQL statements running in the background. Compared with a just-in-time SQL statement, the prepared statement divides an SQL statement into two parts, of which a first part is the same command and structure part, and the second part is a variable data part that follows. During execution of the SQL statement, firstly, the same command and structure part is sent to a database (values in the SQL statement are replaced by placeholders, which may be regarded as templatization or parameterization of the SQL statement), and the database performs preprocessing (including lexical semantic parsing, statement optimization, planning execution, etc.) once in advance. Then, only parameter data is sent when a prepared statement is executed. Advantages of prepared statements can be summarized as: one preprocessing, multiple runs, which eliminates parsing and optimization processes. In addition, the prepared statement can prevent SQL injection. US20070136311A1 relates to a system, which automatically maintains a plurality of client connections associated with a plurality of clients, the plurality of client connections including active and idle connections. A first server receives a request from a client of the plurality of clients to access a second server of a plurality of second servers communicatively coupled to the first server, the plurality of second servers having varying communication protocols. The first server then identifies a first communication protocol associated with the second server and activating a link between the first server and the second server using the first communication protocol. WO2016091068A1 relates to a method and device for executing a special instruction. The method comprises: middleware connecting a database and a client, the middleware sending a special instruction, and recording relevant information corresponding to the special instruction; and when receiving a matching instruction of the special instruction, sending the matching instruction to the database to be executed in a pre-set sending mode corresponding to the relevant information. Due to the fact that the database can correctly identify the matching instruction sent in the pre-set sending mode corresponding to the relevant information, the database can also correctly execute the matching instruction. US20030220941A1 relates to an apparatus, program product and method, which dynamically optimize prepared statements resident in a statement pool to permit subsequent reuses of such statements to utilize the optimized representations of such statements. The optimization of pooled statements may be performed responsive to the tracked usage of the statements in a statement pool, to direct the overhead associated with such optimization to those statements that are more likely to be utilized in the future. Among a multitude of possible optimizations, a pooled statement that requests data in a format other than that utilized by the database being accessed may be modified to request the data in the format used by the database, thereby decreasing the overhead in the database associated with format conversions. Distributed databases currently support preprocessing, but each prepared statement is sent to an underlying database and a current session is maintained. The session will not be deallocated until the preprocessing ends. Therefore, a lot of resources are be consumed, and frequent delivery of prepared statements to the database in high concurrency scenarios may increase the load of the database. As can be seen, the performance and efficiency of distributed database preprocessing are low. SUMMARY The invention is set out in the appended set of claims. Some embodiments of the present disclosure provide a distributed database preprocessing method, applied to a database proxy layer, the distributed database preprocessing method including: receiving a request corresponding to a prepared statement; and performing processing according to the request corresponding to the prepared statement and a session identifier cached in a prepared statement cache library, where a session corresponding to the session identifier cached in the prepared statement cache library is a prepared statement session where a connection is successfully established between a client and a database. Some embodiments of the present disclosure further provide a database proxy layer, including a receiving module and a processing module. The receiving module is configured to receive a request corresponding to a prepared statement. The processing module is configured to perform processing according to the received r