A query optimization method, device, equipment, storage medium and program product
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD
- Filing Date
- 2026-02-12
- Publication Date
- 2026-06-09
AI Technical Summary
In traditional database query schemes, the query optimization process consumes a lot of data transmission bandwidth and system memory.
By optimizing and rewriting the original query statement, introducing a vector computing power card for predicate processing planning and set communication path planning, generating multiple candidate execution plans, evaluating the cost of each candidate execution plan, and selecting the optimal execution plan for database query.
It effectively reduces data transmission bandwidth and memory consumption during query optimization, improving query execution efficiency and performance.
Smart Images

Figure CN122173527A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of cloud computing storage and query technology, and in particular to a query optimization method, apparatus, device, storage medium, and program product. Background Technology
[0002] Traditional database storage systems execute various user-initiated operations through database query statements. For example, data analysts rely on underlying database query languages, such as SQL (Structured Query Language), to write code (i.e., database query statements) to retrieve data from database tables.
[0003] In existing database query solutions, query statements need to be analyzed and optimized through algorithmic logic. During the analysis process, specific feature analysis procedures are performed on the query task, and a preset optimization algorithm is matched and executed. This process consumes a lot of data transmission bandwidth and increases system memory consumption. Summary of the Invention
[0004] To address the problems existing in the prior art, embodiments of the present invention provide a query optimization method, apparatus, device, storage medium, and program product, which can effectively reduce data transmission bandwidth consumption and memory consumption during the query optimization process.
[0005] In a first aspect, embodiments of the present invention provide a query optimization method, including: The original query statement is optimized and rewritten to obtain the target query statement; Based on the target query statement, a vector computing power card is introduced to perform predicate processing planning and set communication path planning, generating multiple candidate execution plans; Cost evaluation is performed on each of the candidate execution plans to obtain the execution cost of each candidate execution plan; A target execution plan is selected from among the candidate execution plans based on the execution cost, and the database is queried based on the target execution plan.
[0006] As an improvement to the above scheme, based on the target query statement, a vector computing power card is introduced to perform predicate processing planning and set communication path planning, generating multiple candidate execution plans, including: The target query statement is parsed using a query tree to obtain an initial logical execution plan; Based on the computing power resources of the vector computing power cards in the database, vector computing power card processing planning is performed on the predicates in the initial logic execution plan to obtain multiple predicate processing strategies; Based on the communication links between the vector computing power cards, communication link planning is performed on each of the predicate processing strategies to obtain multiple set communication path strategies; Based on the predicate processing strategy, the set communication path strategy, and several optional execution plans generated based on the initial logical execution plan, multiple candidate execution plans are generated.
[0007] As an improvement to the above scheme, based on the predicate processing strategy, the set communication path strategy, and several optional execution plans generated based on the initial logical execution plan, multiple candidate execution plans are generated, including: The predicate processing strategy, the set communication path strategy, and several optional execution plans are combined and enumerated to obtain several execution plan combinations; Adapt vectorized execution logic to the aggregate computation class materialized views involved in each of the execution plan combinations to generate multiple candidate execution plans.
[0008] As an improvement to the above scheme, a cost evaluation is performed on each of the candidate execution plans to obtain the execution cost of each candidate execution plan, including: Based on the table statistics of each candidate execution plan, calculate the basic execution cost of each operation in each candidate execution plan; Calculate the cost of aggregate communication based on the cost statistics generated by the vector computing power card aggregate communication; The execution cost of each candidate execution plan is calculated based on the base execution cost of each operation in each candidate execution plan and the set communication cost.
[0009] As an improvement to the above solution, the original query statement is optimized and rewritten to obtain the target query statement, including: Lexical and syntactic analysis are performed on the original query statement to construct a first abstract syntax tree; Based on the first abstract syntax tree, view expansion and subquery rewriting are performed to obtain the second abstract syntax tree; The query relations of the second abstract syntax tree are pushed down by predicates to obtain the target query statement.
[0010] As an improvement to the above solution, querying the database based on the target execution plan includes: Based on the GPU kernel functions, the target execution plan is converted into executable code; The executable code is synchronized to the execution node via set communication operations for database querying.
[0011] Secondly, embodiments of the present invention provide a query optimization apparatus, comprising: The optimization and rewriting module is used to optimize and rewrite the original query statement to obtain the target query statement; The execution plan generation module is used to generate multiple candidate execution plans by introducing a vector computing power card to perform predicate processing plan and set communication path planning based on the target query statement; The execution cost evaluation module is used to evaluate the cost of each of the candidate execution plans and obtain the execution cost of each candidate execution plan. The execution plan selection module is used to select a target execution plan from multiple candidate execution plans based on the execution cost, and query the database based on the target execution plan.
[0012] Thirdly, embodiments of the present invention provide a query optimization device, comprising: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the query optimization method as described in any one of the first aspects.
[0013] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the query optimization method as described in any one of the first aspects.
[0014] Fifthly, embodiments of the present invention provide a computer program product, including a computer program or instructions, which, when executed by a processor, implement the query optimization method as described in any one of the first aspects.
[0015] Compared to existing technologies, the query optimization method, apparatus, device, storage medium, and program product provided in this embodiment of the invention optimizes and rewrites the original query statement to obtain a target query statement; then, based on the target query statement, a vector computing power card is introduced to perform predicate processing planning and set communication path planning to generate multiple candidate execution plans; subsequently, the cost of each candidate execution plan is evaluated to obtain the execution cost of each candidate execution plan; finally, a target execution plan is selected from the multiple candidate execution plans based on the execution cost, and the database is queried based on the target execution plan; this embodiment of the invention introduces a vector computing power card for predicate processing planning and set communication path planning in the candidate execution plan generation stage, which can effectively reduce the data transmission bandwidth consumption and memory consumption in the query optimization process. Attached Figure Description
[0016] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart of a query optimization method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the overall process of query optimization provided in the embodiments of the present invention; Figure 3 This is a structural block diagram of a query optimization device provided in an embodiment of the present invention; Figure 4 This is a structural block diagram of a query optimization device provided in an embodiment of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. 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 are within the scope of protection of the present invention.
[0019] It is understood that the various numerical designations used in the embodiments of this invention are merely for descriptive convenience and are not intended to limit the scope of this application. The order of the process numbers does not imply the order of execution; the execution order of each process should be determined by its function and internal logic.
[0020] In embodiments of the invention, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, without necessarily requiring or implying any such actual relationship or order between these entities or operations. The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising" does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element. The term "a plurality or several" refers to two or more.
[0021] The following explains some terms and concepts involved in the embodiments of the present invention.
[0022] Query optimizer: A built-in database software module used to determine the SQL access request data and generate the best execution plan.
[0023] Cost optimization: The optimizer selects the plan with the lowest cost from all considered candidate plans. The optimizer uses available statistics to calculate the cost. For a specific query in a given environment, the cost calculation takes into account factors related to query execution.
[0024] Execution plan: A combination of steps to execute an SQL statement. Each step can be a data row physically retrieved from the database, or a data row prepared by the user who issued the statement.
[0025] Collective communication refers to the collaborative communication behaviors of multiple vector computing cards (such as GPUs) to complete parallel computing tasks of SQL queries, including batch data synchronization, transmission, and aggregation, according to a preset topology (such as point-to-point, ring, or tree).
[0026] See Figure 1 , Figure 1 This is a flowchart of a query optimization method provided in an embodiment of the present invention. The query optimization method specifically includes: S11: Optimize and rewrite the original query statement to obtain the target query statement; S12: Based on the target query statement, a vector computing power card is introduced to perform predicate processing plan and set communication path planning to generate multiple candidate execution plans; S13: Evaluate the cost of each candidate execution plan to obtain the execution cost of each candidate execution plan; S14: Select a target execution plan from the multiple candidate execution plans based on the execution cost, and query the database based on the target execution plan.
[0027] It should be noted that the query optimization method described in this embodiment of the invention can be executed by a data storage system. The overall process of the query optimization method described in this embodiment of the invention is as follows: Figure 2As shown, the process begins by parsing and rewriting the original input query statement (such as an SQL statement) to obtain the optimized target query statement. Then, statistical information (referred to as table statistics) of relevant tables related to the target query statement is collected to prepare for subsequent cost evaluation. Next, the computing resources of vector computing cards such as GPUs are utilized, and communication resources between computing cards such as PCI-E and NVLink are leveraged through aggregated communication. This is combined with operator programs for vector logic processing and communication network transmission. During the candidate execution plan generation stage, vector computing cards are introduced to perform predicate processing planning and aggregated communication path planning, generating multiple candidate execution plans. Finally, the cost of each candidate execution plan is evaluated, and the optimized target execution plan (referred to as the optimal plan) is selected from the multiple candidate execution plans based on the execution cost. Execution code is then generated from this target execution plan to implement the database query.
[0028] Specifically, the candidate execution plan with the lowest execution cost can be selected from multiple candidate execution plans as the target execution plan, so as to minimize the execution cost of querying data and reduce resource consumption.
[0029] This invention utilizes the computing resources of vector computing cards such as GPUs, and through aggregated communication, leverages the communication resources between computing cards such as PCI-E and NVLink. Combined with operator programs for vector logic processing and communication network transmission, it can accelerate the query union and aggregation process, improve network throughput and task response speed, thereby reducing data transmission bandwidth and memory consumption during query optimization.
[0030] In an optional embodiment, S11: The original query statement is optimized and rewritten to obtain the target query statement, including: Lexical and syntactic analysis are performed on the original query statement to construct a first abstract syntax tree; Based on the first abstract syntax tree, view expansion and subquery rewriting are performed to obtain the second abstract syntax tree; The query relations of the second abstract syntax tree are pushed down by predicates to obtain the target query statement.
[0031] For example, in this embodiment of the invention, the input original query statement (such as an SQL statement) undergoes syntax parsing (including lexical analysis and syntax analysis) to check the grammatical correctness of the original query statement; and if the original query statement is grammatically correct, a first abstract syntax tree of the original query statement is constructed based on the syntax parsing results. If there is a syntax error, an error message is triggered and the subsequent processing flow ends.
[0032] The first abstract syntax tree constructed above is expanded into a view and rewritten into subqueries, including constant expression calculation, equivalent predicate deduction, and removal of redundant expressions, to obtain an optimized second abstract syntax tree. Then, the query relations of the optimized second abstract syntax tree are pushed down with predicates to obtain the efficient target query statement.
[0033] The embodiments of the present invention perform syntax parsing and query rewriting on the original SQL statement, which can reduce unnecessary calculations and intermediate result set size in advance within the database engine, significantly reducing data traffic transmission between nodes during query execution, thereby reducing the consumption of network bandwidth and memory resources.
[0034] In an optional embodiment, S12: Based on the target query statement, a vector computing power card is introduced to perform predicate processing planning and set communication path planning, generating multiple candidate execution plans, including: The target query statement is parsed using a query tree to obtain an initial logical execution plan; Based on the computing power resources of the vector computing power cards in the database, vector computing power card processing planning is performed on the predicates in the initial logic execution plan to obtain multiple predicate processing strategies; Based on the communication links between the vector computing power cards, communication link planning is performed on each of the predicate processing strategies to obtain multiple set communication path strategies; Based on the predicate processing strategy, the set communication path strategy, and several optional execution plans generated based on the initial logical execution plan, multiple candidate execution plans are generated.
[0035] For example, based on the query tree of the target query statement, an initial logical execution plan can be generated through relational algebraization, including but not limited to: relational algebra operators (such as table scan, projection filtering, join, aggregation, set operations, etc.), operator dependencies and execution order, predicates, etc.
[0036] Based on the initial logical execution plan, considering different table join orders and access paths under full table scan and index scan, the join operations in the initial logical execution plan are joined in different ways such as nested loops, hash joins, and sorted merges to generate multiple optional execution plans; Simultaneously, based on the initial logical execution plan, considering the computing resources of the vector computing cards in the database (such as the number of GPUs and GPU utilization), vector computing card processing planning is performed on the predicates in the initial logical execution plan, generating multiple predicate processing strategies adapted to vector computation. This predicate processing strategy instructs the vector computing card allocation and processing method for each predicate in the initial logical execution plan, i.e., which predicates are assigned to which vector computing card for processing, and what processing method is used (how to filter in real-time, which data to filter, how to filter in parallel, etc.), to transform predicate judgments from scalar line-by-line processing to vector batch processing, improving execution efficiency. For example, selecting GPUs with GPU utilization below a set utilization threshold and evenly distributing predicates across all GPUs for execution, or assigning different types of predicates to different GPUs for processing, etc.
[0037] Considering the communication links between vector computing cards (such as PCI-E, NVLink), each predicate processing strategy is adapted to at least one communication link, i.e., the predicate processing strategy.
[0038] Then, the multiple optional execution plans, predicate processing strategies, and predicate processing strategies obtained above are combined. After filtering out unreasonable and invalid combinations (such as communication links and connection order mismatch, computing power and access path mismatch, etc.), combinations that conform to computing power / communication / traditional execution logic are obtained as candidate execution plans.
[0039] This invention introduces a vector computing power card for predicate processing planning and set communication path planning. On the one hand, it leverages the parallel processing advantage of the vector computing power card to improve predicate processing efficiency. On the other hand, it utilizes precise planning of communication links to reduce node transmission overhead, thereby optimizing the execution of database analytical queries using set communication and improving the overall execution performance of database analytical queries.
[0040] Specifically, based on the predicate processing strategy, the set communication path strategy, and several optional execution plans generated based on the initial logical execution plan, multiple candidate execution plans are generated, including: The predicate processing strategy, the set communication path strategy, and several optional execution plans are combined and enumerated to obtain several execution plan combinations; Adapt vectorized execution logic to the aggregate computation class materialized views involved in each of the execution plan combinations to generate multiple candidate execution plans.
[0041] For example, during the candidate execution plan generation stage, the materialized view of the aggregated computation involved can be converted into an aggregated computation materialized view during the materialized view execution. Then, the aggregated computation materialized view is converted and synchronized to the video memory using the existing storage structure. At the same time, the data columns of the aggregated computation materialized view are vectorized using computing power devices, and operators are called to complete the filtering and aggregation, so as to obtain the vectorized execution logic adapted to the aggregated computation materialized view and integrate it into the candidate execution plan.
[0042] The embodiments of the present invention can enrich the optimization dimensions of candidate plans and reduce query execution overhead by materializing view storage transformation, video memory synchronization, data column vectorization, and operator filtering and aggregation processing.
[0043] In an optional embodiment, S13: Cost evaluation is performed on each of the candidate execution plans to obtain the execution cost of each candidate execution plan, including: Based on the table statistics of each candidate execution plan, calculate the basic execution cost of each operation in each candidate execution plan; Calculate the cost of aggregate communication based on the cost statistics generated by the vector computing power card aggregate communication; The execution cost of each candidate execution plan is calculated based on the base execution cost of each operation in each candidate execution plan and the set communication cost.
[0044] In this embodiment of the invention, table statistics of candidate execution plans can be collected, including information such as table size, indexes, and column value distribution. Based on the table statistics of candidate execution plans, the basic execution cost of each operation in the candidate execution plan can be calculated, including CPU cost and I / O cost.
[0045] It should be noted that the calculation of CPU cost and I / O cost is existing technology and will not be described in detail here. For example, CPU cost refers to the computational cost of processing data in memory, which can be obtained by estimating the product of the number of tuples (rows) to be processed and the CPU cost per unit (row). Similarly, I / O cost refers to the cost of reading data from disk into memory, which can be obtained by estimating the product of the number of data pages (Page / Block) to be accessed and the I / O cost per page.
[0046] Furthermore, it can keep the table statistics updated in a timely manner. For example, for frequently changing data, relevant statistics can be collected regularly; and statistics can be manually created for key queries.
[0047] Simultaneously, it can collect cost statistics generated by the collective communication of vector computing cards such as GPUs, including data types to be processed (such as integer data, floating-point data, etc.), data volume, and the topology of the collective communication.
[0048] Based on the cost statistics generated by the ensemble communication of GPU and other vector computing cards, the cost of ensemble communication can be calculated, including computation cost and network transmission cost.
[0049] The computational cost is determined based on the data type and the amount of data. For example, different data types have different unit processing costs. The computational cost can be obtained by summing the products of the amount of data of different data types and their unit processing costs.
[0050] The cost of network transmission is determined by the topology transmission form generated by aggregated communication, and different topology transmission forms have different pre-set costs.
[0051] For each candidate execution plan, based on the CPU cost, I / O cost, and GPU ensemble communication cost (computation cost, network transmission cost) of each operation, combined with the memory space required for execution and the size of the intermediate result set set by the candidate execution plan, a cost evaluation of parallel execution is performed to obtain the total execution cost of the candidate execution plan. For example, the execution cost of the candidate execution plan is obtained by summing the CPU cost, I / O cost, GPU ensemble communication cost, network transmission cost, memory cost corresponding to the memory space required for execution (e.g., calculated as the sum of the products of the memory space required for execution and the unit processing cost), and cost corresponding to the size of the intermediate result set (e.g., calculated as the sum of the products of the size of the intermediate result set and the unit processing cost).
[0052] This invention integrates the traditional operation cost with the communication cost of vector computing cards such as GPUs in a distributed environment with vectorized hardware acceleration, thereby more accurately predicting and selecting the globally optimal query execution plan.
[0053] In one optional embodiment, querying the database according to the target execution plan includes: Based on the GPU kernel functions, the target execution plan is converted into executable code; The executable code is synchronized to the execution node via set communication operations for database querying.
[0054] The selected execution plan is converted into executable code and synchronized to the child execution nodes to begin execution.
[0055] For example, for the optimal target execution plan determined above, the kernel function of the GPU task generates a just-in-time compiled operator executable library (i.e., executable code), and uses the AllReduce and Broadcast functions of the set communication library to synchronize to the relevant execution nodes for database queries, and aggregates and returns the query results of all execution nodes, thus completing the database analytical query execution process optimized based on set communication.
[0056] Compared to existing technologies, this invention leverages the hardware resources of database nodes by integrating the private aggregate communication capabilities of computing cards (such as GPUs, NPUs, and FPGAs). This allows for more efficient use of hardware network capabilities, reducing host network card load and improving performance. In analytical database scenarios, it also reduces communication time between multiple nodes and improves response performance under traditional SQL execution.
[0057] Meanwhile, in the database query statement of the user-defined function, by introducing the vector computing power card for predicate processing plan and set communication path planning, it is possible to directly specify the use of database node computing power resources for processing, reduce the amount of data transmission under large model storage, and achieve a certain degree of integration of database storage and computing power functions, which can reduce the amount of business data and improve performance.
[0058] See Figure 3 , Figure 3 This is a structural block diagram of a query optimization device provided in an embodiment of the present invention. The query optimization device includes: The optimization and rewriting module 11 is used to optimize and rewrite the original query statement to obtain the target query statement; The execution plan generation module 12 is used to generate multiple candidate execution plans by introducing a vector computing power card to perform predicate processing plan and set communication path planning based on the target query statement; The execution cost evaluation module 13 is used to evaluate the cost of each of the candidate execution plans and obtain the execution cost of each of the candidate execution plans; The execution plan selection module 14 is used to select a target execution plan from a plurality of candidate execution plans based on the execution cost, and query the database based on the target execution plan.
[0059] In an optional embodiment, the execution plan generation module 12 includes: The parsing unit is used to parse the target query statement into a query tree to obtain an initial logical execution plan; The first planning unit is used to perform vector computing card processing planning on the predicates in the initial logic execution plan based on the computing power resources of the vector computing cards in the database, and obtain multiple predicate processing strategies. The second planning unit is used to plan the communication links for each of the predicate processing strategies based on the communication links between the vector computing cards, and obtain multiple set communication path strategies. The plan generation unit is used to generate multiple candidate execution plans based on the predicate processing strategy, the set communication path strategy, and several optional execution plans generated based on the initial logical execution plan.
[0060] In one optional embodiment, the plan generation unit includes: The combined enumeration subunit is used to combine and enumerate the predicate processing strategy, the set communication path strategy and several optional execution plans to obtain several execution plan combinations; The materialized view adaptation subunit is used to adapt vectorized execution logic to the aggregate calculation class materialized views involved in each of the execution plan combinations to generate multiple candidate execution plans.
[0061] In an optional embodiment, the execution cost evaluation module 13 includes: The first cost estimation unit is used to calculate the basic execution cost of each operation in each of the candidate execution plans based on the table statistics information of each candidate execution plan; The second cost estimation unit is used to calculate the cost of the aggregate communication based on the cost statistics generated by the vector computing card aggregate communication. The third cost estimation unit is used to calculate the execution cost of each candidate execution plan based on the basic execution cost of each operation in each candidate execution plan and the set communication cost.
[0062] In one optional embodiment, the optimized rewrite module 11 includes: The syntax parsing unit is used to perform lexical and syntactic analysis on the original query statement and construct a first abstract syntax tree; The query rewrite unit is used to perform view expansion and subquery rewriting based on the first abstract syntax tree to obtain the second abstract syntax tree. The predicate pushdown unit is used to push down the predicates of the query relations of the second abstract syntax tree to obtain the target query statement.
[0063] In an optional embodiment, the execution plan selection module 14 includes: The plan selection unit is used to select the candidate execution plan with the lowest execution cost from the multiple candidate execution plans as the target execution plan.
[0064] In an optional embodiment, the execution plan selection module 14 includes: An execution code conversion unit is used to convert the target execution plan into execution code based on GPU kernel functions; The code synchronization unit is used to synchronize the executable code to the execution node for database querying through set communication operations.
[0065] It should be noted that the working process of each module in the query optimization device described in the embodiments of the present invention can refer to the working process of the query optimization method described in the above embodiments, and the technical effect achieved is the same as that of the query optimization method described in the above embodiments, so it will not be repeated here.
[0066] See Figure 4 , Figure 4 This is a structural block diagram of the query optimization device provided in an embodiment of the present invention. The query optimization device includes a processor 21, a memory 22, and a computer program stored in the memory 22 and executable on the processor 21. When the processor 21 executes the computer program, it implements the steps in the various query optimization method embodiments described above, such as steps S11 to S14.
[0067] For example, the computer program may be divided into one or more modules or units, which are stored in the memory 22 and executed by the processor 21 to complete the present invention. The one or more modules or units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the query optimization device.
[0068] The query optimization device may include, but is not limited to, a processor 21 and a memory 22. Those skilled in the art will understand that the schematic diagram is merely an example of a query optimization device and does not constitute a limitation on the device. It may include more or fewer components than illustrated, or combine certain components, or use different components. For example, the query optimization device may also include input / output devices, network access devices, buses, etc.
[0069] The processor 21 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor 21 is the control center of the query optimization device, connecting all parts of the query optimization device via various interfaces and lines.
[0070] The memory 22 can be used to store the computer programs and / or modules. The processor 21 implements various functions of the query optimization device by running or executing the computer programs and / or modules stored in the memory 22 and calling the data stored in the memory 22. The memory 22 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory 22 may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0071] Wherein, if the modules or units integrated into the query optimization device are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by the processor 21, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.
[0072] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the device embodiments provided by this invention, the connection relationships between modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.
[0073] The above description represents the preferred embodiments of the present invention. It should be noted that, for those skilled in the art, various improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A query optimization method, characterized in that, include: The original query statement is optimized and rewritten to obtain the target query statement; Based on the target query statement, a vector computing power card is introduced to perform predicate processing planning and set communication path planning, generating multiple candidate execution plans; Cost evaluation is performed on each of the candidate execution plans to obtain the execution cost of each candidate execution plan; A target execution plan is selected from among the candidate execution plans based on the execution cost, and the database is queried based on the target execution plan.
2. The query optimization method as described in claim 1, characterized in that, Based on the target query statement, a vector computing power card is used to perform predicate processing planning and set communication path planning, generating multiple candidate execution plans, including: The target query statement is parsed using a query tree to obtain an initial logical execution plan; Based on the computing power resources of the vector computing power cards in the database, vector computing power card processing planning is performed on the predicates in the initial logic execution plan to obtain multiple predicate processing strategies; Based on the communication links between the vector computing power cards, communication link planning is performed on each of the predicate processing strategies to obtain multiple set communication path strategies; Based on the predicate processing strategy, the set communication path strategy, and several optional execution plans generated based on the initial logical execution plan, multiple candidate execution plans are generated.
3. The query optimization method as described in claim 2, characterized in that, Based on the predicate processing strategy, the set communication path strategy, and several optional execution plans generated based on the initial logical execution plan, multiple candidate execution plans are generated, including: The predicate processing strategy, the set communication path strategy, and several optional execution plans are combined and enumerated to obtain several execution plan combinations; Adapt vectorized execution logic to the aggregate computation class materialized views involved in each of the execution plan combinations to generate multiple candidate execution plans.
4. The query optimization method as described in claim 1, characterized in that, Cost evaluation is performed on each of the candidate execution plans to obtain the execution cost of each candidate execution plan, including: Based on the table statistics of each candidate execution plan, calculate the basic execution cost of each operation in each candidate execution plan; Calculate the cost of aggregate communication based on the cost statistics generated by the vector computing power card aggregate communication; The execution cost of each candidate execution plan is calculated based on the base execution cost of each operation in each candidate execution plan and the set communication cost.
5. The query optimization method as described in claim 1, characterized in that, The original query statement is optimized and rewritten to obtain the target query statement, including: Lexical and syntactic analysis are performed on the original query statement to construct a first abstract syntax tree; Based on the first abstract syntax tree, view expansion and subquery rewriting are performed to obtain the second abstract syntax tree; The query relations of the second abstract syntax tree are pushed down by predicates to obtain the target query statement.
6. The query optimization method as described in claim 1, characterized in that, Querying the database based on the target execution plan includes: Based on the GPU kernel functions, the target execution plan is converted into executable code; The executable code is synchronized to the execution node via set communication operations for database querying.
7. A query optimization device, characterized in that, include: The optimization and rewriting module is used to optimize and rewrite the original query statement to obtain the target query statement; The execution plan generation module is used to generate multiple candidate execution plans by introducing a vector computing power card to perform predicate processing plan and set communication path planning based on the target query statement; The execution cost evaluation module is used to evaluate the cost of each of the candidate execution plans and obtain the execution cost of each candidate execution plan. The execution plan selection module is used to select a target execution plan from multiple candidate execution plans based on the execution cost, and query the database based on the target execution plan.
8. A query optimization device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements the query optimization method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the query optimization method as described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by the processor, they implement the query optimization method according to any one of claims 1 to 6.