Database access method and electronic device

CN121636544BActive Publication Date: 2026-06-02JIANGSU HUAKU DATA TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
JIANGSU HUAKU DATA TECH CO LTD
Filing Date
2026-02-05
Publication Date
2026-06-02

Smart Images

  • Figure CN121636544B_ABST
    Figure CN121636544B_ABST
Patent Text Reader

Abstract

The application provides a database access method and electronic equipment, which can be applied to the technical field of database access. The method comprises the following steps: generating executable units corresponding to sequence identifiers respectively indicated by a plurality of first mapping relationships, a plurality of second mapping relationships and a plurality of third mapping relationships according to the plurality of first mapping relationships, the first mapping relationship being a mapping relationship between a sequence identifier, a template identifier of a statement template and a parameter position identifier of a parameter, the second mapping relationship being a mapping relationship between a template identifier of a statement template and a pre-compiled statement identifier of a statement template, and the third mapping relationship being a mapping relationship between a template identifier of a statement template and a parameter set associated with the statement template; packing the plurality of executable units to generate at least one execution data packet; and sending the at least one execution data packet to a database so that the database executes the executable units arranged in sequence in the execution data packet in turn.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database access technology, and more specifically to a database access method and electronic device. Background Technology

[0002] In database access technology, applications interact with the database through database connection interfaces to perform batch operations. When it is necessary to execute batch operations with different statement templates, multiple instances need to be created, and parameters need to be added to each instance separately. It is difficult to ensure the consistency between the execution order of different statement templates and the order of adding business logic in a single transaction. Summary of the Invention

[0003] In view of the above problems, embodiments of the present invention provide a database access method and an electronic device.

[0004] According to a first aspect of the present invention, a database access method is provided, comprising: generating an executable unit corresponding to a sequence identifier indicated by each of the plurality of first mapping relationships, a plurality of second mapping relationships, and a plurality of third mapping relationships, wherein the first mapping relationship is a mapping relationship between a sequence identifier, a template identifier of a statement template, and a parameter position identifier of a parameter; the second mapping relationship is a mapping relationship between a template identifier of a statement template and a precompiled statement identifier of a statement template; the third mapping relationship is a mapping relationship between a template identifier of a statement template and a parameter set associated with the statement template; and the executable unit includes a precompiled statement identifier associated with the template identifier and a parameter position identifier associated with the template identifier. Parameters and sequence identifiers are used to indicate the order of batch operations in the global execution sequence. A batch operation is an execution instance of a template identifier and the parameters associated with the template identifier. The pre-compiled statement identifier of the statement template is generated by the database performing pre-compilation operations on multiple statement templates from the client. The parameter position identifier of the parameter indicates the position of the parameter in the parameter set. Multiple executable units are packaged to generate at least one execution data packet, wherein the order of the executable units in the execution data packet is consistent with the order indicated by the sequence identifiers of the executable units. At least one execution data packet is sent to the database so that the database executes the executable units arranged in the execution data packet in sequence.

[0005] Optionally, the order in which the executable units are generated is consistent with the order indicated by the sequence identifier; or the order in which the executable units are generated is inconsistent with the order indicated by the sequence identifier.

[0006] Optionally, based on multiple first mapping relationships, multiple second mapping relationships, and multiple third mapping relationships, an executable unit corresponding to each sequence identifier indicated by each of the multiple first mapping relationships is generated, including: for any sequence identifier among the sequence identifiers indicated by the multiple first mapping relationships, determining a precompiled statement identifier associated with the template identifier from multiple second mapping relationships based on the template identifier indicated by the first mapping relationship associated with the sequence identifier; determining a parameter set associated with the template identifier from multiple third mapping relationships based on the template identifier indicated by the first mapping relationship associated with the sequence identifier; determining a parameter associated with the template identifier from the parameter set associated with the template identifier based on the parameter position identifier indicated by the first mapping relationship associated with the sequence identifier; and generating an executable unit based on the precompiled statement identifier associated with the template identifier and the parameter.

[0007] Optionally, multiple executable units are packaged to generate at least one execution data packet, including at least one of the following: if the generation order of the executable units is inconsistent with the order indicated by the sequence identifiers, the multiple executable units are sorted according to the arrangement order indicated by the multiple sequence identifiers, and the sorted multiple executable units are packaged to generate at least one execution data packet; or if the generation order of the executable units is consistent with the order indicated by the sequence identifiers, the multiple executable units sorted according to the generation order of the executable units are packaged to generate an execution data packet.

[0008] Optionally, the database access method also includes: packaging multiple statement templates associated with the precompiled statement array object to obtain a template data package, wherein the precompiled statement array object is created using a database connection; and sending the template data package to the database via a single network communication so that the database can parse the template data package to obtain multiple statement templates.

[0009] Optionally, the database access method further includes: receiving precompiled statement identifiers of multiple statement templates from the database, wherein the receiving order of the precompiled statement identifiers of the statement templates is consistent with the arrangement order of the statement templates in the template data packet, and the template data packet is obtained by the client packaging multiple statement templates associated with the precompiled statement array object; based on the consistency between the receiving order of the precompiled statement identifiers of the statement templates and the arrangement order of the statement templates in the template data packet, establishing a mapping relationship between the template identifiers of multiple statement templates and the precompiled statement identifiers of multiple statement templates, and obtaining multiple second mapping relationships.

[0010] Optionally, the database access method further includes: establishing a mapping relationship between multiple sequence identifiers, multiple template identifiers, and multiple parameter position identifiers based on the sequence identifiers of multiple batch operations, the template identifiers targeted by each of the multiple batch operations, and the parameter position identifiers of the parameters associated with the template identifiers targeted by each of the multiple batch operations, to obtain multiple first mapping relationships; wherein, the multiple sequence identifiers are determined by the client in response to the add requests for each of the multiple batch operations, based on the add order indicated by each of the multiple add requests.

[0011] Optionally, the parameter position identifier is determined according to the order in which the parameters are added. The order in which the parameters are added is based on the template identifier targeted by the batch operation, and the order in which the parameters of the statement template indicated by the template identifier are added to the parameter set associated with the statement template.

[0012] Optionally, multiple executable units are packaged to generate at least one execution data packet, including: determining the data packet size based on at least one of network latency status or bandwidth status; and packaging the multiple executable units according to the data packet size to generate at least one execution data packet.

[0013] A second aspect of this invention provides a database access apparatus, comprising: a generation module, configured to generate executable units corresponding to sequence identifiers indicated by each of the multiple first mapping relationships, based on multiple first mapping relationships, multiple second mapping relationships, and multiple third mapping relationships. The first mapping relationships are mappings between sequence identifiers, template identifiers of statement templates, and parameter position identifiers of parameters; the second mapping relationships are mappings between template identifiers of statement templates and precompiled statement identifiers of statement templates; and the third mapping relationships are mappings between template identifiers of statement templates and parameter sets associated with the statement templates. The executable unit includes a precompiled statement identifier associated with the template identifier and parameters. The identifier is used to indicate the order of batch operations in the global execution sequence. A batch operation is an execution instance of a template identifier and the parameters associated with the template identifier. The pre-compiled statement identifier of the statement template is generated by the database performing pre-compilation operations on multiple statement templates from the client. The parameter position identifier of the parameter indicates the position of the parameter in the parameter set. The packaging module is used to package multiple executable units to generate at least one execution data packet, wherein the order of the executable units in the execution data packet is consistent with the order indicated by the sequence identifier of the executable unit. The sending module is used to send at least one execution data packet to the database so that the database executes the executable units arranged in the execution data packet in sequence.

[0014] A third aspect of the present invention provides an electronic device, including: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors perform the method described above.

[0015] A fourth aspect of the present invention provides a computer-readable storage medium storing computer-executable instructions, which, when executed, are used to implement the method described above.

[0016] A fifth aspect of the present invention provides a computer program product including computer-executable instructions that, when executed, implement the method described above.

[0017] According to the database access method provided by the present invention, since the parameter position identifier corresponding to the template identifier and parameter corresponding to the sequence identifier is determined from the first mapping relationship, the pre-compiled statement identifier corresponding to this template identifier and parameter is determined from the second mapping relationship, and the parameter is determined from the parameter set corresponding to the template identifier in the third mapping relationship according to the parameter position identifier, and then the executable unit containing the pre-compiled statement identifier and parameter associated with each sequence identifier is generated according to strict logic, the error rate of mismatch between the pre-compiled statement identifier and parameter is reduced. Since the sequence identifier indicates the order of batch processing operations in the global execution sequence, the order of executable units in the execution data packet is consistent with the order indicated by the sequence identifier corresponding to the executable unit, so that the database executes the executable units in the order of arrangement, maintaining the consistency between the order of executing executable units in the database and the logical order of batch processing operations in the business. By recording the order of parameters added to the parameter set of the statement template in the business through a global sequence identifier, subsequent execution operations can be strictly performed according to the order of addition in the business logic, ensuring data consistency within the transaction. Attached Figure Description

[0018] The above and other objects, features and advantages of the present invention will become clearer from the following description of embodiments of the invention with reference to the accompanying drawings.

[0019] Figure 1 A schematic diagram of the architecture of a database access system according to an embodiment of the present invention is shown.

[0020] Figure 2 A flowchart of a database access method according to an embodiment of the present invention is shown.

[0021] Figure 3 A schematic diagram of a database access method according to an embodiment of the present invention is shown.

[0022] Figure 4 This diagram illustrates the number of network interactions required for database access methods in related technologies.

[0023] Figure 5 A schematic diagram illustrating the number of network interactions in a database access method according to an embodiment of the present invention is shown.

[0024] Figure 6 A block diagram of a database access apparatus according to an embodiment of the present invention is shown.

[0025] Figure 7 A block diagram of an electronic device suitable for implementing a database access method according to an embodiment of the present invention is shown. Detailed Implementation

[0026] Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the invention. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of the invention for ease of explanation. However, it will be apparent that one or more embodiments may be practiced without these specific details. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concept of the invention.

[0027] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the invention. The terms “comprising,” “including,” etc., as used herein indicate the presence of features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.

[0028] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.

[0029] When using expressions such as "at least one of A, B and C", they should generally be interpreted in accordance with the meaning that is commonly understood by those skilled in the art (e.g., "a system having at least one of A, B and C" should include, but is not limited to, a system having A alone, a system having B alone, a system having C alone, a system having A and B, a system having A and C, a system having B and C, and / or a system having A, B and C, etc.).

[0030] There are typically two methods for performing batch operations using relevant database access technologies.

[0031] One method is the batch processing temporary storage method, Statement.addBatch(String sql). This method can execute different statement templates, but each execution requires the database to re-parse and compile the statement template, which is not only inefficient but also poses a security risk of statement template injection.

[0032] Secondly, there's the parameterized batch processing method `PreparedStatement.addBatch()`. This method involves a single pre-compilation request performing batch parameter operations on a single statement template, resulting in high execution efficiency after the statement templates are pre-compiled. However, a `PreparedStatement` instance can only be bound to one statement template. When batch operations on different statement templates are required, multiple `PreparedStatement` instances need to be created, and the `addBatch()` method and `executeBatch()` method need to be called separately for each instance. Each `PreparedStatement` instance requires an independent network communication and database interaction for pre-compilation. The more statement templates there are, the more network round trips are required for pre-compilation, leading to greater system overhead and network latency. Each `executeBatch()` call of a `PreparedStatement` instance also requires an independent network communication, further increasing network interaction costs. Furthermore, the lifecycle of multiple `PreparedStatement` instances needs to be manually managed, resulting in complex code logic and susceptibility to errors due to resource leaks or mismanagement.

[0033] Furthermore, existing database access technologies struggle to ensure that the execution order of different statement templates matches the order in which business logic is added within a single transaction when handling parameterized batch processing that executes multiple statement templates in batches, increasing the risk of data inconsistency. Therefore, there is an urgent need for an efficient method for batch accessing databases that can integrate multiple statement templates, reduce network overhead, and guarantee the sequential nature of operations.

[0034] In view of this, embodiments of the present invention provide a database access method. A global sequence identifier records the order in which parameters are added to the statement template in the business logic. The sequence identifier indicates the order of batch operations in the global execution sequence. Based on a first mapping relationship, a second mapping relationship, and a third mapping relationship, executable units containing pre-compiled statement identifiers and parameters are generated according to strict logic, corresponding to the sequence identifiers. The order of executable units in the execution data packet is consistent with the order indicated by the sequence identifiers corresponding to the executable units. This ensures that the database executes the executable units sequentially according to the order of their arrangement, maintaining consistency between the order in which the database executes executable units and the order in which the business logic is added. Consequently, subsequent execution operations can proceed according to the order in which the business logic is added, guaranteeing data consistency within transactions. Furthermore, by creating a pre-compiled statement array object PrepareStatementMap, database connections and statement template resources are managed uniformly. Multiple independent pre-compiled network requests are merged into one, reducing network round trips, database concurrency pressure, and client resource consumption, thereby improving resource efficiency. In addition, PreparedStatementMap provides a simple and easy-to-use core module that automatically manages the underlying database connection and the lifecycle of PreparedStatement instances, simplifying the programming model and allowing developers to focus more on business logic without worrying about the complex underlying resource management and execution optimization, thus reducing the probability of errors.

[0035] Figure 1 A schematic diagram of the architecture of a database access system according to an embodiment of the present invention is shown.

[0036] like Figure 1 As shown, the database access system supports batch processing operations using multiple statement templates. The database access system may include client 110 and database 120.

[0037] Client 110 may include the client application layer and the PrepareStatementMap core module. The client can interact with the database through the standard database connection interface (Java Database Connectivity, JDBC).

[0038] The client application layer consists of the application code, responsible for initiating pre-compilation requests and receiving the database's response. The PrepareStatementMap core module is a library / component introduced by the client application layer, providing the client with the capabilities of "statement template registration, parameter addition, and executable unit generation." The database connection interface is the communication channel between the component and the database, responsible for sending execution data packets to the database. These three components together constitute the client's execution stack.

[0039] The PrepareStatementMap core module includes a template management module, a parameter queue module, a sequence control module, and a batch execution engine. The template management module is responsible for receiving and storing Structured Query Language (SQL) templates and submitting pre-compilation requests to the database. The parameter queue module maintains a parameter queue for each SQL template. The sequence control module uses sequence identifiers to record the order of batch processing operations. The batch execution engine is responsible for generating execution data packets based on sorted executable units or the order in which executable units are generated, and interacting with the database by calling the underlying JDBC interface.

[0040] More specifically, the client application layer creates a PrepareStatementMap instance through a database connection, calls the template management module to inject multiple statement templates at once, and generates a pre-compilation request. Client 110 sends the pre-compilation request to database 120 through the Connection object of the JDBC interface layer. Database 120 parses the pre-compilation request, obtains multiple statement templates, performs pre-compilation operations on each statement template to generate a pre-compiled statement identifier for each statement template, and sends the pre-compiled statement identifier to client 110 to generate a second mapping relationship. The parameter queue module adds multiple sets of parameters to the parameter queue in sequence, and the sequence control module globally records the sequence identifier of parameters added to the parameter queue and generates a first mapping relationship and a third mapping relationship. The execution engine responds to the call to executeBatch() to generate multiple executable units based on multiple first mapping relationships, multiple second mapping relationships, and multiple third mapping relationships, and obtains at least one execution data packet based on multiple executable units. The batch execution engine sends the execution data packet to database 120 through the PreparedStatement instance pool of the JDBC interface layer. Database 120 executes the execution data packet, obtains the execution result, and returns the execution result to client 110.

[0041] It should be noted that the sequence numbers of the operations in the following methods are for descriptive purposes only and should not be considered as indicating the execution order of the operations. Unless explicitly stated otherwise, the method does not need to be executed in the exact order shown.

[0042] Figure 2 A flowchart of a database access method according to an embodiment of the present invention is shown.

[0043] like Figure 2 As shown, the method 200 includes operations S210 to S230.

[0044] In operation S210, based on multiple first mapping relationships, multiple second mapping relationships, and multiple third mapping relationships, an executable unit corresponding to the sequence identifier indicated by each of the multiple first mapping relationships is generated.

[0045] In operation S220, multiple executable units are packaged to generate at least one execution data packet.

[0046] In operation S230, at least one execution data packet is sent to the database so that the database executes the executable units arranged in sequence in the execution data packet.

[0047] The client sends multiple statement templates to the database via a single network communication. The database performs a pre-compilation operation on each statement template to generate a pre-compiled statement identifier for each statement template.

[0048] The statement template is a pre-compiled and parameterized structured query language (SQL) template.

[0049] For example, the database performs pre-compilation operations such as statement and syntax parsing on multiple statement templates to generate execution plans for each statement template. It then assigns an identifier to each execution plan to obtain a pre-compiled statement identifier, which is used to uniquely identify the execution plan of the statement template.

[0050] The database sends multiple statement templates, each with its own precompiled statement identifier, to the client via a single network communication.

[0051] The client receives precompiled statement identifiers for multiple statement templates, maps the template identifiers of the statement templates to their precompiled statement identifiers, and generates a second mapping relationship. The template identifier is used to uniquely identify the statement template.

[0052] The second mapping relationship is the mapping relationship between the template identifier of the statement template and the precompiled statement identifier of the statement template.

[0053] Simultaneously, the client application calls `addBatch()` to add parameters to the statement template, generating a first and third mapping relationship based on the addition result. The sequence identifier determines the order in which the parameters of the statement template are added to the statement template.

[0054] The process of adding parameters to a statement template by calling addBatch() can be as follows: the index value of addBatch() is mapped to the template identifier, the parameters of the statement template corresponding to the template identifier are stored in the parameter queue corresponding to this statement template, and the order of this addition operation and the position of the parameter in the parameter queue are recorded. The order of the addition operation is the sequence identifier.

[0055] Based on the multiple parameters in the parameter queue corresponding to this statement template, a parameter set associated with this statement template is generated. A third mapping relationship is generated by mapping the template identifier of the statement template to the parameter set associated with the statement template.

[0056] The parameter position identifier is used to indicate the position of the parameter in the parameter set, and the position of the parameter in the parameter set is the position of the parameter in the parameter queue.

[0057] The sequence identifier, the template identifier of the statement template, and the parameter position identifier are mapped to generate the first mapping relationship.

[0058] For example, add the parameter `psm.addBatch(0, "value1")` to the first INSERT statement template, with a template identifier of 0 and a sequence identifier of 1; add the parameter `psm.addBatch(1, "new_value1", 123)` to the second UPDATE statement template, with a template identifier of 1 and a sequence identifier of 2; add the parameter `psm.addBatch(2, "obsolete1")` to the third DELETE statement template, with a template identifier of 2 and a sequence identifier of 3; add the parameter `psm.addBatch(0, "value2")` to the first INSERT statement template, with a template identifier of 0 and a sequence identifier of 4; add the parameter `psm.addBatch(1, "new_value2", 123)` to the second UPDATE statement template, with a template identifier of 1 and a sequence identifier of 5; add the parameter `psm.addBatch(2, "obsolete2")` to the third DELETE statement template, with a template identifier of 2 and a sequence identifier of 6.

[0059] For example, the parameter set corresponding to the INSERT statement template is (value1, value2), where the parameter position identifier of value1 is 1 and the parameter position identifier of value2 is 2; the parameter set corresponding to the UPDATE statement template is ({"new_value1", 123}, {"new_value2", 123}), where the parameter position identifier of {"new_value1", 123} is 1 and the parameter position identifier of {"new_value2", 123} is 2; and the parameter set corresponding to the DELETE statement template is (obsolete1, obsolete2), where the parameter position identifier of obsolete1 is 1 and the parameter position identifier of obsolete2 is 2.

[0060] For example, the first mapping relationship can be a mapping relationship between sequence identifier 1, template identifier 0, and parameter position identifier 1. The second mapping relationship can be a mapping relationship between template identifier 0 and parameter set (value1, value2).

[0061] After the addition operation is completed, a batch operation is performed to generate multiple executable units, which include precompiled statement identifiers and parameters associated with the template identifier.

[0062] Batch operations are execution instances that target a template identifier and the parameters associated with that template identifier. For example, batch operations include starting a transaction, calling the execution function executeBatch(), committing the transaction, and rolling back the transaction.

[0063] For example, when executeBatch() is called, executable units can be generated according to the order of sequence identifiers: first, the template identifier 0 and parameter position identifier 1 in the first mapping relationship are determined based on sequence identifier 1; then, the parameter value1 corresponding to template identifier 0 is determined from the second mapping relationship based on template identifier 0 and parameter position identifier 1; finally, the preprocessor identifier A1 corresponding to template identifier 0 is determined from the third mapping relationship; the first executable unit is generated based on preprocessor identifier A1 and parameter value1; then, the second executable unit is generated based on sequence identifier 2, and so on, until the executable unit with sequence identifier 6 is generated.

[0064] For example, when executeBatch() is called, multiple executable units corresponding to sequence identifiers are generated based on a random pattern. For example, the first executable unit corresponding to sequence identifier 2, the second executable unit corresponding to sequence identifier 3, the third executable unit corresponding to sequence identifier 6, the fourth executable unit corresponding to sequence identifier 4, the fifth executable unit corresponding to sequence identifier 1, and the sixth executable unit corresponding to sequence identifier 5.

[0065] Sequence identifiers are used to indicate the order in which batch operations are arranged in the global execution sequence, thereby maintaining transaction consistency and the atomicity of operations.

[0066] Multiple executable units can be packaged to generate one or more execution data packages. For example, when there are many executable units, they can be split into two execution data packages; when there are few executable units, one execution data package can be generated directly.

[0067] If multiple executable units corresponding to sequence identifiers are generated according to the order of sequence identifiers, and the generation order of the executable units is consistent with the order indicated by the sequence identifiers corresponding to the executable units, then the multiple executable units are directly packaged, and the order of the executable units in the execution data packet is also consistent with the order indicated by the sequence identifiers corresponding to the executable units.

[0068] When generating multiple executable units corresponding to sequence identifiers based on a random pattern, it is necessary to first sort the multiple executable units according to the order of the sequence identifiers, and then package the multiple executable units so that the order of the executable units in the execution data packet is consistent with the order indicated by the sequence identifiers corresponding to the executable units.

[0069] The order of executable units in the execution data packet is consistent with the order indicated by the sequence identifiers corresponding to the executable units.

[0070] One or more execution data packets are sent to the database via a single network communication, so that the database executes the executable units arranged in order in the execution data packets in sequence. The database executes the executable units arranged in order in the execution data packets and the execution plan corresponding to the precompiled statement identifiers in the executable units in sequence, and obtains the execution result.

[0071] By determining the template identifier and parameter position identifier corresponding to the sequence identifier from the first mapping relationship, then determining the pre-compiled statement identifier corresponding to this template identifier and parameter from the second mapping relationship, and determining the parameter from the parameter set corresponding to the template identifier in the third mapping relationship based on the parameter position identifier, and then generating an executable unit containing a pre-compiled statement identifier and parameters associated with each sequence identifier according to strict logic, the error rate of mismatch between pre-compiled statement identifiers and parameters is reduced. Since the sequence identifier indicates the order of batch operations in the global execution sequence, the order of executable units in the execution data packet is consistent with the order indicated by the sequence identifier corresponding to the executable unit. This allows the database to execute executable units sequentially according to the order of arrangement, maintaining the consistency between the order of executing executable units in the database and the logical order of batch operations in the business. By recording the order in which parameters are added to the parameter set of the statement template in the business through a global sequence identifier, subsequent execution operations can be strictly performed according to the order of addition in the business logic, ensuring data consistency within the transaction.

[0072] Optionally, the order in which the executable units are generated is consistent with the order indicated by the sequence identifier; or the order in which the executable units are generated is inconsistent with the order indicated by the sequence identifier.

[0073] If executable units are generated according to the sequence identifier order, the generated order of the executable units will be consistent with the sequence identifier order.

[0074] For example, if executable unit 1 is first determined from the first mapping relationship, the second mapping relationship, and the third mapping relationship based on sequence identifier 1, and then executable unit 2 is determined from the first mapping relationship, the second mapping relationship, and the third mapping relationship based on sequence identifier 2, then the generation order of executable unit 1 and executable unit 2 is consistent with the arrangement order indicated by the sequence identifier.

[0075] If executable units are generated according to randomly obtained sequence identifiers, the generation order (1-2) of the resulting executable units is inconsistent with the arrangement order (1-2) indicated by the sequence identifiers.

[0076] For example, if executable unit 1 is first randomly determined from the first mapping relationship, the second mapping relationship, and the third mapping relationship based on sequence identifier 3, and then executable unit 2 is randomly determined from the first mapping relationship, the second mapping relationship, and the third mapping relationship based on sequence identifier 2, then the generation order (1-2) of executable unit 1 and executable unit 2 is inconsistent with the arrangement order (2-3) indicated by the sequence identifier.

[0077] In the process of generating executable units corresponding to multiple sequence identifiers, in a serial scenario, executable units can be generated serially based on the order indicated by the sequence identifiers, thereby strictly controlling the generation order of executable units and reducing the risk of data inconsistency. In a parallel scenario, multiple executable units corresponding to multiple sequence identifiers can be generated in parallel, and then the out-of-order executable units can be sorted, which improves performance and resource utilization.

[0078] Optionally, based on multiple first mapping relationships, multiple second mapping relationships, and multiple third mapping relationships, an executable unit corresponding to each sequence identifier indicated by each of the multiple first mapping relationships is generated, including: for any sequence identifier among the sequence identifiers indicated by the multiple first mapping relationships, determining a precompiled statement identifier associated with the template identifier from multiple second mapping relationships based on the template identifier indicated by the first mapping relationship associated with the sequence identifier; determining a parameter set associated with the template identifier from multiple third mapping relationships based on the template identifier indicated by the first mapping relationship associated with the sequence identifier; determining a parameter associated with the template identifier from the parameter set associated with the template identifier based on the parameter position identifier indicated by the first mapping relationship associated with the sequence identifier; and generating an executable unit based on the precompiled statement identifier associated with the template identifier and the parameter.

[0079] When executeBatch() is called, any sequence identifier is determined from the sequence identifiers indicated by each of the multiple first mappings, and a precompiled statement identifier associated with the template identifier is determined from the multiple second mappings based on the template identifier indicated by the first mapping associated with this sequence identifier.

[0080] For example, based on sequence identifier 1, a first mapping relationship containing sequence identifier 1 is determined, namely, the first mapping relationship between sequence identifier 1, template identifier 0, and parameter position identifier 1. Template identifier 0 is then determined from the first mapping relationship containing sequence identifier 1. Based on template identifier 0, a second mapping relationship containing template identifier 0 is determined from multiple second mapping relationships, namely, the second mapping relationship between template identifier 0 and preprocessor identifier A1, thereby determining that the preprocessor identifier associated with template identifier 0 is A1.

[0081] For example, based on the template identifier indicated by the first mapping relationship associated with the sequence identifier, the parameter set associated with the template identifier is determined from multiple third mapping relationships. Based on the template identifier 0, a third mapping relationship containing the template identifier 0 is determined from multiple third mapping relationships, that is, the third mapping relationship between the template identifier 0 and the parameter set (value1, value2), thereby determining the parameter set (value1, value2) associated with the template identifier 0.

[0082] For example, based on the parameter position identifier 1 indicated by the first mapping relationship associated with sequence identifier 1, the parameter associated with template identifier 0 is determined to be value1 from the parameter set (value1, value2) associated with template identifier 0. Based on the precompiled statement identifier A1 associated with template identifier 0 and the parameter value1, an executable unit is generated.

[0083] Based on the above steps, multiple first mapping relationships are generated, each indicating an executable unit corresponding to a sequence identifier.

[0084] For any sequence identifier, the template identifier and parameter position identifier associated with this sequence identifier are accurately determined from the first mapping relationship. Then, the precompiled statement identifier associated with this template identifier is accurately determined from the second mapping relationship, and the parameter set associated with this template identifier is accurately determined from the third mapping relationship. Thus, the parameters are determined from the parameter set based on this parameter position identifier. Based on the precompiled statement identifier associated with the template identifier and the parameters, an executable unit is generated, thereby achieving accurate matching of the precompiled statement identifier and the parameters.

[0085] Optionally, multiple executable units are packaged to generate at least one execution data packet, including at least one of the following: if the generation order of the executable units is inconsistent with the order indicated by the sequence identifiers, the multiple executable units are sorted according to the arrangement order indicated by the multiple sequence identifiers, and the sorted multiple executable units are packaged to generate at least one execution data packet; or if the generation order of the executable units is consistent with the order indicated by the sequence identifiers, the multiple executable units sorted according to the generation order of the executable units are packaged to generate an execution data packet.

[0086] If a sequence identifier is randomly determined from the sequence identifiers indicated by multiple first mapping relationships, the generation order of the executable units of the multiple sequence identifiers will be inconsistent with the order indicated by the sequence identifiers.

[0087] The order in which the multiple sequence identifiers indicate the order in which parameters are added to the statement template for each call to addBatch().

[0088] Multiple executable units are sorted according to the order indicated by each sequence identifier, so that the order of the sorted executable units is consistent with the order indicated by the sequence identifiers. Then, the sorted executable units are packaged to generate one or more efficient execution data packets.

[0089] If the sequence identifiers are determined sequentially from the sequence identifiers indicated by the multiple first mapping relationships based on the order of the sequence identifiers, then the generation order of the executable units of the multiple sequence identifiers is consistent with the order indicated by the sequence identifiers. In this case, the multiple executable units ordered according to the generation order of the executable units are directly packaged to generate one or more efficient execution data packets.

[0090] The client sends an execution data packet to the database. The database executes the execution plan of the executable units and the statement templates associated with the executable units in the execution data packet according to their order, obtains the execution results, and sends the execution results back to the client.

[0091] By using a global sequence identifier to record the order in which parameters are added when `addBatch` is called, multiple executable units are sorted based on the order indicated by each sequence identifier when the order in which executable units are generated is inconsistent with the order indicated by the sequence identifier. When the order in which executable units are generated is consistent with the order indicated by the sequence identifier, multiple executable units sorted according to the order in which they are generated are packaged together. This conveniently maintains the consistency between the order in which the database ultimately executes multiple statement templates and the order in which parameters are added in the business logic within a single transaction, reducing the risk of data inconsistency, reducing the complexity of concurrent programming, and improving the reliability of the system.

[0092] Optionally, the database access method also includes: packaging multiple statement templates associated with the precompiled statement array object to obtain a template data package, wherein the precompiled statement array object is created using a database connection; and sending the template data package to the database via a single network communication so that the database can parse the template data package to obtain multiple statement templates.

[0093] The application uses a database connection (e.g., Connection) to create a PreparedStatementMap object. The PreparedStatementMap object is an instance of a statement template object that is placeholder, pre-compilable, re-executed, and automatically protected against injection. All the statement templates that need to be used are passed in at once when the PreparedStatementMap object is constructed.

[0094] For example, constructing a prepared statement array object PrepareStatementMap psm = connection.prepareStatementMap( "INSERT INTO table1 (col1) VALUES (?)","UPDATE table2 SET col2 = ? WHERE id = ?","DELETE FROM table3 WHERE status =?") allows the prepared statement array object to support passing in 3 statement templates at once.

[0095] Inside prepareStatementMap, multiple statement templates are packaged into a template data package in a database-recognizable format.

[0096] The client sends a template data packet to the database through a single network communication, so that the database can parse the template data packet to obtain multiple statement templates for batch pre-compilation and assign pre-compiled statement identifiers.

[0097] By introducing a precompiled statement array object, which serves as a unified entry point for client access to the database, all required statement templates are passed in at once during client initialization of the precompiled statement array object, and precompiled to the database via a single network communication. This enables one-time batch precompilation of multiple statement templates in mixed template batch operation scenarios, significantly reducing the number of precompilations. It merges the original multiple independent precompilation network communications for multiple statement templates into a single network communication, greatly reducing the number of network round trips and the preprocessing load on the database, and significantly improving performance.

[0098] Figure 3 A schematic diagram of a database access method according to an embodiment of the present invention is shown.

[0099] like Figure 3As shown, the application first registers multiple SQL templates (SQL template 1, SQL template 2, and SQL template 3) with PrepareStatementMap at once. The template management module generates template identifiers and sends all templates to the database for pre-compilation. After the database returns the pre-compiled statement identifier to the template management module, the application adds the parameters to the parameter queue corresponding to the statement template in the parameter addition request addBatch in sequence. The parameter queue module maintains the parameters in the parameter queue, and the sequence control module records the sequence identifier for each addBatch. For example, the first call to addBatch adds parameter 1 to the parameter queue of template identifier 0, and records the sequence identifier seq1=1; the second call to addBatch adds parameters 2 and 3 to the parameter queue of template identifier 1, and records the sequence identifier seq1=2; the third call to addBatch adds parameter 4 to the parameter queue of template identifier 0, and records the sequence identifier seq1=3.

[0100] When the batch execution request executeBatch() is called, the batch execution engine obtains multiple sequence identifiers and sequentially retrieves the parameters corresponding to the template identifiers corresponding to the sequence identifiers from the parameter queue module. It generates executable units containing the correspondence between precompiled statement identifiers and parameters. Multiple executable units can be combined into a single execution data packet according to the order of the sequence identifiers. The packet is then sent to the database at once through optimized network transmission. After the database executes the packet, it returns the execution result. The batch execution engine summarizes the execution result to obtain a summary result array and encapsulates it in int[] format before returning it to the application. This completes the entire data flow of "template registration at once, parameter injection in batches, and result order return".

[0101] Figure 4 This diagram illustrates the number of network interactions required for database access methods in related technologies.

[0102] Figure 5 A schematic diagram illustrating the number of network interactions in a database access method according to an embodiment of the present invention is shown.

[0103] In a batch processing test involving 10,000 operations with 3 different types of SQL templates, Figure 4 The diagram illustrates the number of network interactions required for database access methods in related technologies. It requires the creation of 10 PreparedStatement instances, each PreparedStatement instance can only precompile one SQL template, and each PreparedStatement instance needs to perform one precompile request round trip and one batch execution request round trip. Therefore, it requires 6 network round trips, including 3 precompiles and 3 batch executions, resulting in approximately 12 network communications. Figure 5The database access method of this embodiment of the invention is shown in terms of the number of network interactions. PrepareStatementMap can perform batch pre-compilation of 3 statement templates. It can be seen that the PrepareStatementMap instance only needs 1 batch pre-compilation request round trip and 1 optimized batch execution request round trip, about 4 network communications, reducing the total number of network round trips to about 4.

[0104] The database access method of this invention creates a PrepareStatementMap to uniformly manage database connections and statement template resources, merging multiple independent pre-compiled network requests into one, reducing network round trips, database concurrency pressure, and client resource consumption, and improving resource efficiency. In addition, PrepareStatementMap provides a simple and easy-to-use core module that automatically manages the lifecycle of underlying database connections and PreparedStatement instances, greatly simplifying the programming model and allowing developers to focus more on business logic without worrying about the complex underlying resource management and execution optimization, thus reducing the probability of errors.

[0105] Optionally, the database access method further includes: receiving precompiled statement identifiers of multiple statement templates from the database, wherein the receiving order of the precompiled statement identifiers of the statement templates is consistent with the arrangement order of the statement templates in the template data packet, and the template data packet is obtained by the client packaging multiple statement templates associated with the precompiled statement array object; based on the consistency between the receiving order of the precompiled statement identifiers of the statement templates and the arrangement order of the statement templates in the template data packet, establishing a mapping relationship between the template identifiers of multiple statement templates and the precompiled statement identifiers of multiple statement templates, and obtaining multiple second mapping relationships.

[0106] After assigning precompiled statement identifiers to multiple statement templates, the database sends the precompiled statement identifiers to the client based on the order of the statement templates in the template data packet.

[0107] The order in which the precompiled statement identifiers of the statement templates are received indicates the order in which the client receives the precompiled statement identifiers. The order in which the precompiled statement identifiers of the statement templates are received is consistent with the order in which the statement templates are arranged in the template data packets.

[0108] Based on the fact that the receiving order of the precompiled statement identifiers of the statement templates is consistent with the arrangement order of the statement templates in the template data packet, a mapping relationship between the template identifier and the precompiled statement identifier is established for each statement template in turn to obtain the second mapping relationship.

[0109] For example, the template data packet includes ordered statement template 1, statement template 2 and statement template 3. The client sequentially receives the precompiled statement identifier A1 of statement template 1, the precompiled statement identifier A2 of statement template 2 and the precompiled statement identifier A3 of statement template 3, and sequentially establishes a second mapping relationship between the template identifier 001 of statement template 1 and the precompiled statement identifier A1, the template identifier 002 of statement template 2 and the precompiled statement identifier A2, and the template identifier 003 of statement template 3 and the precompiled statement identifier A3.

[0110] After the database assigns precompiled statement identifiers to multiple statement templates, the precompiled statement identifiers of each statement template are sent to the client in sequence based on the order of the statement templates in the template data packet. This allows the client to map the precompiled statement identifiers to the template identifiers one-to-one, improving the accuracy of the second mapping relationship.

[0111] Optionally, the database access method further includes: establishing a mapping relationship between multiple sequence identifiers, multiple template identifiers, and multiple parameter position identifiers based on the sequence identifiers of multiple batch operations, the template identifiers targeted by each of the multiple batch operations, and the parameter position identifiers of the parameters associated with the template identifiers targeted by each of the multiple batch operations, to obtain multiple first mapping relationships; wherein, the multiple sequence identifiers are determined by the client in response to the add requests for each of the multiple batch operations, based on the add order indicated by each of the multiple add requests.

[0112] The client responds to the addBatch() request by adding parameters to the statement template and generates the first mapping relationship based on the added result.

[0113] The sequence identifier is determined based on the order in which the multiple add requests indicate the add order.

[0114] The process of adding parameters to a statement template by calling addBatch() can be as follows: the index value of addBatch() is mapped to the template identifier, the parameters of the statement template corresponding to the template identifier are stored in the parameter queue corresponding to this statement template, and the addition order and the position of the parameter in the parameter queue are recorded. The addition order is the sequence identifier.

[0115] The parameter queue module within the precompiled statement array object maintains a parameter batch queue for each precompiled statement template, and the sequence control module records the order in which parameters are added to the parameter queue corresponding to the statement template through a global sequence identifier.

[0116] The parameter position identifier indicates the position in the parameter queue corresponding to this statement template where the parameter is stored.

[0117] For example, add the parameter psm.addBatch(0, "value1") to the first INSERT statement template, with the template identifier set to 0, the parameter position identifier set to 1, and the generated sequence identifier set to 1; add the parameter psm.addBatch(1, "new_value1", 123) to the second UPDATE statement template, with the template identifier set to 1, the parameter position identifier set to 1, and the sequence identifier set to 2; add the parameter psm.addBatch(1, "new_value2", 123) to the second UPDATE statement template, with the template identifier set to 1, the parameter position identifier set to 2, and the sequence identifier set to 3.

[0118] For example, generate a first mapping relationship between sequence identifier 1, template identifier 0 and parameter position identifier 1; generate a first mapping relationship between sequence identifier 2, template identifier 1 and parameter position identifier 1; generate a second mapping relationship between sequence identifier 2, template identifier 1 and parameter position identifier 2.

[0119] By using a global sequence identifier to record the order in which addBatch requests are added, and by using the parameter queue module and sequence control module provided by the precompiled statement array object, multiple batch operations and the generation of sequence identifiers are controlled to be performed in the same transaction context. This establishes the first mapping relationship between multiple sequence identifiers, multiple template identifiers, and multiple parameter position identifiers, so that template identifiers and parameter position identifiers can be quickly located based on sequence identifiers during the generation of executable units, thus reducing the probability of errors.

[0120] Optionally, the parameter position identifier is determined according to the order in which the parameters are added. The order in which the parameters are added is based on the template identifier targeted by the batch operation, and the order in which the parameters of the statement template indicated by the template identifier are added to the parameter set associated with the statement template.

[0121] Parameter queues are established for multiple statement templates. Each time an add request is called, the parameters are stored in the parameter queue of the statement template corresponding to these parameters. After all add requests are completed, a parameter set associated with the statement template is generated based on the multiple parameters stored in the parameter queue of the statement template.

[0122] The order in which parameters are added to the parameter set associated with the statement template determines the order in which they are added to the parameter queue corresponding to the statement template.

[0123] The parameter position identifier is determined by the order in which the parameters are added.

[0124] For example, first add the parameter psm.addBatch(0,"value1") to the first INSERT statement template, with the parameter position identifier of value1 being 1; then add the parameter psm.addBatch(0,"value2") to the first INSERT statement template, with the parameter position identifier of value2 being 2.

[0125] During the process of adding parameters to the parameter set associated with the statement template, parameter position identifiers are generated according to the order in which the parameters are added, so that the specific parameters can be quickly and accurately located from the parameter set based on the parameter position identifiers during the generation of the executable unit.

[0126] Optionally, multiple executable units are packaged to generate at least one execution data packet, including: determining the data packet size based on at least one of network latency status or bandwidth status; and packaging the multiple executable units according to the data packet size to generate at least one execution data packet.

[0127] Bandwidth status represents the estimated available bandwidth of the current communication network.

[0128] Network latency status characterizes the average round-trip time of the current communication network.

[0129] For example, in a high gateway state: network latency = 600 ms, bandwidth = 100 Mbps, and data packet size = 750 kB; the scheduler packages 150 5 kB executable units into one execution data packet.

[0130] For example, in the narrow-height gateway state: network latency = 20 ms, bandwidth = 1 Mbps, and data packet size = 16 kB. The original 16 2 kB executable units are split into 2 16 kB execution data units.

[0131] The system dynamically determines the packet size based on the current network latency or bandwidth status of the communication network. Multiple executable units are packaged according to the packet size, thereby generating multiple efficient execution data to improve throughput with high latency and generating a single execution packet with narrow latency to avoid congestion, balancing bandwidth utilization and latency. In addition, the system combines the executable units of multiple statement templates into one or as few execution packets as possible and sends the execution packets to the database, further reducing network and protocol overhead.

[0132] Based on the above database access method, this application also provides a database access device. The following will be combined with... Figure 6 The device is described in detail.

[0133] Figure 6 A structural block diagram of a database access apparatus according to an embodiment of this application is shown.

[0134] like Figure 6 As shown, the database access device 600 of this embodiment includes a generation module 610, a packaging module 620, and a sending module 630.

[0135] The generation module 610 is used to generate executable units corresponding to the sequence identifiers indicated by the multiple first mapping relationships, multiple second mapping relationships, and multiple third mapping relationships, respectively. The first mapping relationship is a mapping between the sequence identifier, the template identifier of the statement template, and the parameter position identifier of the parameter. The second mapping relationship is a mapping between the template identifier of the statement template and the precompiled statement identifier of the statement template. The third mapping relationship is a mapping between the template identifier of the statement template and the parameter set associated with the statement template. The executable unit includes the precompiled statement identifier associated with the template identifier and the parameter. The sequence identifier is used to indicate the order of batch operations in the global execution sequence. The batch operation is an execution instance of the template identifier and the parameter associated with the template identifier. The precompiled statement identifier of the statement template is generated by the database performing precompilation operations on each of the multiple statement templates from the client. The parameter position identifier of the parameter indicates the position of the parameter in the parameter set.

[0136] Packaging module 620 is used to package multiple executable units to generate at least one execution data packet, wherein the order of the executable units in the execution data packet is consistent with the order indicated by the sequence identifiers corresponding to the executable units.

[0137] The sending module 630 is used to send at least one execution data packet to the database so that the database executes the executable units arranged in sequence in the execution data packet in turn.

[0138] Figure 7 A block diagram of an electronic device suitable for implementing a database access method according to an embodiment of the present invention is shown.

[0139] Figure 7 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.

[0140] like Figure 7As shown, a computer electronic device 700 according to an embodiment of the present invention includes a processor 701, which can perform various appropriate actions and processes according to a program stored in a ROM 702 (read-only memory) or a program loaded from a storage portion 708 into a RAM 703 (random access memory). The processor 701 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 701 may also include onboard memory for caching purposes. The processor 701 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.

[0141] RAM 703 stores various programs and data required for the operation of electronic device 700. Processor 701, ROM 702, and RAM 703 are interconnected via bus 704. Processor 701 executes various operations of the method flow according to embodiments of the present invention by executing programs in ROM 702 and / or RAM 703. It should be noted that programs may also be stored in one or more memories other than ROM 702 and RAM 703. Processor 701 may also execute various operations of the method flow according to embodiments of the present invention by executing programs stored in one or more memories.

[0142] Optionally, the electronic device 700 may also include an input / output (I / O) interface 705, which is also connected to the bus 704. The electronic device 700 may also include one or more of the following components connected to the input / output (I / O) interface 705: an input section 706 including a keyboard, mouse, etc.; an output section 707 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the input / output (I / O) interface 705 as needed. A removable medium 711, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 710 as needed so that computer programs read from it can be installed into the storage section 708 as needed.

[0143] Optionally, the method flow according to embodiments of the present invention can be implemented as a computer software program. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a computer-readable storage medium, the computer program containing program code for performing the method shown in the flowchart. In such embodiments, the computer program can be downloaded and installed from a network via communication section 709, and / or installed from removable medium 711. When the computer program is executed by processor 701, it performs the functions defined in the system of embodiments of the present invention. Optionally, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.

[0144] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the database access method according to embodiments of the present invention.

[0145] Optionally, the computer-readable storage medium can be a non-volatile computer-readable storage medium. Examples include, but are not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this invention, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0146] For example, optionally, the computer-readable storage medium may include the ROM 702 and / or RAM 703 described above and / or one or more memories other than ROM 702 and RAM 703.

[0147] Embodiments of the present invention also include a computer program product comprising a computer program containing program code for performing the methods provided in the embodiments of the present invention. When the computer program product is run on an electronic device, the program code is used to enable the electronic device to implement the database access method provided in the embodiments of the present invention.

[0148] When the computer program is executed by the processor 701, it performs the functions defined in the system / apparatus of this embodiment of the invention. Optionally, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.

[0149] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and may be downloaded and installed via the communication section 709, and / or installed from a removable medium 711. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.

[0150] Optionally, program code for executing the computer programs provided in the embodiments of the present invention can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, languages ​​such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0151] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions. Those skilled in the art will understand that the features described in the various embodiments of the present invention can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in the present invention. In particular, the features described in the various embodiments of the present invention can be combined and / or combined in various ways without departing from the spirit and teachings of the present invention. All such combinations and / or pairings fall within the scope of this invention.

[0152] The embodiments of the present invention have been described above. However, these embodiments are merely illustrative and not intended to limit the scope of the invention. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. Various substitutions and modifications can be made by those skilled in the art without departing from the scope of the invention, and all such substitutions and modifications should fall within the scope of the invention.

Claims

1. A database access method, characterized in that, include: Based on multiple first mapping relationships, multiple second mapping relationships, and multiple third mapping relationships, an executable unit corresponding to each sequence identifier indicated by each of the multiple first mapping relationships is generated. The first mapping relationship is a mapping between a sequence identifier, a template identifier of a statement template, and a parameter position identifier of a parameter. The second mapping relationship is a mapping between the template identifier of the statement template and the precompiled statement identifier of the statement template. The third mapping relationship is a mapping between the template identifier of the statement template and the parameter set associated with the statement template. The executable unit includes a precompiled statement identifier associated with the template identifier and parameters. The sequence identifier is used to indicate the order of batch operations in the global execution sequence. The batch operation is an execution instance targeting the template identifier and the parameters associated with the template identifier. The precompiled statement identifier of the statement template is generated by the database performing precompilation operations on multiple statement templates from the client. The parameter position identifier of the parameter indicates the position of the parameter in the parameter set. The executable units are packaged to generate at least one execution data packet, wherein the order of the executable units in the execution data packet is consistent with the order indicated by the sequence identifiers corresponding to the executable units; At least one execution data packet is sent to the database so that the database executes the executable units arranged in sequence in the execution data packet.

2. The method according to claim 1, characterized in that, The executable units are generated in the same order as indicated by the sequence identifier; or The order in which the executable units are generated is inconsistent with the order indicated by the sequence identifier.

3. The method according to claim 1 or 2, characterized in that, The step of generating an executable unit corresponding to the sequence identifier indicated by each of the multiple first mapping relationships, multiple second mapping relationships, and multiple third mapping relationships includes: For any sequence identifier among the sequence identifiers indicated by each of the multiple first mapping relationships, Based on the template identifier indicated by the first mapping associated with the sequence identifier, a precompiled statement identifier associated with the template identifier is determined from a plurality of second mappings; Based on the template identifier indicated by the first mapping relationship associated with the sequence identifier, determine the parameter set associated with the template identifier from a plurality of the third mapping relationships; Based on the parameter position identifier indicated by the first mapping relationship associated with the sequence identifier, determine the parameter associated with the template identifier from the parameter set associated with the template identifier; The executable unit is generated based on the precompiled statement identifier and parameters associated with the template identifier.

4. The method according to claim 1 or 2, characterized in that, The step of packaging the multiple executable units to generate at least one execution data package includes at least one of the following: If the generation order of the executable units is inconsistent with the order indicated by the sequence identifiers, the executable units are sorted according to the arrangement order indicated by the respective sequence identifiers, and the sorted executable units are packaged to generate at least one execution data packet; or If the generation order of the executable units is consistent with the sorting indicated by the sequence identifier, the multiple executable units sorted according to the generation order of the executable units are packaged to generate the execution data package.

5. The method according to claim 1 or 2, characterized in that, The method further includes: Multiple statement templates associated with the precompiled statement array object are packaged to obtain a template data package, wherein the precompiled statement array object is created using a database connection; The template data packet is sent to the database via a single network communication, so that the database can parse the template data packet to obtain multiple statement templates.

6. The method according to claim 1 or 2, characterized in that, The method further includes: The system receives precompiled statement identifiers for each of the multiple statement templates from the database, wherein the receiving order of the precompiled statement identifiers of the statement templates is consistent with the arrangement order of the statement templates in the template data packet, and the template data packet is obtained by the client packaging multiple statement templates associated with the precompiled statement array object; Based on the consistency between the receiving order of the precompiled statement identifiers of the statement templates and the arrangement order of the statement templates in the template data packet, a mapping relationship is established between the template identifiers of the multiple statement templates and the precompiled statement identifiers of the multiple statement templates, resulting in multiple second mapping relationships.

7. The method according to claim 1 or 2, characterized in that, The method further includes: Based on the sequence identifiers of the multiple batch operations, the template identifiers targeted by the multiple batch operations, and the parameter position identifiers of the parameters associated with the template identifiers targeted by the multiple batch operations, a mapping relationship is established between the multiple sequence identifiers, the multiple template identifiers, and the multiple parameter position identifiers to obtain multiple first mapping relationships; The plurality of sequence identifiers are determined by the client in response to each of the plurality of batch processing operations’ respective add requests, based on the add order indicated by each of the plurality of add requests.

8. The method according to claim 7, characterized in that, The parameter position identifier is determined according to the order in which the parameters are added. The order in which the parameters are added is based on the template identifier targeted by the batch processing operation, and the order in which the parameters of the statement template indicated by the template identifier are added to the parameter set associated with the statement template.

9. The method according to claim 1 or 2, characterized in that, The step of packaging multiple executable units to generate at least one execution data packet includes: The packet size is determined based on at least one of the network latency status or bandwidth status; Based on the data packet size, multiple executable units are packaged to generate at least one execution data packet.

10. An electronic device, comprising: One or more processors; Memory, used to store one or more computer programs. The characteristic feature is that the one or more processors invoke the one or more computer programs to implement the steps of the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Database statement compilation and execution method and device

    CN107220265A

  • Log processing method and device, equipment and storage medium

    CN120234011A