Data access method and device, electronic equipment and storage medium
By executing SQL statements in parallel in a distributed database, the problem of performance bottlenecks when a distributed database is solved when processing large amounts of data is processed, and efficient data processing and data consistency are achieved.
Patent Information
- Application Number
- CN202411454575.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2025-02-11
AI Technical Summary
When a distributed database processes a large amount of data, it uses loops or multiple independent SQL statements to process data one by one, resulting in performance bottlenecks.
Provides a data access method, which can parse and obtain stored procedures by receiving stored procedures sent by the client, distribute and execute several SQL statements in parallel, and generate and feedback data access results.
Improve data processing speed, and process data on multiple servers by executing SQL statements in parallel, ensuring data consistency and integrity, reducing the number of SQL statements written and managed, and reducing the possibility of errors and exceptions.
Smart Images

Figure CN119415552A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a data access method, device, electronic equipment and storage medium. Background Art
[0002] With the rapid development of information technology and economy, the amount of data and user scale in the financial industry have shown explosive growth. Traditional stand-alone database systems have begun to encounter performance bottlenecks and scalability limitations. In order to solve these problems, distributed relational databases have come into being. In addition, as enterprises' demand for data processing grows, database systems are beginning to face performance and efficiency challenges. The performance bottlenecks, duplicated codes, and difficult-to-maintain logic caused by the sequential serial execution of traditional SQL statements are becoming increasingly severe. As a solution, stored procedures provide the following advantages:
[0003] Performance improvement: After the stored procedure is created, it will be precompiled, which means that there is no need to recompile the SQL statement when executing it, thus reducing the parsing and compilation time and improving execution efficiency.
[0004] Reduced network traffic: By executing complex logic on the database server, stored procedures reduce the number of communications between the application and the database, thereby reducing network load.
[0005] Security enhancement: Stored procedures can restrict users from directly accessing data tables and only allow operations through procedures, which can better control data access rights and operations.
[0006] Simplified maintenance: Encapsulating business logic in stored procedures makes the code more centralized and easier to manage. When you need to modify the business logic, you only need to change the stored procedure without having to modify each application that calls it.
[0007] Reusability: Stored procedures can be called repeatedly by multiple applications or users, which improves code reusability and reduces development workload.
[0008] When performing batch operations, database administrators and developers usually need to write loops or use multiple independent SQL statements to process data one by one. However, since this method involves a large number of network round trips and database transaction processing, it will cause performance bottlenecks when processing large amounts of data. Summary of the invention
[0009] The purpose of the present invention is to overcome the above technical deficiencies and provide a data access method, device, electronic device and storage medium to solve the technical problem in the prior art that when a distributed database processes a large amount of data, it uses a loop or multiple independent SQL statements to process data one by one, which will cause performance bottlenecks.
[0010] In order to achieve the above technical objectives, the present invention adopts the following technical solutions:
[0011] In a first aspect, the present invention provides a data access method, comprising the following steps:
[0012] Receive a stored procedure call statement sent by a client, and parse the stored procedure call statement;
[0013] Based on the parsed call stored procedure statement, a corresponding stored procedure is obtained, and the stored procedure is parsed to obtain a plurality of SOL statements;
[0014] Distribute the SQL statements based on the number of the SQL statements and a preset degree of parallelism to execute the SQL statements in parallel;
[0015] Based on the execution result of the SQL statement, a data access result is generated, and the data access result is fed back to the client, wherein the data access result includes a normal result and an abnormal result.
[0016] In some embodiments, the distributing of the plurality of SQL statements based on the number of the SQL statements and the preset parallelism to execute the plurality of SQL statements in parallel includes:
[0017] Determine whether the number of SQL statements is greater than the preset degree of parallelism;
[0018] Based on the judgment result, the plurality of SQL statements are distributed in a preset distribution mode to execute the plurality of SQL statements in parallel.
[0019] In some embodiments, the preset distribution methods include two types. When the number of SQL statements is not greater than the preset parallelism, the first distribution method is adopted. When the number of SQL statements is greater than the preset parallelism, the second distribution method is adopted.
[0020] In some embodiments, the first distribution method is specifically:
[0021] The plurality of SQL statements are obtained, and the SQL statements are distributed to each preset sub-execution thread to execute the plurality of SQL statements in parallel.
[0022] In some embodiments, the second distribution method is specifically:
[0023] Obtain the SQL statements of the preset parallelism size, and add the remaining SQL statements to the queue to be executed;
[0024] Distribute the acquired SQL statements to preset sub-execution threads to execute several SQL statements in parallel;
[0025] When any sub-execution thread finishes executing an SQL statement, an SQL statement is obtained from the queue to be executed and distributed to the sub-execution thread.
[0026] In some embodiments, generating a data access result based on the execution result of the SQL statement and feeding back the data access result to the client includes:
[0027] When any SQL statement fails to execute, an abnormal result is generated, and when several SQL statements are executed successfully, a normal result is generated;
[0028] The abnormal result or normal result is fed back to the client.
[0029] In some embodiments, the method further comprises:
[0030] When any SQL statement fails to execute, all SQL statements will be stopped.
[0031] In a third aspect, the present invention further provides an electronic device, comprising: a processor and a memory;
[0032] The memory stores a computer program executable by the processor;
[0033] When the processor executes the computer program, the steps in the data access method described above are implemented.
[0034] In a fourth aspect, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps in the data access method as described above.
[0035] Compared with the prior art, the data access method, device, electronic device and storage medium provided by the present invention first receive a stored procedure call statement sent by a client, and parse the stored procedure call statement; then, based on the parsed stored procedure call statement, obtain the corresponding stored procedure, and parse the stored procedure to obtain a plurality of SOL statements; then, based on the number of SQL statements and a preset degree of parallelism, distribute the plurality of SQL statements to execute the plurality of SQL statements in parallel; finally, based on the execution result of the SQL statement, generate a data access result, and feed back the data access result to the client. Compared with the traditional SQL statement serial method, the present invention can be executed on multiple parallel servers, further improving the data processing speed, and all operations are regarded as a single transaction, which means that either all operations are successful or all are rolled back when an error occurs, which helps to maintain data consistency and integrity, supports multiple operations, including insert, update and delete operations, and is very useful in various scenarios; and can also be used in combination with the WHERE clause to provide conditional filtering for specific batch operations. In addition, the present invention also reduces the number of SQL statements that need to be written and managed, thereby reducing the possibility of exceptions and errors caused by manual errors or omissions. Moreover, the present invention not only supports the parallel execution of SQL statements, but also supports the parallel calling of stored procedures. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 is a flow chart of a data access method provided by an embodiment of the present invention;
[0037] Figure 2 It is a schematic diagram of the serial execution process of SQL statements in the existing data access method;
[0038] Figure 3 It is a schematic diagram of the parallel execution process of SQL statements in the data access method provided by an embodiment of the present invention;
[0039] Figure 4 is a schematic diagram of functional modules of a data access device provided by an embodiment of the present invention;
[0040] Figure 5 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0042] Distributed database (DDB) systems usually use smaller computer systems, each computer can be placed in a separate place, each computer may have a complete copy of the DBMS, or a partial copy, and has its own local database. Many computers located in different locations are interconnected through the network to form a complete, global, logically centralized, and physically distributed large database. When performing batch operations, database administrators and developers usually need to write loops or use multiple independent SQL statements to process data one by one, but because this method involves a large number of network round trips and database transaction processing, it will cause performance bottlenecks when processing large amounts of data.
[0043] Based on this, the embodiment of the present invention provides a data access method, please refer to Figure 1 , Figure 1 The present invention is a flowchart of a data access method provided by an embodiment of the present invention. The data access method involved in the present invention can be used in data access to avoid the performance bottleneck caused by using a loop or multiple independent SQL statements to process data one by one when a distributed database processes a large amount of data. The data access method involved in the present invention can be executed by an electronic device that can perform operations such as receiving or sending data, and can be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, portable computers, desktop servers, etc.
[0044] See also Figure 1 , which is a flow chart of a data access method according to an embodiment of the present invention, the method at least includes the following steps S100 to S400.
[0045] S100: receiving a stored procedure call statement sent by a client, and parsing the stored procedure call statement.
[0046] In this embodiment, a technology for parallel operation of statements in a stored procedure based on a GoldenDB distributed database system is adopted. The call stored procedure statement sent by the client is sent to a computing node. The computing node has multiple threads, mainly including an execution thread and a stored procedure engine thread (SPE thread). The execution thread is used to process SQL statements sent by the client, including processes such as call parsing, such as processing call stored procedure statements. The stored procedure engine thread is used to process stored procedure related statements sent by the execution thread, including parsing and scheduling. The call stored procedure statement varies depending on the database system. In this embodiment, since a distributed relational database is used, the call stored procedure statement is preferably an SQL Call statement. The CALL statement is a command in SQL for calling a stored procedure. A stored procedure is a precompiled SQL code block that can be created and saved in a database so that it can be executed when needed. The CALL statement can be used to execute a stored procedure and pass parameters to it.
[0047] S200. Based on the parsed stored procedure call statement, obtain the corresponding stored procedure, and parse the stored procedure to obtain a plurality of SOL statements.
[0048] In this embodiment, a stored procedure is a precompiled SQL code block that can be created and saved in a database so that it can be executed when needed. The stored procedure can accept parameters and return a result set or a single value. It is usually used to execute complex business logic, such as data validation, data processing, and report generation. After receiving the message, the spe thread parses the called stored procedure and generates executable instructions one by one after the parsing is completed. The instructions exist in the form of SQL statements.
[0049] S300: Distribute a plurality of the SQL statements based on the number of the SQL statements and a preset degree of parallelism, so as to execute the plurality of the SQL statements in parallel.
[0050] In this embodiment, after receiving the message, the spe thread parses the called stored procedure. After the parsing is completed, it generates executable instructions one by one. When an SQL statement is encountered during execution, the SQL statement needs to be sent to the execution thread, which is parsed by the execution thread and sent to the data node for processing. The next SQL statement will not be driven until the previous SQL statement is executed and the SPE thread receives the execution success or execution failure response sent by the execution thread. Based on this mode, if a slow SQL statement is encountered or a large number of SQL statements need to be executed in a loop, the entire stored procedure execution will be stuck or take a long time. The execution process is as follows: Figure 2As shown. Therefore, the embodiment of the present invention adopts a parallel processing method to process SQL statements. Specifically, the embodiment of the present invention adopts Forall to process SQL statements in parallel. The syntax parsing process is consistent with the original process. The forall loop executes the internal SQL statement expr_start to expr_end times, where / *+FORALL_PARALLELISM(10)* / is a parallelism hint, which may not be declared. If it is not declared in the statement, the default parallelism configured in the computing node configuration item is used. After receiving the forall instruction, the main execution thread first reissues the start transaction statement internally to start the transaction, and then sends the statements to different execution threads one by one for concurrent processing until the parallelism is reached, thereby realizing execution on multiple parallel servers, further improving the data processing speed. The execution process is shown as follows Figure 3 shown.
[0051] S400. Generate a data access result based on the execution result of the SQL statement, and feed back the data access result to the client, wherein the data access result includes a normal result and an abnormal result.
[0052] In this embodiment, since SQL statements may fail during execution, an exception result is generated when an execution failure response is received. At this time, subsequent operations are processed according to the stored procedure exception process. If the SQL statements are executed successfully, normal results are generated and the data desired by the client is returned.
[0053] The embodiment of the present invention first receives a stored procedure call statement sent by a client, and parses the stored procedure call statement; then, based on the parsed stored procedure call statement, obtains a corresponding stored procedure, and parses the stored procedure to obtain a plurality of SOL statements; then, based on the number of SQL statements and a preset degree of parallelism, distributes the plurality of SQL statements to execute the plurality of SQL statements in parallel; finally, based on the execution result of the SQL statement, generates a data access result, and feeds back the data access result to the client. Compared with the traditional SQL statement serial method, the present invention can be executed on multiple parallel servers, further improving the data processing speed, and all operations are regarded as a single transaction, which means that either all operations are successful or all are rolled back when an error occurs, which helps to maintain data consistency and integrity, supports multiple operations, including insert, update and delete operations, and is very useful in various scenarios; and can also be used in combination with the WHERE clause to provide conditional filtering for specific batch operations. In addition, the present invention also reduces the number of SQL statements that need to be written and managed, thereby reducing the possibility of exceptions and errors caused by manual errors or omissions. Moreover, the present invention not only supports the parallel execution of SQL statements, but also supports the parallel calling of stored procedures.
[0054] In some embodiments, step S200 specifically includes:
[0055] Determine whether the number of SQL statements is greater than the preset degree of parallelism;
[0056] Based on the judgment result, the plurality of SQL statements are distributed in a preset distribution mode to execute the plurality of SQL statements in parallel.
[0057] In this embodiment, since the number of parallel executions at one time is limited, that is, the degree of parallelism is limited, the number of SQL statements will affect the subsequent distribution and execution methods. In order to ensure that subsequent SQL statements can be executed correctly, the embodiment of the present invention formulates different distribution methods based on the size relationship between the number of SQL statements and the preset degree of parallelism.
[0058] Optionally, the preset distribution method includes two types. When the number of SQL statements is not greater than the preset parallelism, the first distribution method is adopted; when the number of SQL statements is greater than the preset parallelism, the second distribution method is adopted.
[0059] In this embodiment, when the number of SQL statements is not greater than the preset parallelism, all SQL statements can be directly issued, that is, a direct one-time issuance method is adopted to achieve the distribution of SQL statements. When the number of SQL statements is greater than the preset parallelism, all SQL statements cannot be issued at one time. Therefore, it is necessary to issue SQL statements in batches.
[0060] In some embodiments, the first distribution method is specifically:
[0061] The plurality of SQL statements are obtained, and the SQL statements are distributed to each preset sub-execution thread to execute the plurality of SQL statements in parallel.
[0062] In this embodiment, if the total number of loops is less than the specified concurrency, the SPE thread cyclically sends statements to the execution thread until the total number of loops is reached, and then the total execution thread sends the statements one by one to different execution threads for concurrent processing, thereby realizing parallel processing of several SQL statements to improve data processing speed.
[0063] In some embodiments, the second distribution method is specifically:
[0064] Obtain the SQL statements of the preset parallelism size, and add the remaining SQL statements to the queue to be executed;
[0065] Distribute the acquired SQL statements to preset sub-execution threads to execute several SQL statements in parallel;
[0066] When any sub-execution thread finishes executing an SQL statement, an SQL statement is obtained from the queue to be executed and distributed to the sub-execution thread.
[0067] In this embodiment, if the total number of loops is greater than the specified concurrency, the spe thread loops to send statements to the execution thread until the concurrency is reached. When the concurrency is reached, after receiving a successful statement execution response from the execution thread, the spe thread immediately sends another statement to the execution thread, always maintaining the maximum concurrency until all statements are executed and the next step is performed after all responses are collected.
[0068] In some embodiments, step S300 specifically includes:
[0069] When any SQL statement fails to execute, an abnormal result is generated, and when several SQL statements are executed successfully, a normal result is generated;
[0070] The abnormal result or normal result is fed back to the client.
[0071] In this embodiment, when all SQL statements are executed successfully, the data that the client wants is fed back to the client. If any SQL statement fails to execute, the subsequent operations are processed according to the stored procedure exception flow. All operations are regarded as a single transaction, which means that either all operations are successful or all are rolled back when an error occurs. This helps to maintain data consistency and integrity.
[0072] In some embodiments, the method further comprises:
[0073] When any SQL statement fails to execute, all SQL statements will be stopped.
[0074] In this embodiment, if the spe receives a sql execution failure response returned by the execution thread before all statements are sent, the subsequent statement sending is suspended, and then subsequent operations are processed according to the storage procedure exception process. The present invention rolls back all SQL statements when an error occurs. This helps to maintain the consistency and integrity of the data.
[0075] The technical solution provided by the present invention first receives a stored procedure call statement sent by a client, and parses the stored procedure call statement; then, based on the parsed stored procedure call statement, obtains a corresponding stored procedure, and parses the stored procedure to obtain a plurality of SOL statements; then, based on the number of SQL statements and a preset degree of parallelism, distributes the plurality of SQL statements to execute the plurality of SQL statements in parallel; finally, based on the execution result of the SQL statement, generates a data access result, and feeds back the data access result to the client. Compared with the traditional SQL statement serial method, the present invention can be executed on multiple parallel servers, further improving the data processing speed, and all operations are regarded as a single transaction, which means that either all operations are successful or all are rolled back when an error occurs, which helps to maintain data consistency and integrity, supports multiple operations, including insert, update and delete operations, and is very useful in various scenarios; and can also be used in combination with the WHERE clause to provide conditional filtering for specific batch operations. In addition, the present invention also reduces the number of SQL statements that need to be written and managed, thereby reducing the possibility of exceptions and errors caused by manual errors or omissions. Moreover, the present invention not only supports the parallel execution of SQL statements, but also supports the parallel calling of stored procedures.
[0076] Another embodiment of the present invention provides a data access device, see Figure 4 The data access device includes a stored procedure call statement receiving module 11, a stored procedure parsing module 12, a parallel execution module 13 and a result feedback module 14.
[0077] The stored procedure call statement receiving module 11 is used to receive a stored procedure call statement sent by a client and parse the stored procedure call statement.
[0078] The stored procedure parsing module 12 is used to obtain the corresponding stored procedure based on the parsed stored procedure call statement, and parse the stored procedure to obtain a plurality of SOL statements.
[0079] The parallel execution module 13 is used to distribute the SQL statements based on the number of the SQL statements and a preset parallelism, so as to execute the SQL statements in parallel.
[0080] The result feedback module 14 is used to generate a data access result based on the execution result of the SQL statement, and feed back the data access result to the client, wherein the data access result includes a normal result and an abnormal result.
[0081] The embodiment of the present invention first receives a stored procedure call statement sent by a client, and parses the stored procedure call statement; then, based on the parsed stored procedure call statement, obtains a corresponding stored procedure, and parses the stored procedure to obtain a plurality of SOL statements; then, based on the number of SQL statements and a preset degree of parallelism, distributes the plurality of SQL statements to execute the plurality of SQL statements in parallel; finally, based on the execution result of the SQL statement, generates a data access result, and feeds back the data access result to the client. Compared with the traditional SQL statement serial method, the present invention can be executed on multiple parallel servers, further improving the data processing speed, and all operations are regarded as a single transaction, which means that either all operations are successful or all are rolled back when an error occurs, which helps to maintain data consistency and integrity, supports multiple operations, including insert, update and delete operations, and is very useful in various scenarios; and can also be used in combination with the WHERE clause to provide conditional filtering for specific batch operations. In addition, the present invention also reduces the number of SQL statements that need to be written and managed, thereby reducing the possibility of exceptions and errors caused by manual errors or omissions. Moreover, the present invention not only supports the parallel execution of SQL statements, but also supports the parallel calling of stored procedures.
[0082] It should be noted that the module referred to in the present invention refers to a series of computer program instruction segments that can perform specific functions, which are more suitable for describing the execution process of data access than programs. For the specific implementation of each module, please refer to the corresponding method embodiment above, which will not be repeated here.
[0083] In some embodiments, the parallel execution module 13 is specifically used for:
[0084] Determine whether the number of SQL statements is greater than the preset degree of parallelism;
[0085] Based on the judgment result, the plurality of SQL statements are distributed in a preset distribution mode to execute the plurality of SQL statements in parallel.
[0086] In some embodiments, the preset distribution methods include two types. When the number of SQL statements is not greater than the preset parallelism, the first distribution method is adopted. When the number of SQL statements is greater than the preset parallelism, the second distribution method is adopted.
[0087] In some embodiments, the first distribution method is specifically:
[0088] The plurality of SQL statements are obtained, and the SQL statements are distributed to each preset sub-execution thread to execute the plurality of SQL statements in parallel.
[0089] In some embodiments, the second distribution method is specifically:
[0090] Obtain the SQL statements of the preset parallelism size, and add the remaining SQL statements to the queue to be executed;
[0091] Distribute the acquired SQL statements to preset sub-execution threads to execute several SQL statements in parallel;
[0092] When any sub-execution thread finishes executing an SQL statement, an SQL statement is obtained from the queue to be executed and distributed to the sub-execution thread.
[0093] In some embodiments, the result feedback module 14 is specifically used for:
[0094] When any SQL statement fails to execute, an abnormal result is generated, and when several SQL statements are executed successfully, a normal result is generated;
[0095] The abnormal result or normal result is fed back to the client.
[0096] In some embodiments, the device further includes a pause module, which is used to stop executing all SQL statements when any SQL statement fails to execute.
[0097] Another embodiment of the present invention provides an electronic device, such as Figure 5 As shown, the electronic device 10 includes:
[0098] One or more processors 110 and memory 120, Figure 5A processor 110 is used as an example for description. The processor 110 and the memory 120 may be connected via a bus or other means. Figure 5 The example of connecting through bus is taken in the following.
[0099] The processor 110 is used to complete various control logics of the electronic device 10. It can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of these components. In addition, the processor 110 can also be any traditional processor, microprocessor or state machine. The processor 110 can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP and / or any other such configuration.
[0100] The memory 120 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions corresponding to the data access method in the embodiment of the present invention. The processor 110 executes various functional applications and data processing of the electronic device 10 by running the non-volatile software programs, instructions and units stored in the memory 120, that is, implements the data access method in the above method embodiment.
[0101] The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store an operating platform, an application required for at least one function; the data storage area may store data created according to the use of the electronic device 10, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include a memory remotely arranged relative to the processor 110, and these remote memories may be connected to the electronic device 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0102] One or more units are stored in the memory 120, and when executed by one or more processors 110, the data access method in any of the above method embodiments is executed, for example, the data access method described above is executed. Figure 1 The method comprises steps S100 to S400.
[0103] Another embodiment of the present invention provides a computer-readable storage medium, which stores computer-executable instructions. The computer-executable instructions are executed by one or more processors, for example, to execute the above-described Figure 1 The method comprises steps S100 to S400.
[0104] As an example, a computer readable storage medium can include a read-only memory (ROM), a programmable ROM (PROM), an electrically programmable ROM (EPROM), an electrically erasable ROM (EEPROM), or a flash memory. Volatile memory can include a random access memory (RAM) as an external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0105] In summary, the data access method, device, electronic device and storage medium provided by the present invention first receive a stored procedure call statement sent by a client and parse the stored procedure call statement; then, based on the parsed stored procedure call statement, obtain the corresponding stored procedure, and parse the stored procedure to obtain a number of SOL statements; then, based on the number of SQL statements and a preset degree of parallelism, distribute the several SQL statements to execute the several SQL statements in parallel; finally, based on the execution result of the SQL statement, generate a data access result, and feed back the data access result to the client. Compared with the traditional SQL statement serial method, the present invention can be executed on multiple parallel servers, further improving the data processing speed, and all operations are regarded as a single transaction, which means that either all operations are successful or all are rolled back when an error occurs, which helps to maintain data consistency and integrity, supports multiple operations, including insert, update and delete operations, and is very useful in various scenarios; and can also be used in combination with the WHERE clause to provide conditional filtering for specific batch operations. In addition, the present invention also reduces the number of SQL statements that need to be written and managed, thereby reducing the possibility of exceptions and errors caused by manual errors or omissions. Moreover, the present invention not only supports the parallel execution of SQL statements, but also supports the parallel calling of stored procedures.
[0106] The specific implementation of the present invention described above does not constitute a limitation on the protection scope of the present invention. Any other corresponding changes and modifications made based on the technical concept of the present invention should be included in the protection scope of the claims of the present invention.
Claims
1. A data access method, characterized in that: The steps include: Receive a stored procedure call statement sent by a client, and parse the stored procedure call statement; Based on the parsed call stored procedure statement, a corresponding stored procedure is obtained, and the stored procedure is parsed to obtain a plurality of SOL statements; Distribute the SQL statements based on the number of the SQL statements and a preset degree of parallelism to execute the SQL statements in parallel; Based on the execution result of the SQL statement, a data access result is generated, and the data access result is fed back to the client, wherein the data access result includes a normal result and an abnormal result.
2. The data access method according to claim 1, characterized in that: The distributing of the plurality of SQL statements based on the number of the SQL statements and the preset parallelism to execute the plurality of SQL statements in parallel includes: Determine whether the number of SQL statements is greater than the preset degree of parallelism; Based on the judgment result, the plurality of SQL statements are distributed in a preset distribution mode to execute the plurality of SQL statements in parallel.
3. The data access method according to claim 2, characterized in that: The preset distribution methods include two types. When the number of SQL statements is not greater than the preset parallelism, the first distribution method is adopted. When the number of SQL statements is greater than the preset parallelism, the second distribution method is adopted.
4. The data access method according to claim 3, characterized in that: The first distribution method is specifically: The plurality of SQL statements are obtained, and the SQL statements are distributed to each preset sub-execution thread to execute the plurality of SQL statements in parallel.
5. The data access method according to claim 3, characterized in that: The second distribution method is specifically: Obtain the SQL statements of the preset parallelism size, and add the remaining SQL statements to the queue to be executed; Distribute the acquired SQL statements to preset sub-execution threads to execute several SQL statements in parallel; When any sub-execution thread finishes executing an SQL statement, an SQL statement is obtained from the queue to be executed and distributed to the sub-execution thread.
6. The data access method according to claim 1, characterized in that: The step of generating a data access result based on the execution result of the SQL statement and feeding back the data access result to the client comprises: When any SQL statement fails to execute, an abnormal result is generated, and when several SQL statements are executed successfully, a normal result is generated; The abnormal result or normal result is fed back to the client.
7. The data access method according to claim 6, characterized in that: Also includes: When any SQL statement fails to execute, all SQL statements will be stopped.
8. A data access device, characterized in that: include: A stored procedure call statement receiving module is used to receive a stored procedure call statement sent by a client and parse the stored procedure call statement; A stored procedure parsing module, used to obtain a corresponding stored procedure based on the parsed call stored procedure statement, and parse the stored procedure to obtain a plurality of SOL statements; A parallel execution module, used for distributing a plurality of the SQL statements based on the number of the SQL statements and a preset parallelism, so as to execute the plurality of the SQL statements in parallel; The result feedback module is used to generate a data access result based on the execution result of the SQL statement, and feed back the data access result to the client, wherein the data access result includes a normal result and an abnormal result.
9. An electronic device, characterized in that: include: Processor and memory; The memory stores a computer program executable by the processor; When the processor executes the computer program, the steps in the data access method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: include: Processor and memory; The memory stores a computer program executable by the processor; When the processor executes the computer program, the steps in the data access method according to any one of claims 1 to 7 are implemented.