Database execution plan generation method and device, equipment and storage medium
By building an execution cost model and dynamically adjusting the execution plan, it solves the problem of traditional query optimizers being difficult to adapt to data changes and changing query modes, improves query efficiency and user experience, and ensures the stability and elasticity of the system under high load.
Patent Information
- Application Number
- CN202410848965.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-10-01
AI Technical Summary
Traditional query optimizers are difficult to adapt to the actual situation of changing data distribution and changing query modes, resulting in suboptimal execution plans and affecting query response speed and resource utilization.
By obtaining the performance status information of the database, we build an execution cost model, dynamically adjust the execution plan, and optimize the target execution plan based on real-time workload data to ensure the optimal execution plan.
It significantly improves query processing efficiency, reduces response time, improves user experience, and can automatically adapt to changes in data distribution and diversity of query patterns, strengthening the stability and flexibility of the system under high load conditions.
Smart Images

Figure CN118733632A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of database management, and in particular to a method, device, equipment and storage medium for generating an execution plan of a database. Background Art
[0002] Currently, column storage databases such as Doris have demonstrated excellent performance in big data processing scenarios. However, traditional query optimizers mainly formulate execution plans based on static statistical information, which is often difficult to adapt to the actual situation where data distribution changes over time and query patterns change. This results in the execution plan being suboptimal, which in turn affects query response speed and resource utilization. In addition, static optimization strategies cannot effectively utilize resource status and load information during system operation, limiting the overall performance of the system. Summary of the invention
[0003] In view of the above problems, the present application provides a method, apparatus, device and storage medium for generating an execution plan for a database, which can significantly improve query processing efficiency and reduce response time, thereby improving user experience.
[0004] According to a first aspect of an embodiment of the present application, a method for generating an execution plan for a database is provided, the method comprising: obtaining performance status information of the database, the performance status information comprising current statistical data and current workload data; constructing an execution cost model of the database based on the current statistical data and the current workload data, so as to determine a target execution plan of the database based on the execution cost model; and during the process of the database executing the target execution plan, optimizing the target execution plan based on the current workload data to obtain an optimal execution plan.
[0005] In an optional manner, the method for optimizing the target execution plan based on the current workload data includes: obtaining estimated performance data and real-time performance data of the database executing the target execution plan based on the current workload data; if the difference between the real-time performance data and the estimated performance data of the target execution plan is greater than a preset deviation threshold, optimizing the target execution plan based on the real-time performance data.
[0006] In an optional manner, the method for optimizing the target execution plan based on the real-time performance data includes: obtaining the remaining tasks in the target execution plan at the current moment; and reallocating the remaining tasks based on the real-time performance data.
[0007] In an optional manner, the method further includes: acquiring real-time performance data generated in the process of obtaining the optimal execution plan; and updating the execution cost model based on the real-time performance data to obtain an updated execution cost model.
[0008] In an optional manner, the method for determining the target execution plan of the database based on the execution cost model includes: generating multiple preset execution plans in response to query requests received by the database; determining the preset execution plan with the lowest cost among the multiple preset execution plans based on the execution cost model, and using the execution cost plan with the lowest cost as the target execution plan.
[0009] In an optional manner, the method for obtaining performance status information of a database includes: monitoring resource usage data of the database to obtain real-time load data of the database; obtaining execution logs of the database at a preset frequency; and determining current workload data of the database based on the execution logs and the real-time load data.
[0010] In an optional manner, the method for obtaining performance status information of a database includes: triggering a data statistics task in the database at a preset frequency to obtain statistical information in the database; storing the statistical information in a preset data table format to obtain a metadata table; and determining current statistical data of the database based on the metadata table.
[0011] According to a second aspect of an embodiment of the present application, a device for generating an execution plan for a database is provided, the device comprising: a first acquisition module for acquiring performance status information of the database, the performance status information comprising statistical data and workload data; a construction module for constructing an execution cost model of the database based on the statistical data and the workload data, so as to determine a target execution plan of the database based on the execution cost model; a second acquisition module for acquiring the workload data of the database during the process of the database executing the target execution plan; and an optimization module for optimizing the target execution plan based on the workload data to obtain an optimal execution plan.
[0012] According to a third aspect of an embodiment of the present application, there is provided an electronic device, comprising: a controller; and a memory for storing one or more programs, wherein when the one or more programs are executed by the controller, the controller implements the above-mentioned method for generating an execution plan for a database.
[0013] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, wherein at least one executable instruction is stored in the storage medium. When the executable instruction is run on an execution plan generation device, the execution plan generation device of the database performs the operations of the execution plan generation method of the database as described above.
[0014] The execution plan generation method of the database of the present application first constructs an execution cost model of the database through statistical information and workload data; then, when the database responds to the input query request, the target execution plan for executing the query task is determined through the execution cost model; then, after the target execution plan is determined, and in the process of executing the target execution plan in the database, the workload data and execution log of the database are continuously obtained to optimize the target execution plan in real time when executing the target execution plan, and finally obtain the optimal execution plan. Therefore, the execution plan generation method of the database can dynamically adjust the target execution plan in the process of executing the target execution plan in the database, and then obtain the optimal execution plan, which ultimately significantly improves the query processing efficiency, reduces the response time, and improves the user experience; and it can automatically adapt to changes in data distribution and the diversity of query patterns, thereby maintaining the timeliness of the optimization plan and enhancing the stability and elasticity of the system under high load conditions.
[0015] The above description is only an overview of the technical solution of the embodiment of the present application. In order to more clearly understand the technical means of the embodiment of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiment of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings are only used to illustrate the embodiments and are not to be considered as limiting the present application. In addition, the same reference symbols are used to represent the same components throughout the accompanying drawings. In the accompanying drawings:
[0017] Figure 1 A schematic diagram of an implementation environment involved in an embodiment of the present application is shown.
[0018] Figure 2 A schematic flowchart of a method for generating an execution plan provided in an embodiment of the present application is shown.
[0019] Figure 3 A logical schematic block diagram of an execution plan generation method provided in an embodiment of the present application is shown.
[0020] Figure 4 A schematic diagram of the structure of an execution plan generation device provided in an embodiment of the present application is shown.
[0021] Figure 5 It is a structural diagram of a computer system of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0022] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0023] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0024] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0025] The term "multiple" as used in this application refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0026] First of all, it should be noted that the execution plan generation method of the database of this application is applied to the Apache Doris distributed database. Among them, Apache Doris is a high-performance, real-time analytical database based on the MPP architecture. It is well-known for its extremely fast and easy-to-use characteristics. It only takes sub-second response time to return query results under massive data. It can not only support high-concurrency point query scenarios, but also support high-throughput complex analysis scenarios. Based on this, Apache Doris can better meet the use scenarios such as report analysis, instant query, unified data warehouse construction, data lake federated query acceleration, etc. Users can build user behavior analysis, AB experimental platform, log retrieval analysis, user portrait analysis, order analysis and other applications on it.
[0027] Secondly, in terms of usage interface, Doris adopts the MySQL protocol, is highly compatible with MySQL syntax, supports standard SQL, and users can access Dorls through various client tools, and supports seamless docking with BL tools.
[0028] Furthermore, in terms of storage engine, Doris uses column storage, encodes, compresses and reads data by column, which can achieve extremely high compression ratios, while reducing the scanning of a large amount of non-related data, thereby making more efficient use of IO and CPU resources. In addition, Doris also supports a relatively rich index structure to reduce data scanning: it supports Sorted CompoundKeyIndex, which can specify up to three columns to form a composite sort key. Through this index, data can be effectively trimmed, thereby better supporting high-concurrency reporting scenarios.
[0029] For example, Z-order Index: Using Z-order index, you can efficiently perform range queries on any combination of fields in the data model. MIn / Max index: Effectively filter equal values and range queries of numeric types. Bloom Filter: Very effective for equal value filtering and pruning of high cardinality columns. Invert Index: Enables fast retrieval of any field.
[0030] Furthermore, in terms of storage models, Doris supports multiple storage models and makes targeted optimizations for different scenarios.
[0031] For example, Aggregate Key model: Value columns with the same key are merged, and performance is greatly improved by pre-aggregation. Unique Key model: Key is unique, and data with the same key is overwritten to achieve row-level data updates. DuplicateKey model: Detailed data model, which meets the detail storage of fact tables. Doris also supports strongly consistent materialized views. The update and selection of materialized views are automatically performed in the system, without the need for manual selection by users, which greatly reduces the cost of materialized view maintenance.
[0032] In addition, Doris also supports strongly consistent materialized views. The update and selection of materialized views are automatically performed within the system, without the need for manual selection by users, thereby greatly reducing the cost of materialized view maintenance.
[0033] Furthermore, in terms of query engine, Doris adopts the MPP model, which executes in parallel both between nodes and within nodes, and also supports distributed Shufie Join of multiple large tables, so that it can better cope with complex queries.
[0034] See also Figure 1 , Figure 1 3 is a schematic diagram of an implementation environment involved in an embodiment of the present application. The implementation environment includes a terminal 310 and a server 320, wherein the terminal 310 and the server 320 communicate via wired or wireless means.
[0035] Specifically, the server 320 can be used to receive the query request sent by the terminal 310, and process the query request of the terminal 310 (for example: query syntax parsing and semantic analysis, query planning and optimization), and finally obtain the optimal execution plan and send it to the terminal 310.
[0036] It should be noted that the terminal 310 can be any electronic device that supports the execution plan generation function of the database, such as a smart phone, a tablet computer, a laptop computer, or a wearable device, but is not limited thereto. For example, the terminal 310 can also be a vehicle-mounted terminal, an aircraft, or other equipment used in special fields. The terminal 310 can communicate with the server 320 via wireless networks such as 3G (third generation mobile information technology), 4G (fourth generation mobile information technology), and 5G (fifth generation mobile information technology), or communicate with the server 320 via a wired network, and this is not limited here.
[0037] Server 320 can be, for example, an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), as well as big data and artificial intelligence platforms, and there is no limitation here.
[0038] It should be understood that cloud technology refers to a hosting technology that unifies hardware, software, network and other resources within a wide area network or local area network to achieve data computing, storage, processing and sharing. Cloud technology is also a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model application, which can form a resource pool and be used on demand, flexibly and conveniently.
[0039] Figure 2 A schematic flow chart of a method for generating an execution plan provided in an embodiment of the present application is shown. Figure 3 FIG. 1 is a logic schematic diagram of a method for generating an execution plan provided by an embodiment of the present application. Figure 2 and Figure 3 As shown, this embodiment provides a method for generating an execution plan for a database, and the method for generating an execution plan for a database is executed by a device for generating an execution plan for a database 200. The method is applied to an adaptive query optimization device in a Doris distributed database system, and improves the efficiency and flexibility of query processing by integrating a data analysis algorithm with a real-time monitoring mechanism.
[0040] S100: The method for generating an execution plan for a database includes: initialization of the database and environment preparation. That is, when the database is started, the monitoring and statistics modules are initialized, and the scheduled tasks are configured, and the initial cost model is loaded or established to ensure that the database metadata and system resource monitoring interface are available. For example, when configuring the scheduled tasks, the database can be configured to execute the data statistics task once an hour, and when loading or establishing the initial cost model, the initial cost model parameters may include a default I / O cost factor of 10 and a CPU cost factor of 5.
[0041] S200: The method for generating an execution plan of a database further includes: obtaining performance status information of the database, where the performance status information includes current statistical data and current workload data.
[0042] In one embodiment of the present application, the method for obtaining statistical data of database performance status information includes: triggering a data statistical task in the database at a preset frequency to obtain statistical information in the database. For example, triggering a data statistical task in the database every hour or every day.
[0043] Furthermore, the statistical information is stored in a preset data table format to obtain a metadata table, and the current statistical data of the database is determined based on the metadata table. For example, statistical information such as the number of data rows in the database table, the number of unique values in each column, data distribution (such as a histogram), and index usage frequency are collected and stored in the metadata storage to obtain a metadata table, and the index usage statistics are updated at the same time, thereby identifying hot and unpopular data areas for quick access.
[0044] Optionally, in the above steps, a scheduled task scheduler may be responsible for triggering data statistics updates at a preset frequency, and a stratified random sampling technique may be used to ensure the representativeness of the statistical information. The above steps may be implemented using the following program:
[0045] 1. Pseudo code example:
[0046] 2.def collect_statistics(table):
[0047] 3.samples=table.random_sample(size=sample_size)
[0048] 4.histogram=samples.column_histogram()
[0049] 5.unique_counts={col:samples[col].nunique()for col insamples.columns}
[0050] 6.#Storing Statistics
[0051] 7.metadata_storage.save(table_name=table.name,histogram=histogram,unique_counts=unique_counts)
[0052] In one embodiment of the present application, a method for obtaining current workload data of database performance status information includes: designing a monitoring system in the database, that is, implanting an event listener in the query engine of the database to monitor system resource usage data (such as CPU, memory, and I / O usage data) in real time to obtain real-time load data of the database; obtaining the execution log of the database at a preset frequency, and determining the current workload data of the database based on the execution log and the real-time load data.
[0053] It should be understood that the current workload data includes the real-time workload data in the process of generating the optimal execution plan, and the real-time execution log of generating the optimal execution plan.
[0054] For example, the principle of obtaining the current workload data of the database performance status information is as follows: design a monitoring system, use the message queue to record the start and end time, resource consumption and other information of each optimal execution plan, and collect the database resource usage. Specifically: first, implant an event listener in the database query engine to capture the key events of the query life cycle, that is, capture the start and end time, resource consumption and other information of each optimal execution plan, and collect the database resource usage; then periodically check the system resource (CPU, memory, I / O) usage; finally, aggregate the data, that is, use the stream processing framework (such as Apache Kafka, Flink) to integrate the monitoring data and provide a real-time view to determine the current workload data based on the real-time view. Among them, the above steps can be implemented specifically using the following program:
[0055] 1. Pseudo code example:
[0056] 2.class QueryMonitor:
[0057] 3.def on_query_start(self, query_id):
[0058] 4.self.query_times[query_id]=time.time() 5.
[0060] 6.def on_query_end(self, query_id, resource_usage):
[0061] 7. duration=time.time()-self.query_times.pop(query_id)
[0062] 8. workload_monitor.update(query_id=query_id, duration=duration, resource_usage=resource_usage)
[0063] S300: updating the initial cost model based on the statistical data and the workload data, and then constructing an execution cost model of the database to determine a target execution plan of the database based on the execution cost model.
[0064] For example, based on the collected current statistical data and current workload data, the steps of building an execution cost model may include: 1. Building a cost function: defining a cost function C(Plan), where Plan represents a preset execution plan; 2. Strategy evaluation: for each preset execution plan, use the cost function to calculate its expected cost; 3. Model training: if a machine learning method is used, the model must be trained with historical execution data in advance. Among them, the execution cost model considers multi-dimensional indicators such as execution time and resource consumption.
[0065] Specifically, the following procedures can be used to achieve this:
[0066] 1. Pseudo code example:
[0067] 2.def evaluate_cost(plan,stats,workload):
[0068] 3.expected_rows=estimate_rows_returned(plan,stats)
[0069] 4.cpu_cost=expected_rows*workload.current_cpu_load
[0070] 5.io_cost=plan.disk_access*workload.io_throughput
[0071] 6.return cpu_cost+io_cost
[0072] S400: A method for determining a target execution plan of a database based on an execution cost model includes: responding to user requests received by a database, generating multiple preset execution plans based on the user requests, the preset execution plans including a distributed logical plan and a distributed physical plan, wherein the distributed logical plan includes a node topology of the database and data distribution and storage conditions of query data corresponding to the user request, and the distributed physical plan includes the transmission conditions between nodes of the database and the storage engine characteristics of the database.
[0073] Furthermore, based on the execution cost model, a preset execution plan with the lowest comprehensive cost of the distributed logical plan and the distributed physical plan among multiple preset execution plans is determined, and the execution cost plan with the lowest comprehensive cost is used as the target execution plan.
[0074] For example, among multiple preset execution plans, if there are: Plan A: Full table scan orders, estimated cost = 10,000 (based on the number of rows and I / O cost); Plan B: Index scan (order_date), estimated cost = 5,000 (taking data locality into account), then select Plan B as the target execution plan because it has a lower cost.
[0075] It should be understood that the principle of determining the target execution plan of the database based on the execution cost model may include using a greedy algorithm, a genetic algorithm, or a deep learning model to search for the optimal solution from all preset execution plans.
[0076] For example, the specific steps of determining the target execution plan of the database based on the execution cost model may include: 1. Search space definition: Generate all legal execution plan combinations based on the query structure. 2. Optimization goal: Minimize the cost function C(Plan). 3. Selection strategy: Adjust the optimization goal weight according to the real-time workload. The following program can be used to implement it:
[0077] 1. Pseudo code example:
[0078] 2.def generate_optimal_plan(query,stats,workload):
[0079] 3.candidate_plans=generate_candidate_plans(query)
[0080] 4.best_plan=min(candidate_plans,key=lambda plan:evaluate_cost(plan,s tats,workload))
[0081] 5. return best_plan
[0082] Of course, in other embodiments, the duration of each preset execution plan may be evaluated based on the execution cost model, and then the preset execution plan with the shortest duration among multiple preset execution plans may be determined, and the execution cost plan with the shortest duration may be used as the target execution plan to meet the needs of users for efficient queries in special circumstances.
[0083] S500: In the process of executing the target execution plan in the database, the target execution plan is optimized based on the current workload data to obtain the optimal execution plan. The optimal execution plan includes a distributed logical plan generated based on the user request and a distributed physical plan generated based on the distributed logical plan.
[0084] In one embodiment of the present application, a method for optimizing a target execution plan based on workload data includes: obtaining estimated performance data and real-time performance data of a target execution plan executed by a database based on workload data; if the difference between the real-time performance data and the estimated performance data of the target execution plan is greater than a preset deviation threshold, optimizing the target execution plan based on the real-time performance data. If the difference between the real-time performance data and the estimated performance data of the target execution plan is equal to or less than the preset deviation threshold, determining that the current target execution plan is the optimal execution plan.
[0085] It should be understood that the real-time performance data may include integrated data such as resource consumption data of the database executing the target execution plan, database resource usage data, and the like.
[0086] In one embodiment of the present application, the steps of optimizing the target execution plan based on real-time performance data may be: when the target execution plan is halfway executed, that is, when the query is halfway executed, it is found that the I / O usage rate is significantly higher than expected (the original plan B estimated 30GB, but 50GB was actually used), and then the target execution plan is re-evaluated through the execution cost model, and the use of the index (status) combined with the range scan of order_date is considered.
[0087] In one embodiment of the present application, when the target execution plan is re-evaluated through the execution cost model, the execution cost model is an execution cost model that is updated in real time based on current workload data and current statistical data, that is, the execution cost model is dynamically adjusted while executing the target execution plan.
[0088] Furthermore, the method for optimizing the target execution plan based on real-time performance data includes: determining the remaining tasks in the target execution plan based on the inter-node transmission status of the database at the current moment.
[0089] Furthermore, the remaining tasks are redistributed based on the real-time performance data and the node topology of the database. This can be achieved by the following procedure:
[0090] 1. Pseudo code example:
[0091] 2.def adjust_plan_if_needed(query_id,current_plan,runtime_stats):
[0092] 3.if is_performance_degraded(query_id,runtime_stats):
[0093] 4.new_plan=reoptimize_plan(current_plan,latest_workload)
[0094] 5.query_engine.resubmit(query_id,new_plan)
[0095] S600: The execution plan generation method of the database also includes: after obtaining the optimal execution plan, obtaining the real-time performance data generated in the process of obtaining the optimal execution plan; updating the execution cost model based on the real-time performance data to update the current performance status information, and then obtaining the updated execution cost model, so that the database can determine the target execution plan through the updated execution cost model when responding to the next query request.
[0096] It should be understood that after obtaining the optimal execution plan, that is, after the query task is completed, the real-time performance data generated in the process of obtaining the optimal execution plan can be collected, and the real-time performance data can be used as feedback information to update the current statistical data and current workload data, and to continuously improve the future optimization target execution plan and improve the accuracy of future predictions.
[0097] For example, you can first collect performance indicators, that is, the actual execution time and resource usage after obtaining the optimal execution plan; then update the model: that is, update the execution cost model regularly or on demand to incorporate new data; finally, iterate and optimize: form a closed loop and continuously iterate the optimization strategy. Specifically, the following procedures can be used:
[0098] 1. Pseudo code example:
[0099] 2.def update_model_with_feedback(query_id,actual_performance):
[0100] 3.historical_data.append((query_id,actual_performance))
[0101] 4.if should_retrain_model():
[0102] 5.retrain_cost_model(historical_data)
[0103] Furthermore, the sample data flow of updating the execution cost model based on real-time performance data can be illustrated as follows: 1. Actual performance data: Query Q1 is finally completed, the actual total I / O consumption is 60GB, and the CPU usage is 25%. 2. Update statistics: According to the actual performance of Q1, it may be necessary to adjust the histogram distribution assumption of the order_date column to reflect the data access concentration during the query period. 3. Retrain the cost model: Through machine learning algorithms, integrate new execution log data and readjust the cost factors, such as increasing the penalty factor for high I / O operations.
[0104] In summary, combined Figure 2 and Figure 3 As shown, the execution plan generation method of the database in the embodiment of the present invention first constructs the execution cost model of the database through statistical information and workload data; then, when the database responds to the input query request, the target execution plan for executing the query task is determined through the execution cost model; then, after the target execution plan is determined, and in the process of executing the target execution plan in the database, the workload data and execution log of the database are continuously obtained to optimize the target execution plan in real time when executing the target execution plan, and finally obtain the optimal execution plan. Therefore, the execution plan generation method of the database can dynamically adjust the target execution plan in the process of executing the target execution plan in the database, and then obtain the optimal execution plan, which ultimately significantly improves the query processing efficiency, reduces the response time, and improves the user experience; and it can automatically adapt to the changes in data distribution and the diversity of query patterns, thereby maintaining the timeliness of the optimization plan and enhancing the stability and elasticity of the system under high load conditions.
[0105] Figure 4 FIG. 1 is a schematic diagram showing the structure of an execution plan generation device provided in an embodiment of the present application. Figure 4 As shown, in this embodiment, a database execution plan generation device 200 is also provided, which is used to execute the database execution plan generation method in the above embodiment.
[0106] Furthermore, the execution plan generating device 200 includes: a first acquisition module 210, which is used to acquire performance status information of the database, and the performance status information includes statistical data and workload data.
[0107] Furthermore, the execution plan generating device 200 also includes a construction module 220 for constructing an execution cost model of the database based on the statistical data and the workload data, so as to determine a target execution plan of the database based on the execution cost model.
[0108] Furthermore, the execution plan generating device 200 also includes a second acquisition module 230, which is used to acquire the workload data of the database during the process of the database executing the target execution plan.
[0109] Furthermore, the execution plan generating device 200 also includes an optimization module 240 for optimizing the target execution plan based on the workload data to obtain an optimal execution plan.
[0110] It should be noted that the database execution plan generation device 200 provided in the above embodiment and the database execution plan generation method provided in the aforementioned embodiment belong to the same concept, wherein the specific manner in which each module and unit executes the operation has been described in detail in the method embodiment and will not be repeated here.
[0111] Another aspect of the present application provides an electronic device, comprising: a controller; a memory for storing one or more programs, which, when executed by the controller, executes the above-mentioned method for generating an execution plan for a database.
[0112] The present application also provides a computer-readable storage medium on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the above-mentioned method for generating an execution plan for a database.
[0113] See also Figure 5 , Figure 5 1 is a schematic diagram of the structure of a computer system of an electronic device shown in an exemplary embodiment of the present application, which shows a schematic diagram of the structure of a computer system of an electronic device suitable for implementing an embodiment of the present application.
[0114] It should be noted that Figure 5 The computer system 400 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0115] like Figure 5As shown, the computer system 400 includes a central processing unit (CPU) 401, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 402 or the program loaded from the storage part 408 to the random access memory (RAM) 403, such as executing the method in the above embodiment. In the RAM 403, various programs and data required for system operation are also stored. The CPU 401, ROM 402 and RAM 403 are connected to each other through a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404. The following components are connected to the I / O interface 405: an input section 406 including a keyboard, a mouse, etc.; an output section 407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 408 including a hard disk, etc.; and a communication section 409 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed so that a computer program read therefrom is installed into the storage section 408 as needed.
[0116] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 409, and / or installed from a removable medium 411. When the computer program is executed by a central processing unit (CPU) 401, various functions defined in the system of the present application are executed.
[0117] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as a part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program used by or in combination with an instruction execution system, device, or device. The computer program contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above. The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions, and operations of the systems, methods, and computer program products according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above module, program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each block in the block diagrams or flowcharts, and combinations of blocks in the block diagrams or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0118] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not constitute limitations on the units themselves in some cases.
[0119] Another aspect of the present application further provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the execution plan generation method of the database as described above is implemented. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0120] Another aspect of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the execution plan generation method for the database provided in each of the above embodiments.
[0121] According to one aspect of an embodiment of the present application, a computer system is also provided, including a central processing unit (CPU), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage portion into a random access memory (RAM), such as executing the method in the above embodiment. In RAM, various programs and data required for system operation are also stored. CPU, ROM and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0122] The following components are connected to the I / O interface: an input part including a keyboard, a mouse, etc.; an output part including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage part including a hard disk, etc.; and a communication part including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication part performs communication processing via a network such as the Internet. A drive is also connected to the I / O interface as needed. Removable media, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., are installed on the drive as needed so that the computer program read therefrom is installed into the storage part as needed.
[0123] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A method for generating an execution plan of a database, characterized in that: The method comprises: Acquire performance status information of the database, wherein the performance status information includes current statistical data and current workload data; Building an execution cost model of the database based on the current statistical data and the current workload data, so as to determine a target execution plan of the database based on the execution cost model; During the process of the database executing the target execution plan, the target execution plan is optimized based on the current workload data to obtain an optimal execution plan, wherein the optimal execution plan includes a distributed logical plan generated based on a user request and a distributed physical plan generated based on the distributed logical plan.
2. The method according to claim 1, characterized in that The method for optimizing the target execution plan based on the current workload data includes: Acquire estimated performance data and real-time performance data of the database executing the target execution plan based on the current workload data; If the difference between the real-time performance data and the estimated performance data of the target execution plan is greater than a preset deviation threshold, the target execution plan is optimized based on the real-time performance data.
3. The method according to claim 2, characterized in that The method for optimizing the target execution plan based on the real-time performance data includes: Determine the remaining tasks in the target execution plan based on the inter-node transmission status of the database at the current moment; The remaining tasks are reallocated based on the real-time performance data and the node topology of the database.
4. The method according to claim 1, characterized in that The method further comprises: Acquiring real-time performance data generated in the process of obtaining the optimal execution plan; The execution cost model is updated based on the real-time performance data to obtain an updated execution cost model.
5. The method according to claim 1, characterized in that The method for determining the target execution plan of the database based on the execution cost model includes: In response to a user request received by the database, a plurality of preset execution plans are generated based on the user request, wherein the preset execution plans include a distributed logical plan and a distributed physical plan, wherein the distributed logical plan includes a node topology of the database and data distribution and storage conditions of query data corresponding to the user request, and the distributed physical plan includes an inter-node transmission condition of the database and storage engine characteristics of the database; Based on the execution cost model, a preset execution plan with the lowest comprehensive cost of the distributed logical plan and the distributed physical plan among the plurality of preset execution plans is determined, and the execution cost plan with the lowest comprehensive cost is used as the target execution plan.
6. The method according to claim 1, characterized in that The method for obtaining the performance status information of the database includes: Monitoring resource usage data of the database to obtain real-time load data of the database; Obtaining the execution log of the database at a preset frequency; Current workload data of the database is determined based on the execution log and the real-time load data.
7. The method according to claim 1, characterized in that The method for obtaining the performance status information of the database includes: Triggering a data statistics task in the database at a preset frequency to obtain statistical information in the database; The statistical information is stored in a preset data table format to obtain a metadata table; Current statistics of the database are determined based on the metadata table.
8. A database execution plan generation device, characterized in that: The execution plan generating device comprises: A first acquisition module is used to acquire performance status information of the database, wherein the performance status information includes statistical data and workload data; A construction module, configured to construct an execution cost model of the database based on the statistical data and the workload data, so as to determine a target execution plan of the database based on the execution cost model; A second acquisition module is used to acquire workload data of the database during the process of the database executing the target execution plan; The optimization module is used to optimize the target execution plan based on the workload data to obtain an optimal execution plan.
9. An electronic device, characterized in that: include: Controller; The memory is used to store one or more programs. When the one or more programs are executed by the controller, the controller implements the method for generating an execution plan for a database according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The storage medium stores at least one executable instruction. When the executable instruction is executed on the execution plan generation device, the execution plan generation device of the database performs the operation of the execution plan generation method of the database as described in any one of claims 1-7.
Citation Information
Patent Citations
Rule-driven and data-driven combined cross-platform SQL query optimization method
CN111444220A
Data query optimization processing method and device based on machine learning
CN115617830A
Query acceleration method and device based on materialized view, electronic equipment and medium
CN117688032A
Cited By
Self-adaptive execution engine optimization method based on dynamic query
CN120872973A
