A method, device, and storage medium for performing plan generation

By generating an execution plan for SQL statements without grouping items, obtaining deduplication parameters, and determining the parallelism of subtasks, the problem of insufficient multi-threaded resource utilization in existing technologies is solved, improving the execution efficiency of SQL statements and reducing data copying overhead.

CN116628036BActive Publication Date: 2026-05-12SHANGHAI DAMENG DATABASE
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHANGHAI DAMENG DATABASE
Filing Date
2023-06-16
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In a distributed database environment, existing technologies cannot effectively utilize multi-threaded resources, resulting in low execution efficiency of aggregate function queries without GROUP BY and network communication overhead issues.

Method used

When generating the execution plan, for SQL statements with no grouping items and all query items being target aggregate functions, the deduplication parameters are obtained, and an execution plan including the operators and parallelism of each subtask is generated based on these parameters, and multi-threaded resources are used for processing.

Benefits of technology

With minimal modifications to the existing distributed execution framework, the efficiency of SQL statement execution is improved, unnecessary data copying overhead is avoided, and multi-threaded resources are fully utilized.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116628036B_ABST
    Figure CN116628036B_ABST
Patent Text Reader

Abstract

The application discloses an execution plan generation method and device, equipment and a storage medium. The method comprises the following steps: if there is no grouping item in an SQL statement, and all query items are target aggregation functions, obtaining a deduplication item parameter, wherein the target aggregation function is an aggregation function comprising a deduplication item; and generating an execution plan corresponding to the SQL statement according to the SQL statement and the deduplication item parameter, wherein the execution plan comprises an operator corresponding to each subtask and parallelism corresponding to each subtask. The execution plan provided by the application can be executed without introducing redundant data replication overhead under the condition that the existing distributed execution framework is slightly changed, and can fully utilize multi-thread resources to improve the execution efficiency of the SQL statement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an execution plan generation method, apparatus, device and storage medium. Background Technology

[0002] In a distributed database environment, there exist query statements like the one below that do not have GROUP BY and whose aggregate functions include DISTINCT.

[0003] First, create the table. The table creation statement is: create table t1(c1 int,c2 int,c3 int,id int)partition by hash(id)partitions 5;

[0004] Example 1:

[0005] select sum(distinct c1),count(distinct c2),sum(distinct c3)from t1;

[0006] Existing methods for handling aggregation functions containing multiple deduplicated items fall into two categories: the first is to aggregate the data in a single thread, and the second is to repeatedly send the parameter data of the aggregation function. The first method cannot fully utilize multi-threaded parallel optimization; the second method incurs additional network communication overhead. Summary of the Invention

[0007] This invention provides an execution plan generation method, apparatus, device, and storage medium. Executing the execution plan provided by this invention can improve the execution efficiency of SQL statements by making full use of multi-threaded resources with minimal modifications to the existing distributed execution framework, without introducing unnecessary data replication overhead.

[0008] According to one aspect of the present invention, an execution plan generation method is provided, comprising:

[0009] If there are no grouping items in the SQL statement and all query items are target aggregation functions, then the deduplication item parameter is obtained, wherein the target aggregation function is an aggregation function that includes deduplication items;

[0010] An execution plan is generated based on the SQL statement and the deduplication parameter, wherein the execution plan includes: the operator corresponding to each subtask and the parallelism corresponding to each subtask.

[0011] According to another aspect of the present invention, an execution plan generation apparatus is provided, the execution plan generation apparatus comprising:

[0012] The deduplication parameter acquisition module is used to acquire deduplication parameters if there are no grouping items in the SQL statement and all query items are target aggregation functions, wherein the target aggregation function is an aggregation function that includes deduplication items;

[0013] The execution plan generation module is used to generate an execution plan corresponding to the SQL statement based on the SQL statement and the deduplication parameter, wherein the execution plan includes: the operator corresponding to each subtask and the parallelism corresponding to each subtask.

[0014] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0015] At least one processor; and

[0016] A memory communicatively connected to the at least one processor; wherein,

[0017] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the execution plan generation method according to any embodiment of the present invention.

[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the execution plan generation method according to any embodiment of the present invention.

[0019] This invention provides an embodiment for SQL statements without grouping items, where all set functions include deduplication items. It generates an execution plan corresponding to the SQL statement based on the deduplication item parameters and the SQL statement, and executes the execution plan provided by this invention. This can improve the execution efficiency of SQL statements by making full use of multi-threaded resources without introducing extra data copying overhead, with minimal modifications to the existing distributed execution framework.

[0020] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0021] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 This is a flowchart of an execution plan generation method according to an embodiment of the present invention;

[0023] Figure 2 This is a schematic diagram of the execution plan in an embodiment of the present invention;

[0024] Figure 3 This is a schematic diagram of the structure of an execution plan generation device according to an embodiment of the present invention;

[0025] Figure 4 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0026] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0028] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.

[0029] Example 1

[0030] Figure 1 This is a flowchart illustrating an execution plan generation method provided in an embodiment of the present invention. This embodiment is applicable to the generation of execution plans. The method can be executed by the execution plan generation device in this embodiment, which can be implemented in software and / or hardware, such as... Figure 1 As shown, the method specifically includes the following steps:

[0031] S110, if there are no grouping items in the SQL statement and all query items are target aggregation functions, then obtain the deduplication item parameter, wherein the target aggregation function is an aggregation function that includes deduplication items.

[0032] It should be noted that the embodiments of the present invention are only for the execution plan generation method of specific SQL statements. That is, the execution plan can be generated in the following ways only if the SQL statement meets the following target conditions, wherein the target conditions include: 1. There are no grouping items in the SQL statement; 2. The query items of the SQL statement are all aggregate functions with DISTINCT.

[0033] Specifically, the method to obtain the deduplication parameters can be: collect the parameters of all DISTINCT items. For example, if the SQL statement is select sum(distinct c1),count(distinct c2),sum(distinct c3)fromt1, then the deduplication parameters include c1, c2 and c3.

[0034] S120, Generate an execution plan corresponding to the SQL statement based on the SQL statement and the deduplication parameter, wherein the execution plan includes: the operator corresponding to each subtask and the parallelism corresponding to each subtask.

[0035] The execution plan includes at least three subtasks, an operator for each subtask, and a degree of parallelism for each subtask.

[0036] Specifically, the method for generating the execution plan corresponding to the SQL statement based on the SQL statement and the deduplication parameters can be as follows: determine the target table based on the SQL statement; determine the number of subtasks, the parallelism of each subtask, and the operators corresponding to each subtask based on the target table, the available hardware resources of the node storing the target table, and the deduplication parameters; and generate the execution plan corresponding to the SQL statement based on the number of subtasks, the parallelism of each subtask, and the operators corresponding to each subtask. The method for generating the execution plan corresponding to the SQL statement based on the SQL statement and the deduplication parameters can be as follows: determine the target table based on the SQL statement; determine the parallelism of the first subtask based on the target table and the available hardware resources of the node storing the target table, wherein the first subtask includes a first dispatch operator; determine the parallelism of the second subtask based on the deduplication parameters and the available hardware resources of the node storing the target table, wherein the second subtask includes a first receive operator, a first aggregation operator, and a second dispatch operator; and determine the parallelism of the third subtask as a first value, wherein the third subtask includes a second receive operator and a second aggregation operator.

[0037] Understandably, if the SQL is a simple statement involving a single-table query followed by aggregation, it can be divided into three subtasks. If the SQL is slightly more complex, then there will be other subtasks before and after the above three subtasks.

[0038] In addition, the generation of the execution plan for an SQL statement also requires statistical information, various optimizer parameters, etc.

[0039] The technical solution of this embodiment is for SQL statements without grouping items and whose set functions all include deduplication items. It generates an execution plan corresponding to the SQL statement based on the deduplication item parameters and the SQL statement, and executes the execution plan provided by this embodiment of the invention. It can improve the execution efficiency of SQL statements by making full use of multi-threaded resources without introducing extra data copying overhead, with minimal changes to the existing distributed execution framework.

[0040] Optionally, an execution plan corresponding to the SQL statement is generated based on the SQL statement and the deduplication parameter, including:

[0041] Determine the target table based on the SQL statement;

[0042] The parallelism of the first subtask is determined based on the target table and the available hardware resources of the node storing the target table, wherein the first subtask includes: a first dispatch operator;

[0043] The parallelism of the second subtask is determined based on the deduplication parameters and the available hardware resources of the node storing the target table, wherein the second subtask includes: a first receive operator, a first aggregation operator, and a second dispatch operator;

[0044] The parallelism of the third subtask is determined to be a first value, wherein the third subtask includes: a second receive operator and a second aggregation operator.

[0045] The target table is the FROM parameter of the SQL statement. For example, if the SQL statement is select sum(distinct c1), count(distinct c2), sum(distinct c3) from t1, then the target table is t1.

[0046] The first subtask includes a first dispatch operator and may also include the identification information of the target table.

[0047] Specifically, the parallelism of the first subtask can be determined based on the target table and the available hardware resources of the node storing the target table.

[0048] Specifically, the method for determining the parallelism of the second subtask based on the deduplication parameters and the available hardware resources of the nodes storing the target table can be as follows: generate a target linked list based on the deduplication parameters, and determine the parallelism of the second subtask based on the length of the target linked list and the available hardware resources of the nodes storing the target table.

[0049] The first value can be 1.

[0050] In a specific example, such as Figure 2 As shown, the parallelism of the first subtask is 4. Subtask 1 includes: the first dispatch operator SEND1 and TABLE SCAN(t1). The parallelism of subtask 2 is 3*n (n is an integer >= 1). The second subtask includes: the second dispatch operator SEND2, the first aggregation operator AGGR FUNC, and the first receive operator RECV1. The third subtask includes: the second aggregation operator AGGR FUNC and the second receive operator RECV2.

[0051] It should be noted that if the SQL statement is `select sum(distinct c1),count(distinct c2),sum(distinct c3)from t1`, the first subtask is responsible for the "distribution" work in the "distribution-aggregation-summary-secondary aggregation" process. It executes on each node storing `t1`, and the parallelism of the first subtask is determined by the size of the `t1` table and available hardware resources (e.g., ...). Figure 2In the example, the parallelism of the first subtask is 4. The first dispatch operator SEND1 dispatches keys (c1), (c2), and (c3). For each row of data in TABLE SCAN, it is sent three times to the second subtask, RECV1. The second subtask is responsible for the "aggregation" work in "distribution-aggregation-summarization-secondary aggregation". Each thread performs a preliminary calculation of an aggregation function with the same DISTINCT parameter. If the parallelism of the second subtask is 3, the parallel threads are worker A, worker B, and worker C. The aggregation operator corresponding to worker A processes the information sum(distinct c1); the aggregation operator corresponding to worker B processes the information count(distinct c2); and the aggregation operator corresponding to worker C processes the information sum(distinct c3). If the parallelism of the second subtask is 6, then the aggregation operator corresponding to worker A1 & A2 threads processes the information as sum(distinct c1); the aggregation operator corresponding to worker B1 & B2 threads processes the information as count(distinct c2); and the aggregation operator corresponding to worker C1 & C2 threads processes the information as sum(distinct c3). The third subtask is responsible for the last link in the "distribution-aggregation-summarization-secondary aggregation" process: "summarization-secondary aggregation". The parallelism of the third subtask is 1, and the second aggregation operator AGGR FUNC is responsible for the final data summarization and result assembly. The comparison of aggregation functions in the execution plan before and after processing is shown in Table 1:

[0052] Table 1

[0053] Original aggregation in user query Functions of secondary aggregation sum(c) sum (one-stage aggregate sum result) count(c) sum(one-stage aggregated count result)

[0054] Optional, also includes:

[0055] The first subtask, the second subtask, and the third subtask are executed sequentially to obtain the target execution result.

[0056] Specifically, the first subtask, the second subtask, and the third subtask are executed sequentially to obtain the target execution result. This can be achieved by: sending data based on the first subtask, performing initial aggregation on the received data based on the second subtask, and summarizing and performing secondary aggregation on the data obtained after the initial aggregation based on the third subtask.

[0057] Optionally, the first subtask, the second subtask, and the third subtask are executed sequentially to obtain the target execution result, including:

[0058] The data to be sent corresponding to each deduplication parameter is determined based on the target table and the deduplication parameter.

[0059] According to the first subtask, the data to be sent corresponding to each deduplication parameter is sent to the receiving thread corresponding to each deduplication parameter.

[0060] Each receiving thread performs an initial aggregation on the received data, obtaining the initial aggregation result for each receiving thread.

[0061] Based on the third subtask, the initial aggregation result corresponding to each receiving thread is aggregated a second time to obtain the target execution result corresponding to the SQL statement.

[0062] Specifically, the method for determining the data to be sent corresponding to each deduplication parameter based on the target table and the deduplication parameter can be as follows: The data to be sent corresponding to each deduplication parameter is determined based on the parallelism of the first subtask, the target table, and the deduplication parameter. For example, if the SQL statement is `select sum(distinct c1),count(distinct c2),sum(distinct c3)from t1`, then for each row of data in table t1, it is sent to the second subtask in three separate steps.

[0063] Specifically, the method for sending the data to be sent corresponding to each deduplication parameter to the corresponding receiving thread according to the first subtask can be as follows: obtain the hash fold value of each deduplication parameter; determine the receiving thread corresponding to each deduplication parameter based on the hash fold value; and then send the data to be sent corresponding to each deduplication parameter to the corresponding receiving thread according to the first subtask. For example, if the parallelism of the second subtask is 3, then assume the threads are worker A, worker B, and worker C. Send the data to be sent corresponding to deduplication parameter c1 to worker A, the data to be sent corresponding to deduplication parameter c2 to worker B, and the data to be sent corresponding to deduplication parameter c3 to worker C.

[0064] Specifically, each receiving thread performs an initial aggregation on the received data, obtaining its corresponding initial aggregation result. For example, worker A's aggregation operator might be `sum(distinct c1)`, worker B's might be `count(distinct c2)`, and worker C's might be `sum(distinct c3)`. Based on worker A's processing of `sum(distinct c1)`, its initial aggregation result is obtained; based on worker B's processing of `count(distinct c2)`, its initial aggregation result is obtained; and based on worker C's processing of `sum(distinct c3)`, its initial aggregation result is obtained.

[0065] Specifically, the method for performing secondary aggregation on the first aggregation result corresponding to each receiving thread based on the third subtask to obtain the target execution result corresponding to the SQL statement can be as follows: determine the secondary aggregation function based on the third subtask and the SQL statement, and perform secondary aggregation on the first aggregation result corresponding to each receiving thread based on the secondary aggregation function to obtain the target execution result corresponding to the SQL statement.

[0066] Optionally, before sending the data to be sent corresponding to each deduplication parameter to the receiving thread corresponding to each deduplication parameter according to the first subtask, the method further includes:

[0067] Get the hash fold value of each deduplication parameter;

[0068] The receiving thread corresponding to each deduplication parameter is determined based on the hash fold value of each deduplication parameter.

[0069] It should be noted that when the dispatch operator SEND sends data, it sends the data to a specific thread according to the hash value of the distinct column. In this way, the same data will always get the same hash fold and be sent to the same thread that calculates the aggregate function.

[0070] Optionally, the receiving thread corresponding to each deduplication parameter is determined based on the hash fold value of each deduplication parameter, including:

[0071] The number of parallel threads corresponding to each deduplication parameter is determined based on the parallelism of the second subtask and the number of deduplication parameters.

[0072] The receiving thread corresponding to each deduplication parameter is determined based on the number of parallel threads corresponding to each deduplication parameter and the hash fold value of each deduplication item parameter.

[0073] Specifically, the method for determining the number of parallel threads corresponding to each deduplication parameter based on the parallelism of the second subtask and the number of deduplication parameters can be as follows: the ratio of the parallelism of the second subtask to the number of deduplication parameters is used to determine the number of parallel threads corresponding to each deduplication parameter.

[0074] It should be noted that if the parallelism of the second subtask is 3, the parallel threads are worker A, worker B, and worker C. The aggregation operator for worker A processes the information as sum(distinct c1); the aggregation operator for worker B processes the information as count(distinct c2); and the aggregation operator for worker C processes the information as sum(distinct c3). If the parallelism of the second subtask is 6, then based on the parallelism of the second subtask being 6 and the number of deduplication parameters being 3, the number of parallel threads corresponding to each deduplication parameter is determined to be 2. That is, the aggregation operator for worker A1 & A2 processes the information as sum(distinct c1); the aggregation operator for worker B1 & B2 processes the information as count(distinct c2); and the aggregation operator for worker C1 & C2 processes the information as sum(distinct c3).

[0075] Optionally, based on the third subtask, a second aggregation is performed on the initial aggregation result corresponding to each receiving thread to obtain the target execution result corresponding to the SQL statement, including:

[0076] The secondary aggregation function is determined based on the initial aggregation result corresponding to each receiving thread;

[0077] Based on the second aggregation function, the first aggregation result corresponding to each receiving thread in the second subtask is aggregated again to obtain the target execution result corresponding to the SQL statement.

[0078] Specifically, the method for determining the secondary aggregation function based on the first aggregation result corresponding to each receiving thread can be as follows: the secondary aggregation function is determined based on the first aggregation function and the first aggregation result corresponding to each receiving thread. For example, if the first aggregation function is sum(c), then the secondary aggregation function is sum(first aggregation sum result); if the first aggregation function is count(c), then the secondary aggregation function is sum(first aggregation count result).

[0079] In a specific example, the execution plan generation process includes:

[0080] 1. Determine if optimization is possible. A SQL statement is considered optimizable if it meets the following conditions, and proceeds to step 2 for further processing:

[0081] No grouping items;

[0082] The query terms are all aggregate functions with DISTINCT.

[0083] 2. Mark the first send operator (SEND) and the corresponding receive operator (RECV), and execute using an optimized "distribution-aggregation-summarization-secondary aggregation" approach. Collect all DISTINCT parameters (collecting only once for identical parameters) to obtain a linked list L, and set the distribution information for SEND based on this linked list.

[0084] The parallelism of the subtask in which the first aggregation occurs is length(L)*n (n is an integer >= 1, which is related to the actual available hardware resources). The parallelism is calculated from the size of the data to be processed and the available hardware resources, which will not be elaborated here.

[0085] 3. Based on the parallelism of the subtask containing "aggregation", set the aggregation function to be executed by each thread. Each worker thread of the aggregation subtask only processes the aggregation function for a specific distinct column parameter.

[0086] For parallelism length(L)*n, the AGGR FUNC operator in the i-th worker thread is the aggregate function involved in processing the parameters of the i / n-th node in L, where the value of i is in the range [0, n).

[0087] The aggregation operator AGGR FUNC is used to compute ungrouped aggregation functions. During computation, it iterates through the received data and outputs the result according to the definition of the aggregation function.

[0088] 4. The output of the aggregation operator AGGR FUNC for the first "aggregation" is (nth_distinct, aggr_func(distintct)), where nth_distinct represents the nth distinct parameter in the original query term. When the distinct parameter appears multiple times in the original query term, the first occurrence number is used, and the value of the number ranges from [0, length(L)). aggr_func(distintct) represents the aggregation function in the original query corresponding to the distinct parameter.

[0089] For example, in the SQL statement `select sum(distinct c1),count(distinct c1),avg(distinct c1),sum(distinct c2)from t1`, c1 appears multiple times. The first occurrence is numbered 0, so it is the 0th distinct parameter. The first occurrence of c2 is numbered 1, so it is the 1st distinct parameter. The initial "aggregate" output has 4 items: (0,sum(distinct c1)), (0,count(distinct c1)), (0,avg(distinct c1)), (1,sum(distinct c2)).

[0090] During "secondary aggregation," the aggregation operator AGGR FUNC summarizes identical nth_distinct values. Depending on the definition of different aggregation functions, this can be handled as follows:

[0091] Sum(distinct c1)→sum(sum(distinct c1));

[0092] Count(distinct c1)→sum(count(distinct c1)).

[0093] In another specific example, the send operator SEND and the aggregation operator AGGR FUNC are modified. The dispatch operator SEND, which belongs to the first "dispatch" in "dispatch-aggregation-summary-secondary aggregation", is modified as follows:

[0094] For the data DATA to be sent, determine the number of threads corresponding to the second subtask when calculating each aggregation function, n_dest = parallelism of the target subtask / length(L); where n_dest is the number of threads corresponding to each deduplication parameter.

[0095] for(each row D i in D), where D i This refers to one data point in the data to be sent, D.

[0096] for(each node L i in L), where i∈[0,length(L));

[0097] calc hash fold(L i ),send Calculate the hashfold value of each deduplication parameter to ensure that identical deduplication parameters are sent to the same thread.

[0098] As can be seen from the above sending steps, the SEND operator only sends the distinct column L in the node for the thread of the second subtask. i .

[0099] When sending data, the SEND operator sends the data to a specific thread based on the hash value of the distinct column. This ensures that identical data will always receive the same hash fold and be sent to the same thread that calculates the aggregate function.

[0100] The AGGR FUNC operator, which belongs to "secondary aggregation" in "distribution-aggregation-summarization-secondary aggregation", is modified as follows:

[0101] Based on the received initial aggregation result (nth_distinct, aggr_func(distintct)), the aggregation results with the same nth_distinct are merged to obtain the final result. For example: assuming the parallelism of the second subtask is 6, during the initial aggregation, each distinct set function has two threads: workers A and B are responsible for receiving input data; for the set function sum(distinct c1):

[0102] Worker A receives c1 data (1,3,1,5,7,9,5) from multiple sources → sum(distinct c)=1+3+5+7+9=25, and outputs (0,25), meaning that the result of the 0th distinct parameter is 25;

[0103] Worker B receives c1 data from multiple sources (2,8,0,6,0,8,10,2) → sum(distinct c)=0+2+6+8+10=26, and outputs (0,26), meaning that the result of the 0th distinct parameter is 26.

[0104] The aggregation operator AGGR FUNC in the third subtask receives the same 0th distinct result, 25 and 26, from two threads. It adds them together to get the final sum(distinct c) = 25 + 26 = 51.

[0105] Example 2

[0106] Figure 3 This is a schematic diagram of an execution plan generation device provided in an embodiment of the present invention. This embodiment is applicable to execution plan generation. The device can be implemented using software and / or hardware, and can be integrated into any device that provides execution plan generation functionality, such as… Figure 2As shown, the execution plan generation device specifically includes: a deduplication parameter acquisition module 210 and an execution plan generation module 220.

[0107] The deduplication parameter acquisition module is used to acquire deduplication parameters if there are no grouping items in the SQL statement and all query items are target aggregation functions. The target aggregation function is an aggregation function that includes deduplication items.

[0108] The execution plan generation module is used to generate an execution plan corresponding to the SQL statement based on the SQL statement and the deduplication parameter, wherein the execution plan includes: the operator corresponding to each subtask and the parallelism corresponding to each subtask.

[0109] The above-described products can perform the methods provided in any embodiment of the present invention, and have the corresponding functional modules and beneficial effects for performing the methods.

[0110] Example 3

[0111] Figure 4 A schematic diagram of an electronic device 10 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0112] like Figure 4 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0113] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0114] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as executing plan generation methods.

[0115] In some embodiments, the execution plan generation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the execution plan generation method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the execution plan generation method by any other suitable means (e.g., by means of firmware).

[0116] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0117] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0118] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0119] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0120] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0121] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0122] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0123] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A method for generating an execution plan, characterized in that, include: If there are no grouping items in the SQL statement and all query items are target aggregation functions, then the deduplication item parameter is obtained, wherein the target aggregation function is an aggregation function that includes deduplication items; An execution plan is generated based on the SQL statement and the deduplication parameter, wherein the execution plan includes: the operator corresponding to each subtask and the parallelism corresponding to each subtask; The process of generating an execution plan corresponding to the SQL statement based on the SQL statement and the deduplication parameter includes: Determine the target table based on the SQL statement; The parallelism of the first subtask is determined based on the target table and the available hardware resources of the node storing the target table, wherein the first subtask includes: a first dispatch operator; The parallelism of the second subtask is determined based on the deduplication parameters and the available hardware resources of the node storing the target table, wherein the second subtask includes: a first receive operator, a first aggregation operator, and a second dispatch operator; The parallelism of the third subtask is determined to be a first value, wherein the third subtask includes: a second receive operator and a second aggregation operator; The method further includes: The first subtask, the second subtask, and the third subtask are executed sequentially to obtain the target execution result; The process involves sequentially executing the first subtask, the second subtask, and the third subtask to obtain the target execution result, including: The data to be sent corresponding to each deduplication parameter is determined based on the target table and the deduplication parameter. According to the first subtask, the data to be sent corresponding to each deduplication parameter is sent to the receiving thread corresponding to each deduplication parameter. Based on the second subtask, the received data is aggregated for the first time to obtain the first aggregation result for each receiving thread; Based on the third subtask, the initial aggregation result corresponding to each receiving thread is aggregated a second time to obtain the target execution result corresponding to the SQL statement.

2. The method according to claim 1, characterized in that, Before sending the data to be sent corresponding to each deduplication parameter to the receiving thread corresponding to each deduplication parameter according to the first subtask, the process also includes: Get the hash fold value of each deduplication parameter; The receiving thread corresponding to each deduplication parameter is determined based on the hash fold value of each deduplication parameter.

3. The method according to claim 2, characterized in that, The receiving thread corresponding to each deduplication parameter is determined based on its hash fold value, including: The number of parallel threads corresponding to each deduplication parameter is determined based on the parallelism of the second subtask and the number of deduplication parameters. The receiving thread corresponding to each deduplication parameter is determined based on the number of parallel threads corresponding to each deduplication parameter and the hash fold value of each deduplication parameter.

4. The method according to claim 1, characterized in that, Based on the third subtask, a second aggregation is performed on the initial aggregation result corresponding to each receiving thread to obtain the target execution result corresponding to the SQL statement, including: The secondary aggregation function is determined based on the initial aggregation result corresponding to each receiving thread; Based on the second aggregation function, the first aggregation result corresponding to each receiving thread in the second subtask is aggregated again to obtain the target execution result corresponding to the SQL statement.

5. An execution plan generation device, characterized in that, include: The deduplication parameter acquisition module is used to acquire deduplication parameters if there are no grouping items in the SQL statement and all query items are target aggregation functions, wherein the target aggregation function is an aggregation function that includes deduplication items; An execution plan generation module is used to generate an execution plan corresponding to the SQL statement based on the SQL statement and the deduplication parameter, wherein the execution plan includes: the operator corresponding to each subtask and the parallelism corresponding to each subtask; Specifically, the execution plan generation module is used for: Determine the target table based on the SQL statement; The parallelism of the first subtask is determined based on the target table and the available hardware resources of the node storing the target table, wherein the first subtask includes: a first dispatch operator; The parallelism of the second subtask is determined based on the deduplication parameters and the available hardware resources of the node storing the target table, wherein the second subtask includes: a first receive operator, a first aggregation operator, and a second dispatch operator; The parallelism of the third subtask is determined to be a first value, wherein the third subtask includes: a second receive operator and a second aggregation operator; The first subtask, the second subtask, and the third subtask are executed sequentially to obtain the target execution result; The process involves sequentially executing the first subtask, the second subtask, and the third subtask to obtain the target execution result, including: The data to be sent corresponding to each deduplication parameter is determined based on the target table and the deduplication parameter. According to the first subtask, the data to be sent corresponding to each deduplication parameter is sent to the receiving thread corresponding to each deduplication parameter. Based on the second subtask, the received data is aggregated for the first time to obtain the first aggregation result for each receiving thread; Based on the third subtask, the initial aggregation result corresponding to each receiving thread is aggregated a second time to obtain the target execution result corresponding to the SQL statement.

6. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the execution plan generation method according to any one of claims 1-4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the execution plan generation method according to any one of claims 1-4.