SQL statement execution method and parallel apparatus

By dynamically adjusting the parallelism and priority queue management of the database system using parallel devices, the problem of low SQL statement execution efficiency in the database system is solved, achieving more efficient SQL statement execution and resource optimization.

WO2025242054A1PCT designated stage Publication Date: 2025-11-27HUAWEI TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2025/095851
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-05-24
Filing Date
2025-05-19
Publication Date
2025-11-27

AI Technical Summary

Technical Problem

The number of SQL statements that a database system can execute in parallel is specified by the business system, which may not be suitable for the database system's operating conditions, resulting in excessively high or low load and affecting execution efficiency.

Method used

The parallel device dynamically adjusts the parallelism of the database system, determines the number of parallel SQL statements based on the IO load, manages unexecuted SQL statements through a priority queue, prioritizes the execution of statements with long historical execution times, and dynamically adjusts the length of the queue to optimize resource utilization.

Benefits of technology

While ensuring the performance of the database system, improve the execution efficiency of SQL statements, shorten the total execution time of tasks, optimize resource utilization, and reduce memory consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025095851_27112025_PF_FP_ABST
    Figure CN2025095851_27112025_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application are an SQL statement execution method and a parallel apparatus, which can improve the SQL statement execution efficiency. The method can be applied to the parallel apparatus. In specific implementation, the parallel apparatus can acquire a plurality of SQL statements which are not executed by a database system, and put the plurality of SQL statements into a queue to be executed; the parallel apparatus can also periodically determine input and output loads of the database system, so as to determine the degree of parallelism for SQL statements executed in parallel by the database system; when the degree of parallelism is greater than the number of SQL statements currently executed in parallel, the parallel apparatus acquires from said queue a number of SQL statements equal to a difference between the degree of parallelism and the number of the SQL statements currently executed in parallel, and executes same; otherwise, upon completing execution of the number of SQL statements equal to the difference between the degree of parallelism and the number of the SQL statements currently executed in parallel, the parallel apparatus does not acquire SQL statements from said queue.
Need to check novelty before this filing date? Find Prior Art

Description

Method and parallel device for executing SQL statement

[0001] The present application claims priority to the Chinese patent application No. 202410657793.8, filed on May 24, 2024, with the State Intellectual Property Office of China, and entitled "Method and parallel device for executing SQL statement", the whole content of which is incorporated herein by reference. TECHNICAL FIELD

[0002] The present application relates to the technical field of database, and in particular, to a method and a parallel device for executing a structured query language (SQL) statement. BACKGROUND

[0003] In order to improve the processing efficiency of a task, a database system usually needs to execute a SQL statement related to the task in parallel. At present, the number of parallelisms of the SQL statement executed in parallel by the database system can be specified by a business system. However, the number of parallelisms specified by the business system may not be suitable for the running situation of the database system, thereby causing the load of the database system to be too high or too low. SUMMARY

[0004] The present application provides a method and a parallel device for executing a SQL statement, which can improve the efficiency of the database system in executing the SQL statement while ensuring the performance of the database system.

[0005] In a first aspect, the present application provides a method for executing a SQL statement. The method can be applied to a parallel device. Specifically, the parallel device can obtain a plurality of SQL statements which are not executed by a database system, and put the plurality of SQL statements into an execution queue. The parallel device can also periodically determine the input / output (IO) load of the database system, and then determine the number of parallelisms of the SQL statement executed in parallel by the database system (i.e., the parallelism degree of the database system). When the parallelism degree of the database system is greater than the number of the SQL statement currently executed in parallel, the parallel device obtains the difference between the parallelism degree of the database system and the number of the SQL statement currently executed in parallel from the execution queue, and executes the SQL statement. When the parallelism degree of the database system is less than the number of the SQL statement currently executed in parallel, the parallel device does not obtain the SQL statement from the execution queue after the difference between the parallelism degree of the database system and the number of the SQL statement currently executed in parallel is executed.

[0006] The parallel device can dynamically adjust the number of SQL statements executed in parallel by the database system according to the parallel degree of the database system, so that more SQL statements are executed in parallel by the database system under the premise of ensuring the performance of the database system, and the execution efficiency of the SQL statements is improved.

[0007] In an implementation manner, the parallel device puts the plurality of SQL statements into the to-be-executed queue by determining priorities of the plurality of SQL statements, and putting the SQL statements with higher priorities into the to-be-executed queue in priority.

[0008] In an implementation manner, the parallel device determines the priorities of the plurality of SQL statements by determining historical execution durations of each of the plurality of SQL statements according to a SQL statement library, wherein the SQL statement library includes a plurality of SQL statement templates and execution durations corresponding to each of the plurality of SQL statement templates, and the historical execution duration of the SQL statement is the execution duration corresponding to the matched SQL statement template. Then, the parallel device determines the priorities of the plurality of SQL statements according to the historical execution durations of the plurality of SQL statements, wherein the historical execution duration of the SQL statement with a higher priority is greater than the historical execution duration of the SQL statement with a lower priority.

[0009] Through the implementation manner, the SQL statement with a long historical execution duration can be put into the to-be-executed queue in priority, so that the database system can execute the SQL statement with a long historical execution duration in priority. It should be understood that for a task including the SQL statement, the total execution duration of the task can be shortened, and the execution efficiency of the task can be improved.

[0010] In an implementation manner, the parallel device acquires the plurality of SQL statements by scanning the unexecuted SQL statements in the database system through a scanning thread, and locking the scanning thread. After the plurality of SQL statements are put into the to-be-executed queue, the parallel device further unlocks the scanning thread. Through the implementation manner, different instances can be prevented from reading the same SQL statement at the same time.

[0011] In an implementation manner, the length of the to-be-executed queue can be adjusted. For example, the length of the to-be-executed queue can be adjusted according to the parallel degree of the database system. When the parallel degree of the database system is greater than the current length of the to-be-executed queue, the length of the to-be-executed queue can be increased, so as to improve the efficiency of acquiring the unexecuted SQL statements from the to-be-executed queue. When the parallel degree of the database system 100 is less than the current length of the to-be-executed queue, and the difference between them is large, the length of the to-be-executed queue can be shortened, so as to reduce the memory occupation.

[0012] In an implementation, the parallel device acquires the plurality of SQL statements not executed by the database system includes that the parallel device acquires the SQL statements from the database system periodically, and waits when the to-be-executed queue is full.

[0013] In a second aspect, the application provides a parallel device. The device can include an acquisition module, a determination module and an execution module. The acquisition module is configured to acquire a plurality of SQL statements not executed by a database system and put the plurality of SQL statements into a to-be-executed queue. The determination module is configured to periodically determine an IO load of the database system and further determine a parallel degree of the database system. The execution module is configured to acquire, when the parallel degree of the database system is greater than a number of SQL statements currently being executed in parallel, a difference between the parallel degree of the database system and the number of SQL statements currently being executed in parallel from the to-be-executed queue and execute the difference. The execution module is further configured to not acquire SQL statements from the to-be-executed queue when the parallel degree of the database system is less than the number of SQL statements currently being executed in parallel.

[0014] In an implementation, the acquisition module is configured to determine priorities of the plurality of SQL statements, and put SQL statements with higher priorities into the to-be-executed queue first.

[0015] In an implementation, the acquisition module is configured to determine a historical execution duration of each of the plurality of SQL statements according to a SQL statement library, wherein the SQL statement library includes a plurality of SQL statement templates and an execution duration corresponding to each of the SQL statement templates, and the historical execution duration of a SQL statement is the execution duration corresponding to a matched SQL statement template; and determine the priorities of the plurality of SQL statements according to the historical execution durations of the plurality of SQL statements, wherein the historical execution duration of a SQL statement with a higher priority is greater than the historical execution duration of a SQL statement with a lower priority.

[0016] In an implementation, the acquisition module is configured to scan the database system for SQL statements not executed by the database system through a scanning thread, and lock the scanning thread. The acquisition module is further configured to unlock the scanning thread after putting the plurality of SQL statements into the to-be-executed queue.

[0017] In an implementation, the length of the to-be-executed queue can be adjusted.

[0018] In an implementation, the acquisition module is configured to acquire the SQL statements from the database system periodically, and wait when the to-be-executed queue is full.

[0019] In a third aspect, the present application provides a database system. The system comprises a storage device and a computing device. The storage device is configured to store a plurality of SQL statements which are not executed. The computing device comprises a processor and a memory, wherein the processor is configured to execute instructions stored in the memory to cause the computing device to perform part or all of the method described in the first aspect above and any of its implementation forms.

[0020] In a fourth aspect, the present application provides a computing device. The computing device comprises a processor and a memory, wherein the processor is configured to execute instructions stored in the memory to cause the computing device to perform part or all of the method described in the first aspect above and any of its implementation forms.

[0021] In a fifth aspect, the present application provides a computing device cluster. The computing device cluster comprises at least one computing device, each of which comprises a processor and a memory. The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the computing device cluster to perform part or all of the method described in the first aspect above and any of its implementation forms.

[0022] In a sixth aspect, the present application provides a computer program product comprising instructions. The computer program product can be a software or program product comprising instructions capable of running on a computing device or stored in any available medium. When the computer program product runs on the computing device, it causes the computing device to perform part or all of the method described in the first aspect above and any of its implementation forms.

[0023] In a seventh aspect, the present application provides a computer readable storage medium. The computer storage medium comprises computer program instructions, which, when executed by a computing device, cause the computing device to perform part or all of the method described in the first aspect above and any of its implementation forms. BRIEF DESCRIPTION OF DRAWINGS

[0024] FIG. 1 is a structural schematic diagram of a database system provided by the present application;

[0025] FIG. 2 is a schematic diagram of an application scenario provided by the present application;

[0026] FIG. 3 is a flow schematic diagram of a method for generating an execution queue provided by the present application;

[0027] FIG. 4 is a flow schematic diagram of a method for executing a SQL statement provided by the present application;

[0028] FIG. 5 is a structural schematic diagram of a parallel device provided by the present application;

[0029] FIG. 6 is a structural schematic diagram of a computing device provided by the present application;

[0030] FIG. 7 is a structural diagram of a computing device cluster provided by the present application;

[0031] FIG. 8 is a structural diagram of another computing device cluster provided by the present application. DETAILED DESCRIPTION

[0032] In order to improve the execution efficiency of the SQL statement, the present application provides an execution method of the SQL statement. The method can be applied to a parallel device, and the parallel device is deployed in a database system. The parallel device can dynamically adjust the parallelism of the database system according to the IO load of the database system, and execute the SQL statement not executed by the database system in parallel according to the parallelism of the database system, thereby increasing the number of the SQL statement executed in parallel by the database system and improving the execution efficiency of the SQL statement.

[0033] The technical solutions provided by the present application will be described below with reference to the accompanying drawings.

[0034] Referring to FIG. 1, FIG. 1 shows a structural diagram of a possible database system, which can be a storage system integrated with computing or a storage system separated from computing. As shown in FIG. 1, the database system 100 includes a computing layer 110 and a storage layer 120. The computing layer 110 can include a computing device 111, which can be a server. The storage layer 120 includes a storage device 121, which can be a hard disk, a disk or other types of storage medium, such as a solid state disk (SSD) or a shingled magnetic recording hard disk, etc.

[0035] In the scenario where the database system 100 needs to perform a large batch of SQL statements, such as when employees of a business need to generate reports on various scenarios such as ordering, inventory, cash flow, accounts receivable and payable, profit and loss, etc., the business system will send a large number of SQL statements to the database system 100. After the database system 100 receives the SQL statements sent by the business system, it can store these SQL statements in the storage device 121. Then, the above-mentioned SQL statements can be executed based on the parallel device 200 deployed on the computing device 111, and the specific process is as follows: the parallel device 200 reads a plurality of SQL statements that have not been executed by the database system 100 from the storage device 121, and puts these SQL statements into an execution queue. The parallel device 200 also determines the parallelism of the database system 100 according to the current IO load of the database system 100, wherein the parallelism of the database system 100 refers to the maximum number of SQL statements that the database system 100 allows to be executed in parallel. Then, the parallel device 200 reads a plurality of SQL statements that can be executed in parallel from the above-mentioned execution queue according to the parallelism of the database system 100, and submits each read SQL statement to a thread, and executes the above-mentioned plurality of threads in parallel. When the parallelism of the database system 100 changes, the parallel device 200 can also dynamically adjust the number of SQL statements executed in parallel. Wherein, when the new parallelism is greater than the number of SQL statements currently being executed in parallel, the parallel device 200 obtains M SQL statements from the execution queue and executes the M SQL statements, M being the difference between the new parallelism and the number of SQL statements currently being executed in parallel. When the new parallelism is less than the number of SQL statements currently being executed in parallel, if only N SQL statements are executed, the parallel device 200 does not obtain SQL statements from the execution queue, N being a positive integer less than or equal to M.

[0036] In an implementation, the above-mentioned functions provided by the database system 100 can be provided to tenants (e.g., enterprises) in the form of cloud services, which will be described below with reference to the application scenario shown in FIG. 2. As shown in FIG. 2, the database system 100 is deployed in a data center and provides cloud services based on the underlying resources (including computing resources, storage resources, network resources, etc.) provided by the data center. An enterprise can remotely access a cloud management platform through a client 300 (e.g., a browser), register an account on the cloud management platform, log in to the cloud management platform through the account, and thus purchase services provided by the database system 100 on the cloud management platform. After successful purchase, the enterprise can store various business data to the database system 100 and manage and maintain the business data through the database system 100. In the specific management and maintenance process, the database system 100 dynamically adjusts the number of SQL statements executed in parallel based on the internal parallel device 200 according to the IO load of the database system 100, so as to improve the execution efficiency of the SQL statements without affecting the performance of the database system 100, thereby achieving more effective data management and data maintenance.

[0037] Next, the process of executing SQL statements in parallel by the database system 100 will be described in more detail with reference to FIGS. 3-4.

[0038] Referring to FIG. 3, FIG. 3 shows a flowchart of a method of generating a to-be-executed queue. As shown in FIG. 3, the parallel device 200 can generate a to-be-executed queue through the following steps.

[0039] In step 101, the parallel device 200 obtains a plurality of SQL statements that are not executed by the database system 100.

[0040] The above-mentioned plurality of SQL statements can include data manipulation language (DML) statements such as INSERT statements, DELETE statements, UPDATE statements, and SELECT statements, and can also include data definition language (DDL) statements such as CREATE statements, TRNCATE statements, and DROP statements, or other database operation statements.

[0041] In a specific implementation, the parallel device 200 can read a plurality of SQL statements that are not executed by the database system 100 from the storage device 121 of the database system 100 according to pre-stored configuration information. The configuration information can include one or more of the time, the number, the batch, and the priority of the batch of the SQL statements that the parallel device 200 needs to read from the storage device 121. The configuration information can be set by a user or dynamically adjusted by the parallel device 200 according to actual conditions. For example, if the database system 100 frequently receives SQL statements sent by a business system in a certain time period, the parallel device 200 can increase the frequency and the number of reading the unexecuted SQL statements from the storage device 121 in the time period. For another example, if there is a task that needs to be completed in priority, the parallel device 200 can set the priority of the batch corresponding to the SQL statements of the task in the configuration information to a high priority, so that the parallel device 200 can read the SQL statements of the batch from the storage device 121 in priority, and then complete the processing process of the task in priority.

[0042] Exemplarily, the parallel device 200 can periodically obtain the unexecuted SQL statements from the storage device 121 of the database system 100. Alternatively, the parallel device 200 determines the priorities of the unexecuted SQL statements in the storage device 121, and then selects the unexecuted SQL statements with high priorities. Here, the priority of the SQL statement can be the priority of the batch corresponding to the SQL statement.

[0043] To avoid the case that multiple instances read the same SQL statement from the storage device 121 of the database system 100 at the same time, the parallel device 200 obtains a plurality of unexecuted SQL statements of the database system 100, including: the parallel device 200 scans the plurality of unexecuted SQL statements of the database system 100 through a scanning thread, and locks the scanning thread.

[0044] In step 102, the parallel device 200 determines the priorities of the obtained plurality of SQL statements according to the SQL statement library.

[0045] The parallel device 200 pre-stores a SQL statement library, which includes a plurality of SQL statement templates and the execution duration corresponding to each SQL statement template. The execution duration corresponding to the SQL statement template refers to the historical execution duration of the SQL statement generated according to the template, wherein the SQL statement template is consistent with the SQL statement generated according to the template except that the SQL statement template does not include the parameter value, and the SQL statement template can use a placeholder to represent the parameter value. For ease of understanding, a possible SQL statement template is taken as an example for description below:

[0046] SQL statement template: SECLECT year month

[0047] FROM time data table

[0048] WHERE year = placeholder, month = placeholder

[0049] The SQL statement generated according to the template is: SECLECT year month

[0050] FROM time data table

[0051] WHERE year = 2024, month = 3

[0052] As can be seen, the above SQL statement template and the SQL statement generated according to the template both include three parts, which are the SECLECT part, the FROM part and the WHERE part. The content included in the SECLECT part of the SQL statement template is the same as the content included in the SECLECT part of the SQL statement. The content included in the FROM part of the SQL statement template is the same as the content included in the FROM part of the SQL statement. The WHERE part of the SQL statement includes a field to be queried and a value of the field to be queried, and the WHERE part of the SQL statement template is the same as the WHERE part of the SQL statement except that a placeholder is used to represent the value of the field to be queried.

[0053] Therefore, the parallel device 200 can determine the priority of the above obtained multiple SQL statements in the following manner: the parallel device 200 determines the historical execution time length of each SQL statement in the above multiple SQL statements according to the SQL statement library, and then determines the priority of the above multiple SQL statements according to the historical execution time length of each SQL statement. The longer the historical execution time length of a SQL statement is, the higher the priority of the SQL statement is, that is, the historical execution time length of a SQL statement with high priority is greater than the historical execution time length of a SQL statement with low priority.

[0054] More specifically, the parallel device 200 can determine the historical execution time length of each SQL statement in the following manner: the parallel device 200 determines the historical execution time length of each SQL statement according to the matching relationship between each SQL statement and multiple SQL statement templates in the SQL statement library. When a certain SQL statement matches a certain SQL statement template, the historical execution time length of the SQL statement is determined to be the execution time length corresponding to the matching template. When a certain SQL statement does not match any of the SQL statement templates, the historical execution time length of the SQL statement is determined to be a preset time length. The preset time length can be set by a user or by the parallel device 200. For example, the parallel device 200 can set the preset time length to a value greater than the execution time length corresponding to all SQL statement templates.

[0055] Taking one SQL statement (hereinafter referred to as "SQL statement 1") and one SQL statement template (hereinafter referred to as "SQL statement template 1") as an example, the parallel device 200 can determine the matching relationship between the two in the following manner: the parallel device 200 determines the input parameter values in the SQL statement 1 by parsing the SQL statement 1, and then deletes the input parameter values in the SQL statement 1 to obtain a processed SQL statement 1. Similarly, the parallel device 200 determines the placeholders in the SQL statement template 1 by parsing the SQL statement template 1, and then deletes the placeholders in the SQL statement template 1 to obtain a processed SQL statement template 1. Then, the parallel device 200 embeds the processed SQL statement 1 and the processed SQL statement template 1 into a vector space using a word embedding model to obtain a vector corresponding to the processed SQL statement 1 and a vector corresponding to the processed SQL statement template 1, and then calculates the similarity between the two vectors. When the similarity between the two vectors is greater than a similarity threshold, it means that the SQL statement 1 and the SQL statement template 1 match; otherwise, when the similarity between the two vectors is less than or equal to the similarity threshold, it means that the SQL statement 1 and the SQL statement template 1 do not match.

[0056] Optionally, for the SQL statement that does not match all the SQL statement templates, the parallel device 200 can further obtain the execution duration of the SQL statement after the execution of the SQL statement is completed, and delete the input parameter values in the SQL statement to obtain a corresponding SQL statement template. Then, the parallel device 200 adds the obtained SQL statement template and the corresponding execution duration to the SQL statement library.

[0057] Step 103, the parallel device 200 puts the plurality of SQL statements obtained above into a to-be-executed queue according to the priority of the SQL statements.

[0058] Specifically, the parallel device 200 initializes the to-be-executed queue, and the length of the to-be-executed queue can be set by the user or dynamically adjusted by the parallel device 200. For example, the parallel device 200 can dynamically adjust the length of the to-be-executed queue according to the parallelism of the database system 100, wherein when the parallelism of the database system 100 is greater than the current length of the to-be-executed queue, the length of the to-be-executed queue can be increased; when the parallelism of the database system 100 is less than the current length of the to-be-executed queue, and the difference between the two is large, the length of the to-be-executed queue can be shortened. Then, the parallel device 200 writes the SQL statements into the to-be-executed queue in order of priority from high to low, wherein the SQL statements with higher priority are preferentially put into the to-be-executed queue. When the to-be-executed queue is full, the SQL statements are waited (i.e., not put into the to-be-executed queue).

[0059] As can be known from step 101, the parallel device 200 can lock a scan thread for scanning the SQL statements not executed in the database system 100, and in this case, the parallel device 200 further unlocks the scan thread after the plurality of SQL statements are put into the execution queue, so that other instances can read the SQL statements.

[0060] Through steps 101 to 103, the parallel device 200 can put the SQL statements not executed in the database system 100 into the execution queue. Next, the parallel device 200 can obtain the SQL statements not executed in the database system 100 from the execution queue and execute the SQL statements, and the specific execution process can be referred to FIG. 4 and the related description thereof. It can be understood that the higher the priority of the SQL statement is, the longer the execution time of the SQL statement is, and thus by putting the SQL statement with long execution time into the execution queue first, the database system 100 can execute the SQL statement with long execution time first. For the task including the SQL statement, the total critical path of the corresponding batch of SQL statements can be shortened, so that the execution efficiency of the task is improved.

[0061] Referring to FIG. 4, FIG. 4 shows a flowchart of a method for executing a SQL statement according to the present application. As shown in FIG. 4, the parallel device 200 can execute the SQL statement through the following steps.

[0062] In step 201, the parallel device 200 determines the IO load of the database system 100.

[0063] Specifically, the database system 100 provides a query interface of the IO load, so that the parallel device 200 can obtain the IO load of the database system 100 by calling the query interface. The IO load of the database system 100 is an index for characterizing the read-write performance of the database system 100, and specifically refers to the workload of input and output generated by the database system 100 when performing read and write operations. The IO load of the database system 100 can specifically include the input output operations per second (IOPS), the throughput (i.e., the amount of IO operations that the database system 100 can process in a unit of time), the response time (i.e., the time required by the database system 100 to respond to a SQL statement), the disk utilization rate (i.e., the proportion of the time length of the IO operation performed by the disk in the database system 100 in the total time length), the cache hit rate (i.e., the proportion of the amount of data read from the cache in the database system 100 in the total amount of data), and the like.

[0064] In step 202, the parallel device 200 determines the parallel degree of the database system 100 according to the IO load of the database system 100.

[0065] Specifically, the parallel device 200 pre-stores a correspondence between the IO load of the database system 100 and the parallelism of the database system 100, so that the parallel device 200 can determine the parallelism of the database system 100 according to the correspondence after determining the IO load of the database system 100.

[0066] The correspondence between the IO load of the database system 100 and the parallelism of the database system 100 can be represented by a chart or a calculation formula. The correspondence can be set by a user or by the parallel device 200 according to the performance and historical operation of the database system 100. For example, the historical operation of the database system 100 indicates that "when the IO load of the database system 100 reaches 40%, the database system 100 can execute at most 128 SQL statements in parallel", so that the parallel device 200 can determine that when the IO load of the database system 100 is 40%, the parallelism of the database system 100 is 128.

[0067] In an implementation manner, the parallel device 200 can periodically determine the IO load of the database system 100, and further periodically determine the parallelism of the database system 100.

[0068] In step 203, the parallel device 200 determines whether the parallelism of the database system 100 is greater than the number of SQL statements currently executed by the database system 100. If yes, step 204 is performed; if no, step 205 is performed.

[0069] In step 204, the parallel device 200 acquires P SQL statements from the to-be-executed queue, and executes the P SQL statements. P is the difference between the parallelism of the database system 100 and the number of SQL statements currently executed, and P is a positive integer greater than 0.

[0070] Specifically, the parallel device 200 pre-stores a thread pool, and the thread pool includes a plurality of threads. Therefore, the parallel device 200 can acquire P idle threads from the thread pool, and the P threads can be randomly selected by the parallel device 200, can be selected according to the ID of the thread, or can be selected by the parallel device 200 in other manners, which are not limited by the present application. Then, the parallel device 200 submits the P SQL statements acquired from the to-be-executed queue to the P threads respectively, and then executes the P threads in parallel.

[0071] In step 205, when the number of executed SQL statements is less than or equal to P, the parallel device 200 does not acquire SQL statements from the to-be-executed queue. The execution includes execution success and execution failure.

[0072] The execution success means that the database system 100 does not have any error or exception during the execution of the SQL statement. The execution failure means that the database system 100 has an error during the execution of the SQL statement, or attempts to execute the SQL statement multiple times and each execution has an error, and the reason for the execution failure of the SQL statement can be one or more of the following: the database system 100 restarts, network exception, and SQL statement itself error (for example, syntax error, format error, etc.).

[0073] It can be understood that through the above steps 203 to 205, more SQL statements can be executed in parallel by the database system 100 without affecting the performance of the database system 100. On the other hand, since the parallel device 200 can also periodically determine the parallelism of the database system 100, the number of SQL statements executed in parallel by the database system 100 can also be dynamically adjusted according to the change of the parallelism of the database system 100 through the above method, thereby more flexibly and accurately improving the execution efficiency of the SQL statement.

[0074] In addition to the above steps 201 to 205, in order to further improve the execution efficiency of the SQL statement, the parallel device 200 can also perform the following steps: the parallel device 200 sends a prompt message of the execution failed SQL statement to the operation and maintenance personnel. The parallel device 200 can send the prompt message to the operation and maintenance personnel through short message, telephone, email and the like, and the prompt message can include at least one or more of the above execution failed SQL statement, the execution state of the SQL statement, the error information of the SQL statement, the task to which the SQL statement belongs, and the solution. In this way, the operation and maintenance personnel can be assisted to intervene in time.

[0075] In an implementation manner, the parallel device 200 can determine the above solution by the following manner: the parallel device 200 pre-stores an exception problem library, wherein the exception problem library includes a plurality of exception problems and a solution of each exception problem. Therefore, when the SQL statement fails to execute, the parallel device 200 can determine the solution corresponding to the execution failure of the SQL statement according to the matching relationship between the error information of the SQL statement and the plurality of exception problems in the exception problem library, that is, the solution of the matched exception problem.

[0076] The above generation method of the to-be-executed queue and the method of executing the SQL statement according to the to-be-executed queue provided by the present application are described in detail in combination with FIGS. 3 to 4, and the structure of the parallel device 200 executing the above method is described in combination with FIG. 5.

[0077] Referring to FIG. 5, FIG. 5 exemplarily shows a structural schematic diagram of the parallel device 200. It should be understood that in actual applications, the structure of the parallel device 200 can also have other divisions, which are not limited by the present application. As shown in FIG. 5, the parallel device 200 includes an obtaining module 201, a determining module 202, and an executing module 203.

[0078] The obtaining module 201 is configured to perform the steps 101-103 described above. The determining module 202 is configured to perform the steps 201-202 described above. The executing module 203 is configured to perform the steps 203-205 described above. Optionally, the obtaining module 201 is further configured to perform related steps of unlocking the scan thread. The executing module 203 is further configured to perform related steps of sending a prompt message of the failed SQL statement to the operation and maintenance personnel.

[0079] The obtaining module 201, the determining module 202, and the executing module 203 can be implemented by software or by hardware. Exemplarily, the implementation of the determining module 202 is introduced as an example. Similarly, the implementation of the obtaining module 201 and the executing module 203 can refer to the implementation of the determining module 202.

[0080] As an example of a software functional unit, the determining module 202 can include code running on a computing instance. The computing instance can include at least one of a physical host (computing device), a virtual machine, and a container. Further, the computing instance can be one or more. For example, the determining module 202 can include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code can be distributed in the same region, or can be distributed in different regions. Further, the multiple hosts / virtual machines / containers used to run the code can be distributed in the same availability zone (AZ), or can be distributed in different AZs, each AZ including one data center or multiple data centers with similar geographical locations. Generally, one region can include multiple AZs.

[0081] Similarly, the multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC), or can be distributed in multiple VPCs. Generally, one VPC is set in one region, and communication between two VPCs in the same region, or between VPCs in different regions, needs to set a communication gateway in each VPC to realize the interconnection between the VPCs through the communication gateway.

[0082] As an example of a hardware functional unit, the determining module 202 can include at least one computing device, such as a server or the like. Alternatively, the determining module 202 can also be implemented by using a central processing unit (CPU), an application-specific integrated circuit (ASIC), or through a programmable logic device (PLD). Among them, the PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), a data processing unit (DPU), a neural network processing unit (NPU), a system on chip (SoC), an offload card, an acceleration card, or any combination thereof.

[0083] The plurality of computing devices included in the determining module 202 can be distributed in the same region or in different regions. The plurality of computing devices included in the determining module 202 can be distributed in the same AZ or in different AZs. Similarly, the plurality of computing devices included in the determining module 202 can be distributed in the same VPC or in multiple VPCs. Among them, the plurality of computing devices included in the determining module 202 can be any combination of servers, ASICs, PLDs, CPLDs, FPGAs, GALs, DPUs, NPUs, SoCs, offload cards, acceleration cards, and the like.

[0084] It should be noted that in other embodiments, the obtaining module 201 can be configured to perform any of the steps of the above-described method of generating a to-be-executed queue and the method of executing a SQL statement, the determining module 202 can be configured to perform any of the steps of the above-described method of generating a to-be-executed queue and the method of executing a SQL statement, and the execution module 203 can be configured to perform any of the steps of the above-described method of generating a to-be-executed queue and the method of executing a SQL statement. The steps responsible for the implementation of the obtaining module 201, the determining module 202, and the execution module 203 can be specified according to actual needs, and the entire function of the parallel device 200 can be realized by realizing different steps in the above-described method of generating a to-be-executed queue and the method of executing a SQL statement through the obtaining module 201, the determining module 202, and the execution module 203 respectively.

[0085] The application also provides a computing device. The computing device can be a server, for example, a central server, an edge server, or a local server in a local data center. The computing device can also be a terminal device such as a desktop computer, a notebook computer, or a smart phone.

[0086] FIG. 6 exemplarily shows a structural schematic diagram of a computing device provided by the application. As shown in FIG. 6, the computing device 400 includes a bus 401, a processor 402, a memory 403, and a communication interface 404, and the processor 402, the memory 403, and the communication interface 404 communicate through the bus 401. It should be understood that the number of the processor 402 and the memory 403 in the computing device 400 is not limited by the application, and for the sake of simplicity, FIG. 6 describes one processor 402 and one memory 403.

[0087] The bus 401 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, a unified bus (UB), a compute express link (CXL), a cache coherent interconnect for accelerators (CCIX), etc., wherein the unified bus is also referred to as a coherent accelerated processor bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience, only one line is used in FIG. 6, but this does not mean that the computing device 400 has only one bus or only one type of bus. The bus 401 can include a path for transmitting information between various components (for example, the processor 402, the memory 403, and the communication interface 404) of the computing device 400.

[0088] The processor 402 can include any one or more of a CPU, a graphics processor (GPU), a microprocessor (MP), or a digital signal processor (DSP), an ASIC, an FPGA, a CPLD, an NPU, a SoC, an offload card, an acceleration card, or any other computing unit having computing capability.

[0089] The memory 403 can include volatile memory, such as random access memory (RAM) including a cache area for the temporary storage of data. The memory 403 also can include non-volatile memory, such as read only memory (ROM), EPROM, EEPROM, flash memory, or the like. Additionally, the memory 403 can be implemented using a storage class memory (SCM), phase change memory (PCM), or other types of storage media.

[0090] It is worth noting that the same type of storage medium can be configured to implement the memory 403 function in the same computing device, or two or more types of storage media can be configured to implement the memory 403 function, which is not limited in the present application.

[0091] The memory 403 stores executable program code. The processor 402 executes the executable program code to implement the functions of the above-mentioned obtaining module 201, determining module 202 and executing module 203 respectively, so as to implement the above-mentioned method for generating an execution queue and the method for executing an SQL statement. That is, the memory 403 stores instructions for executing the above-mentioned method for generating an execution queue and the method for executing an SQL statement.

[0092] The communication interface 404 uses a transceiver module such as, but not limited to, a network interface card, a transceiver, and the like to implement the communication between the computing device 400 and other devices or communication networks. For example, the computing device 400 communicates with a service system through the communication interface 404.

[0093] It should be understood that the computing device 400 provided according to the present application can correspond to the computing device 111 in the computing layer 110 of the above-mentioned database system 100, and the above-mentioned and other operations and / or functions of each module in the computing device 400 are respectively for implementing the corresponding flow of each method in FIGS. 3 and 4, which will not be described here for brevity.

[0094] The present application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. The computing device can also be a terminal device such as a desktop computer, a notebook computer, or a smart phone.

[0095] FIG. 7 exemplarily shows a structural diagram of a computing device cluster provided in the present application. As shown in FIG. 7, the computing device cluster 500 includes at least one computing device 400. The memory 403 of one or more computing devices 400 in the computing device cluster 500 can store the same instructions for executing the method for generating the to-be-executed queue and the method for executing the SQL statement.

[0096] In an implementation, the memory 403 of one or more computing devices 400 in the computing device cluster 500 can also respectively store partial instructions for executing the method for generating the to-be-executed queue and the method for executing the SQL statement, i.e., the combination of one or more computing devices 400 can collectively execute the method for generating the to-be-executed queue and the method for executing the SQL statement.

[0097] It should be noted that the memory 403 in different computing devices 400 in the computing device cluster 500 can also store different instructions for respectively executing partial functions of the parallel device 200. That is, the instructions stored in the memory 403 in different computing devices 400 can implement the functions of one or more of the obtaining module 201, the determining module 202, and the executing module 203.

[0098] In an implementation, the plurality of computing devices 400 in the computing device cluster 500 can be connected through a network, which can be a wide area network or a local area network, etc. FIG. 8 shows one possible implementation. As shown in FIG. 8, the computing device 400A and the computing device 400B are connected through a network. Specifically, the computing device 400A and the computing device 400B are connected to the network through the communication interfaces therein. In this implementation, the memory 403 in the computing device 400A and the memory 403 in the computing device 400B both store instructions for executing the functions of the obtaining module 201, the determining module 202, and the executing module 203.

[0099] The connection manner between the computing devices 500 shown in FIG. 8 can be considered in the scenario of high concurrency computing, for example, when there are multiple tasks, a part of the tasks included in the SQL statement can be executed by the computing device 400A, and another part of the tasks included in the SQL statement can be executed by the computing device 400B. It should be understood that the functions of the computing device 400A in FIG. 8 can also be completed by multiple computing devices 400, and similarly, the functions of the computing device 400B can also be completed by multiple computing devices 400.

[0100] It should be understood that the computing device cluster 500 provided according to the present application can correspond to the computing devices 111 in the computing layer 110 of the database system 100 described above, and the above and other operations and / or functions of the various modules in the computing device cluster 500 are respectively for implementing the corresponding flows of the various methods in FIGS. 3 and 4, and for brevity, will not be repeated here.

[0101] The present application also provides a computer program product containing instructions. The computer program product can be a software or program product containing instructions capable of running on a computing device or stored in any available medium. When the computer program product runs on the computing device, it causes the computing device to perform the method of generating an execution queue and the method of executing a SQL statement described above.

[0102] The present application also provides a computer readable storage medium. The computer readable storage medium can be any available medium that the computing device can store or a data storage device such as a data center containing one or more available media. The above available media can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk), etc. The computer readable storage medium includes instructions that instruct the computing device to perform the method of generating an execution queue and the method of executing a SQL statement described above.

[0103] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them. Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements to some technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the protection scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for executing Structured Query Language (SQL) statements, characterized in that, The method comprises: acquiring a plurality of SQL statements not executed by a database system and placing the plurality of SQL statements into an execution queue; periodically determining an input / output load of the database system and determining a parallel number of SOL statements executed in parallel by the database system; when the parallel number is greater than a number of SQL statements currently executed in parallel, then acquiring from the execution queue a difference between the parallel number and the number of SQL statements currently executed in parallel and executing the difference; and when the parallel number is less than the number of SQL statements currently executed in parallel, then after a difference between the parallel number and the number of SQL statements currently executed in parallel is executed, not acquiring a SQL statement from the execution queue.

2. The method of claim 1, wherein, The placing of the plurality of SQL statements into the execution queue comprises: determining priorities of the plurality of SQL statements and placing SQL statements with higher priorities into the execution queue first.

3. The method of claim 1, wherein: the acquiring of the plurality of SQL statements comprises: scanning, by a scanning thread, for SQL statements not executed by the database system and locking the scanning thread; and the method further comprises: after the placing of the plurality of SQL statements into the execution queue, unlocking the scanning thread.

4. The method of claim 1, wherein, The length of the execution queue can be adjusted.

5. The method of claim 1, wherein, The acquiring of the plurality of SQL statements not executed by the database system comprises: periodically acquiring a SQL statement from the database system and waiting when the execution queue is full.

6. The method of claim 2, wherein, The determining of the priorities of the plurality of SQL statements comprises: determining, according to a SQL statement library, a historical execution duration of each SQL statement in the plurality of SQL statements, wherein the SQL statement library comprises a plurality of SQL statement templates and a corresponding execution duration of each SQL statement template, and the historical execution duration of a SQL statement is the corresponding historical execution duration of a matched SQL statement template; and determining, according to the historical execution durations of the plurality of SQL statements, the priorities of the plurality of SQL statements, wherein a SQL statement with a higher priority has a greater historical execution duration than a SQL statement with a lower priority.

7. A parallel device, characterized by The apparatus comprises: an acquiring module configured to acquire a plurality of SQL statements not executed by a database system and place the plurality of SQL statements into an execution queue; a determining module configured to periodically determine an input / output load of the database system and determine a parallel number of SOL statements executed in parallel by the database system; an executing module configured to, when the parallel number is greater than a number of SQL statements currently executed in parallel, acquire from the execution queue a difference between the parallel number and the number of SQL statements currently executed in parallel and execute the difference, and when the parallel number is less than the number of SQL statements currently executed in parallel, after a difference between the parallel number and the number of SQL statements currently executed in parallel is executed, not acquire a SQL statement from the execution queue.

8. A database system, characterized by comprising a storage device and a computing device; the storage device, configured to store a plurality of SQL statements that are not executed; the computing device, comprising a processor and a memory, the processor configured to execute instructions in the memory to cause the computing device to perform the operational steps of the method of any one of claims 1 to 6.

9. A computer program product comprising instructions, characterized in that, a computer program product tangibly embodied in a non-transitory machine readable storage medium containing instructions that, when executed, cause a computing device to perform the operational steps of the method of any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that, computer program instructions, which, when executed by a computing device, cause the computing device to perform the operational steps of the method of any one of claims 1 to 6.

Citation Information

Patent Citations

  • SQL statement control method and device

    CN113961586A

  • Data processing task scheduling method and device

    CN117742907A

  • Database query task asynchronous management method and device and computer equipment

    CN118567856A

  • Database grouping set query

    US20140067794A1

  • Parallel Transfer of SQL Data to Software Framework

    US20170109420A1