Training method of query decision model, database query method, device and equipment
Patent Information
- Application Number
- CN202510870031.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-24
- Publication Date
- 2026-10-30
AI Technical Summary
在实际应用中发现,这种实现方式依赖人工设计的固定公式和启发式规则,可能无法适应数据分布动态变化的情况;而且对于较为复杂的查询需求,成本模型确定的执行代价数据的准确度偏低,导致挑选的查询计划树在实际执行中性能欠佳,影响数据的查询效率
[0068]本申请实施例至少包括以下有益效果:本申请提供一种查询决策模型的训练方法、数据库查询方法、装置及设备,该训练方法获取针对数据库的多个样本查询语句,通过原始查询优化器生成每个原始查询优化器对应的至少一个第一样本查询计划树,对各个第一样本查询计划树的执行开销进行预测,确定对应的预测执行开销数据,以此为基础构建强化学习模型的反馈机制:根据样本查询语句和数据库确定状态值,通过强化学习模型从候选的第一样本查询计划树中确定第一动作决策,并根据第一动作决策对应的预测执行开销数据确定奖励值,从而动态调整强化学习模型的参数。该训练方法能够动态优化查询决策模型中的强化学习模型,提高强化学习模型确定动作决策的准确度,从而改善挑选的查询计划树在实际执行中的性能,有利于提高数据的查询效率。
Smart Images

Figure CN123014063A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a training method for a query decision model, a database query method, an apparatus, and a device. Background Technology
[0002] A database is a system used to store, manage, and retrieve data, widely applied in various business scenarios such as e-commerce, financial services, and social media. Currently, when querying data in a database, users can edit query statements according to their needs and input them into the database. The database is equipped with a query optimizer, which analyzes the query statement, generates corresponding query plan trees, and selects the most efficient query plan tree to perform the data retrieval.
[0003] In related technologies, traditional query optimizers typically construct cost models based on static rules and statistical information (such as database table size and index distribution). These cost models then determine the execution cost data for each query plan tree, thereby selecting the most efficient one. However, in practical applications, this approach relies on manually designed fixed formulas and heuristic rules, which may not adapt to dynamically changing data distributions. Furthermore, for more complex query requirements, the accuracy of the execution cost data determined by the cost model is low, leading to suboptimal performance of the selected query plan tree in actual execution and impacting query efficiency. Summary of the Invention
[0004] This application provides a method for training a query decision model, a database query method, an apparatus, and a device that can dynamically optimize the reinforcement learning model in the query decision model, thereby improving the efficiency of data query.
[0005] One aspect of this application provides a method for training a query decision model, wherein the query decision model includes a reinforcement learning model; the method includes:
[0006] Retrieve multiple sample query statements for the database;
[0007] Each of the sample query statements is input into the original query optimizer, which generates a set of sample query plans for each sample query statement; wherein the set of sample query plans includes at least one first sample query plan tree;
[0008] The execution cost of each first sample query plan tree is predicted to obtain the predicted execution cost data for each first sample query plan tree;
[0009] Based on the sample query statement and the database, a state value is determined, and any first sample query plan tree is determined from the sample query plan set corresponding to the sample query statement as the first action decision corresponding to the sample query statement through the reinforcement learning model;
[0010] Based on the predicted execution cost data corresponding to the first action decision, the reward value corresponding to the first action decision is determined, and the parameters of the reinforcement learning model are updated based on the reward value.
[0011] On the other hand, embodiments of this application provide a database query method, the method comprising:
[0012] Retrieve the target query statement;
[0013] The target query statement is input into the original query optimizer, which generates a set of target query plans corresponding to the target query statement; wherein the set of target query plans includes at least one target query plan tree;
[0014] Based on the target query statement and the database, a state value is determined, and a query decision model trained using the aforementioned training method determines the target action decision corresponding to the target query statement from the target query plan tree; wherein, the query decision model includes a reinforcement learning model;
[0015] The target action decision is executed in the database to obtain the query results.
[0016] On the other hand, embodiments of this application provide a training apparatus for a query decision model, wherein the query decision model includes a reinforcement learning model; the apparatus includes:
[0017] The first acquisition unit is used to acquire multiple sample query statements for the database;
[0018] The first generation unit is used to input each of the sample query statements into the original query optimizer, and generate a sample query plan set corresponding to each sample query statement through the original query optimizer; wherein, the sample query plan set includes at least one first sample query plan tree;
[0019] The prediction unit is used to predict the execution cost of each of the first sample query plan trees and obtain the predicted execution cost data corresponding to each of the first sample query plan trees.
[0020] The first selection unit is used to determine a state value based on the sample query statement and the database, and to determine any first sample query plan tree as the first action decision corresponding to the sample query statement from the sample query plan set corresponding to the sample query statement through the reinforcement learning model.
[0021] The update unit is configured to determine the reward value corresponding to the first action decision based on the prediction execution cost data corresponding to the first action decision, and update the parameters of the reinforcement learning model based on the reward value.
[0022] Optionally, in some embodiments, the first generating unit is specifically used for:
[0023] The sample query statement is input into the original query optimizer, which parses the sample query statement to obtain the abstract syntax tree corresponding to the sample query statement.
[0024] The abstract syntax tree is processed by equivalent transformation rules to obtain at least one logical query plan corresponding to the sample query statement;
[0025] Based on each of the logical query plans, the original query optimizer performs combined enumeration of the database operators to obtain at least one first sample query plan tree corresponding to the sample query statement.
[0026] Optionally, in some embodiments, the first generating unit is specifically used for:
[0027] Lexical analysis was performed on the sample query statement to obtain multiple lexical units;
[0028] The sample query statement is lexically verified based on the lexical unit.
[0029] If the sample query statement is determined to pass lexical verification, an abstract syntax tree corresponding to the sample query statement is constructed based on each lexical unit.
[0030] Optionally, in some embodiments, the first generating unit is specifically used for:
[0031] The original query optimizer combines and enumerates the operators of the database to obtain multiple original query plan trees;
[0032] The execution cost data corresponding to each of the original query plan trees is determined by the original query optimizer.
[0033] The first sample query plan tree is determined by identifying at least one original query plan tree with the smaller corresponding execution cost data.
[0034] Optionally, in some embodiments, the query decision model further includes an expense prediction model; the prediction unit is specifically used for:
[0035] The first sample query plan tree is input into a pre-trained cost prediction model, and the first query feature corresponding to the first sample query plan tree is extracted through the cost prediction model.
[0036] Based on the first query feature, regression prediction is performed using the cost prediction model to obtain the predicted execution cost data corresponding to the first sample query plan tree.
[0037] Optionally, in some embodiments, the first sample query plan tree includes multiple levels, each level including at least one node; the prediction unit is specifically used for:
[0038] Obtain the node attribute information of each of the nodes;
[0039] The node attribute information is encoded using the overhead prediction model to obtain the node features corresponding to each node;
[0040] The second-to-last layer in the first sample query plan tree is determined as the layer to be processed. The feature aggregation of each node to be processed in the layer to be processed is performed by the cost prediction model to obtain new node features corresponding to each node to be processed.
[0041] Detect whether the current layer to be processed is the first layer in the first sample query plan tree;
[0042] If the current layer to be processed is not the first layer in the first sample query plan tree, the layer above the layer to be processed in the first sample query plan tree is determined as the new layer to be processed, and the step of performing feature aggregation on each node to be processed in the layer to be processed through the cost prediction model is returned.
[0043] If the current layer to be processed is the first layer in the first sample query plan tree, the node feature corresponding to the root node of the first sample query plan tree is determined as the first query feature.
[0044] Optionally, in some embodiments, the prediction unit is specifically used for:
[0045] Based on the cost prediction model, the shared convolutional kernel corresponding to the current layer to be processed is determined; wherein, the cost prediction model includes multiple different shared convolutional kernels, and each shared convolutional kernel corresponds to a level in the query plan tree;
[0046] A first node is determined from the nodes to be processed; wherein the first node is a node to be processed that includes child nodes;
[0047] The first node and its corresponding child nodes are feature aggregated using the shared convolutional kernel.
[0048] Optionally, in some embodiments, the training device further includes a first training unit, which is specifically used for:
[0049] Obtain multiple second sample query plan trees and the labels corresponding to each second sample query plan tree; wherein, the labels are used to characterize the actual results of the execution overhead data corresponding to the second sample query plan tree;
[0050] The second sample query plan tree is input into the cost prediction model to be optimized, and the second query feature corresponding to the second sample query plan tree is extracted through the cost prediction model.
[0051] Based on the second query feature, regression prediction is performed through the cost prediction model to obtain the second prediction execution cost data corresponding to the second sample query plan tree;
[0052] The training loss value is determined based on the label corresponding to the second sample query plan tree and the second prediction execution overhead data;
[0053] Based on the loss value, the parameters of the cost prediction model are updated to obtain a trained cost prediction model.
[0054] Optionally, in some embodiments, the label includes an execution time label and a resource consumption label, and the second predicted execution overhead data includes predicted execution time data and predicted resource consumption data; the first training unit is specifically used for:
[0055] Based on the execution time label and the predicted execution time data, determine the first sub-loss value for training;
[0056] Based on the resource consumption label and the predicted resource consumption data, determine the second sub-loss value for training;
[0057] The first sub-loss value and the second sub-loss value are weighted and summed to obtain the training loss value.
[0058] On the other hand, embodiments of this application provide a database query apparatus, the apparatus comprising:
[0059] The second acquisition unit is used to acquire the target query statement;
[0060] The second generation unit is used to input the target query statement into the original query optimizer, and generate a set of target query plans corresponding to the target query statement through the original query optimizer; wherein, the set of target query plans includes at least one target query plan tree;
[0061] The second selection unit is used to determine the state value based on the target query statement and the database, and to determine the target action decision corresponding to the target query statement from the target query plan tree through the query decision model trained by the aforementioned training method; wherein, the query decision model includes a reinforcement learning model;
[0062] The execution unit is used to execute the target action decision in the database and obtain the query results.
[0063] On the other hand, embodiments of this application provide an electronic device, including a processor and a memory;
[0064] The memory is used to store computer programs;
[0065] The processor executes the computer program to implement the aforementioned query decision model training method or database query method.
[0066] On the other hand, embodiments of this application provide a computer-readable storage medium storing a computer program, which is executed by a processor to implement the aforementioned training method for the query decision model or the database query method.
[0067] On the other hand, embodiments of this application also provide a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to execute the training method or database query method that implements the aforementioned query decision model.
[0068] The embodiments of this application include at least the following beneficial effects: This application provides a training method for a query decision model, a database query method, an apparatus, and a device. The training method acquires multiple sample query statements for a database, generates at least one first sample query plan tree corresponding to each original query optimizer through an original query optimizer, predicts the execution cost of each first sample query plan tree, determines the corresponding predicted execution cost data, and constructs a feedback mechanism for a reinforcement learning model based on this: a state value is determined according to the sample query statements and the database; a first action decision is determined from the candidate first sample query plan trees through the reinforcement learning model; and a reward value is determined based on the predicted execution cost data corresponding to the first action decision, thereby dynamically adjusting the parameters of the reinforcement learning model. This training method can dynamically optimize the reinforcement learning model in the query decision model, improve the accuracy of the reinforcement learning model in determining action decisions, thereby improving the performance of the selected query plan trees in actual execution, and is beneficial to improving data query efficiency. Attached Figure Description
[0069] The accompanying drawings are used to provide a further understanding of the technical solutions of this application and constitute a part of the specification. They are used together with the embodiments of this application to explain the technical solutions of this application and do not constitute a limitation on the technical solutions of this application.
[0070] Figure 1 This is a schematic diagram illustrating the principle of data querying in related technologies.
[0071] Figure 2 This is a system architecture diagram of the training method for a query decision model provided in the embodiments of this application;
[0072] Figure 3 This is a schematic diagram illustrating a version update and iteration of a game application provided in this embodiment of the application;
[0073] Figure 4 This is a schematic diagram illustrating the relationship between a query decision model and the original query optimizer provided in the embodiments of this application;
[0074] Figure 5 This is a flowchart illustrating a training method for a query decision model provided in an embodiment of this application.
[0075] Figure 6 This is a schematic diagram illustrating the principle of reinforcement learning provided in an embodiment of this application;
[0076] Figure 7 This is a schematic diagram of a process for determining predictive execution overhead data provided in an embodiment of this application;
[0077] Figure 8 This is a schematic diagram of the training process of an expense prediction model provided in an embodiment of this application;
[0078] Figure 9 This is a flowchart illustrating a database query method provided in an embodiment of this application;
[0079] Figure 10 This is a schematic diagram illustrating the specific implementation process of a database query method provided in this application embodiment;
[0080] Figure 11 This is a structural block diagram of a training device for a query decision model provided in an embodiment of this application;
[0081] Figure 12 This is a structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0082] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0083] It is understood that the terms “first,” “second,” etc., used in this application may be used to describe various concepts herein, but unless otherwise stated, these concepts are not limited by these terms. These terms are used only to distinguish one concept from another.
[0084] As used in this application, the terms "at least one", "multiple", "each", "any", etc., "at least one" includes one, two or more, "multiple" includes two or more, "each" refers to each of the corresponding multiples, and "any" refers to any one of the multiples.
[0085] 1) Artificial Intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the functions of perception, reasoning, and decision-making.
[0086] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, pre-trained model technology, operating / interactive systems, and mechatronics. Among these, pre-trained models, also known as large-scale models or foundational models, can be widely applied to downstream tasks across various AI fields after fine-tuning. AI software technologies primarily include computer vision, speech processing, natural language processing, and machine learning / deep learning.
[0087] 2) Machine Learning (ML) is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and pre-trained learning. Pre-trained models are the latest development in deep learning, integrating the above techniques.
[0088] 3) Reinforcement Learning (RL), an important branch of machine learning, focuses on how to enable an agent to learn optimal behavioral strategies through interaction with the environment. In reinforcement learning, the agent continuously tries different actions and adjusts its behavior based on reward or punishment signals obtained from the environment to maximize long-term cumulative rewards.
[0089] A database is a system used to store, manage, and query data, and it is widely used in various business scenarios.
[0090] For example, in e-commerce applications, online shopping platforms often build databases to store registered account information, merchant information, product data, order data, and other related information (such as shopper reviews and interactions between shoppers and merchants). In financial services applications, banking systems and financial transaction platforms often build databases to store customer account information, balances, and transaction records. This information can be used to provide related financial services or to assist in customer credit assessment and risk management. In social media applications, social media platforms often build databases to store information about social media accounts, such as profile pictures, avatars, and interests, as well as records of posts, articles, images, and videos published by these accounts. Social media platform databases can also store relationships between social media accounts, such as following lists and friend relationships, and chat data between various social media accounts.
[0091] It is understandable that the data types and uses of databases may differ in different application scenarios. Furthermore, the actual application scenarios of databases are not limited to the types shown above. For example, in other examples, databases can also be used in application scenarios such as game services, the Internet of Things, education platforms, logistics management, and healthcare, which will not be elaborated upon here.
[0092] In databases, there are frequent data query requirements stemming from business needs for real-time data access and analysis. Objects or applications can use queries to retrieve, filter, and statistically analyze relevant data from the database to perform daily operations, decision analysis, or system optimization. Queries are typically implemented using SQL (Structured Query Language), a standard language specifically designed for managing and manipulating relational databases. SQL allows for CRUD operations with concise syntax and can improve query efficiency through indexes and query optimizers.
[0093] Besides SQL statements, data queries can also be achieved using other query statements. For example, MongoDB databases can be queried using JSON statements, and Neo4j databases can be queried using Cypher statements. Some database systems also support natural language queries (such as AI-driven semantic parsing) or other visualization tools to generate query statements, lowering the barrier to entry for non-technical users. This application does not impose any restrictions on this.
[0094] As the volume and complexity of database data increase, efficient and accurate queries become increasingly important for database applications. Please refer to... Figure 1 , Figure 1 This diagram illustrates a principle for implementing data querying provided in related technologies. For example... Figure 1 As shown, when there is a need to query data, an object can use a terminal device to initiate a data query request to the database. For example, the object can enter a query statement through the terminal device and then initiate a query request. The database receives the object's query request, parses the query statement, and returns the corresponding query results.
[0095] Databases typically have a query optimizer, which analyzes the query statement, generates corresponding query plan trees, selects the most efficient query plan tree to perform the data query, and then sends the queried data back to the terminal device as the query result.
[0096] For example, when a SQL statement is entered into a database to query data, the query optimizer first parses and performs semantic analysis on the SQL statement to understand the query intent and the data objects involved. Then, based on database statistics (such as table size, index distribution, and data characteristics), the query optimizer generates multiple candidate query plan trees, representing different execution paths and algorithm combinations. For instance, for queries involving multiple table joins, the query optimizer might consider different join orders and algorithms (such as hash joins or nested loop joins), each choice potentially resulting in a different execution plan (i.e., a query plan tree). After determining multiple execution plans, the query optimizer estimates the execution cost of each plan using its internal cost model, and then selects the query plan tree with the lowest cost and highest execution efficiency for the execution engine to run.
[0097] Traditional query optimizers typically build cost models based on static rules and statistical information (such as table size and index distribution in a database). In practice, this approach, relying on manually designed fixed formulas and heuristic rules, may not adapt to dynamically changing data distributions. Furthermore, for more complex query requirements, the accuracy of the execution cost data determined by the cost model is low, leading to suboptimal performance of the selected query plan tree during actual execution and impacting query efficiency.
[0098] Some related technical solutions utilize query optimizers built on artificial intelligence or machine learning algorithms. However, current applications generally face challenges such as complex feature engineering and lagging model updates. Moreover, these solutions often involve building new query optimizers to replace traditional ones, requiring large-scale downtime adjustments to the database system during deployment. This results in high costs and a susceptibility to cold start issues, impacting the stability and reliability of the database system.
[0099] In view of this, embodiments of this application provide a training method for a query decision model, a database query method, an apparatus, and a device. The training method acquires multiple sample query statements for a database, generates at least one first sample query plan tree corresponding to each original query optimizer through an original query optimizer, predicts the execution cost of each first sample query plan tree, determines the corresponding predicted execution cost data, and constructs a feedback mechanism for a reinforcement learning model based on this: a state value is determined according to the sample query statements and the database; a first action decision is determined from the candidate first sample query plan trees through the reinforcement learning model; and a reward value is determined based on the predicted execution cost data corresponding to the first action decision, thereby dynamically adjusting the parameters of the reinforcement learning model. This training method can dynamically optimize the reinforcement learning model in the query decision model, improve the accuracy of the reinforcement learning model in determining action decisions, thereby improving the performance of the selected query plan trees in actual execution and improving data query efficiency.
[0100] Furthermore, the database query method of this application adopts a non-intrusive architecture, which can improve query performance through external enhancements without modifying the internal logic of the original query optimizer. Specifically, by using a reinforcement learning model as the "intelligent decision layer" of the original query optimizer, the candidate query plans generated by the original query optimizer are screened a second time, without performing complex optimizations and adjustments on the original query optimizer itself. It also eliminates the need to build a new query optimizer from scratch, resulting in lower costs. This method can adapt well to the current state of the database, reducing the probability of cold start problems and thus improving the operational stability and reliability of the database system.
[0101] System architecture and scenario description used in the embodiments of this application
[0102] Figure 2 This is a system architecture diagram of a training method for a query decision model provided in this application embodiment, which includes a terminal device 240, an Internet 230, a gateway 220, a backend server 210, etc.
[0103] In some embodiments, the terminal device 240 may include various forms such as a desktop computer, laptop computer, PDA (personal digital assistant), mobile phone, vehicle terminal, home theater terminal, and dedicated terminal. Furthermore, it can be a single device or a collection of multiple devices. The terminal device 240 can communicate with the Internet 230 via wired or wireless means to exchange data.
[0104] A backend server 210 refers to a computer system that can provide certain services to terminal devices 240. Compared to ordinary terminal devices 240, backend servers 210 have higher requirements in terms of stability, security, and performance. A backend server 210 can be a single high-performance computer in a network platform, a cluster of multiple high-performance computers, a portion of a single high-performance computer (e.g., a virtual machine), or a combination of portions of multiple high-performance computers (e.g., virtual machines).
[0105] Gateway 220, also known as an internetwork connector or protocol converter, is a computer system or device that acts as a translator, enabling network interconnection at the transport layer. It bridges the gap between two systems using different communication protocols, data formats, languages, or even completely different architectures. Gateways can also provide filtering and security functions. Messages sent from terminal device 240 to backend server 210 are forwarded to the corresponding backend server 210 via gateway 220. Messages sent from backend server 210 to terminal device 240 are also forwarded to the corresponding terminal device 240 via gateway 220.
[0106] The backend server 210 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0107] The query decision model training method provided in this application embodiment can be executed independently on the terminal device 240 or independently on the backend server 210. Relatively speaking, since the method in this application embodiment uses related models, it places certain performance requirements on the device. Therefore, it is advisable to deploy it on the backend server 210, and this application does not impose any restrictions on this. When the method in this application embodiment is deployed on the backend server 210, the training of the query decision model can be achieved based on data transmission between the terminal device 240 and the backend server 210.
[0108] For example, in this embodiment, the terminal device 240 can install and run related applications, such as social applications, multimedia applications, and news aggregation applications. The backend server 210 can be the backend server corresponding to these applications. Users of the terminal device 240 can access the backend server 210 based on the applications installed on the terminal device 240 to process related business. The backend server 210 can be equipped with a corresponding database, which can be used to store application-related business data. When users of the terminal device 240 access the backend server 210, they can include business requests to query data in the database. The database can respond to the business request and then return the queried data to the terminal device 240 through the backend server 210.
[0109] In this scenario, the training method of the query decision model provided in this application embodiment can be executed on the backend server 210 side. By training the query decision model, the backend server 210 can help the database determine a suitable query plan to improve the efficiency and accuracy of data query.
[0110] It should be noted that, in this embodiment of the application, a database query method is also provided, which can also be used in... Figure 2 The system architecture shown is used in this application, and will not be described in detail here.
[0111] Of course, it is understood that the implementation environment corresponding to the method in the embodiments of this application is not limited to that of the implementation environment. Figure 2 As shown, those skilled in the art can flexibly select the specific implementation environment according to actual needs, and this application does not impose any restrictions on this.
[0112] The training method for the query decision model provided in this application can be executed in various scenarios, and the following is an exemplary description of this method.
[0113] (I) Scenarios of Financial Risk Control
[0114] In financial risk control scenarios, systems need to process massive amounts of transaction data in real time and perform complex multi-dimensional risk analyses. For example, they need to identify abnormal transaction patterns (such as high-frequency transfers within a short period), assess customer credit risk, or detect potential abnormal behavior. These applications often involve frequent and complex database query tasks, typically involving multi-table joins (such as transaction records, customer information, historical behavior, etc.), complex aggregation calculations, and real-time rule matching. This places high demands on query performance. Furthermore, the dynamic changes in data distribution (such as sudden large-scale transactions or the emergence of new anomalies) make it difficult for traditional static rule-based query optimizers to consistently provide the optimal execution plan.
[0115] Applying the method from the embodiments of this application to this scenario, the reinforcement learning model can automatically learn changes in data distribution and adjust the selection method of the query plan tree in real time, thereby improving the efficiency and accuracy of data query.
[0116] (II) Game Development Scenarios
[0117] The method described in this application embodiment can be applied to game development scenarios.
[0118] For example, consider a game operator offering an online multiplayer game where players can create characters, purchase virtual items, and participate in various activities. During the game's operation, frequent version updates and iterations are required. (See reference...) Figure 3 , Figure 3 This illustration shows a schematic diagram of a game application undergoing version updates and iterations, as provided in an embodiment of this application. When a game application undergoes version updates and iterations, it is necessary to perform large-scale queries and verifications of the game application's business data. Applying the technical solution of this application can significantly improve the efficiency and reliability of data querying and verification.
[0119] Specifically, traditional query optimizers often struggle to adapt to changes in data distribution when faced with large-scale analytical query tasks due to the limitations of static rules. This is especially true when data table structures or indexes change after a game version update, easily leading to problems such as execution plan failures and sudden drops in query performance. In contrast, this application employs a reinforcement learning strategy to build a query decision model that dynamically learns updated data characteristics and optimizes the scanning strategy for related queries. This approach can handle sudden high-concurrency verification requests during version updates and accurately respond to changes in query patterns caused by data structure alterations, forming a dynamic optimization system with self-learning capabilities.
[0120] General Description of Embodiments in this Application
[0121] Before introducing the training method and database query method of the query decision model provided in this application, the query decision model involved in the embodiments of this application will be introduced first.
[0122] Please refer to Figure 4 , Figure 4 This illustration shows a schematic diagram illustrating the relationship between a query decision model and the original query optimizer provided in an embodiment of this application, such as... Figure 4As shown in this embodiment, the original query optimizer refers to an existing query optimizer in the database system (such as one already deployed and in use). Its related functions have been described above. It is mainly responsible for generating the query plan tree and determining the execution cost data corresponding to the query plan tree based on the cost model, thereby selecting a suitable query plan tree. The query decision model provided in this embodiment can replace the function of the cost model part in the original query optimizer. That is, after the original query optimizer generates the query plan tree, the query decision model provided in this embodiment can be used to select a suitable query plan tree as the optimal query plan tree.
[0123] For example, such as Figure 4 As shown in the embodiments of this application, the original query optimizer can still be responsible for generating the query plan tree. For example, if N query plan trees are generated, they are denoted as query plan tree 1, query plan tree 2, ..., query plan tree N (N is a positive integer). The query decision model in this embodiment can select the optimal query plan tree from the N query plan trees to provide to the database to execute the corresponding query task, obtain the query results, and output them back.
[0124] In contrast, the technical solution in this application, by introducing an iteratively trainable and optimized query decision model to replace the traditional static cost model, can improve the problems of traditional query optimizers relying on manual rules and having poor adaptability. The query decision model can autonomously learn the optimal decision strategy from training data, dynamically capture the inherent patterns of data distribution changes and complex query patterns, and improve the accuracy of selecting the optimal query plan tree. The query plan determined in this application has better actual execution performance in dynamic data environments or complex query scenarios, and does not require manual adjustment of rule formulas, achieving automation and intelligence in query optimization. Furthermore, due to its non-intrusive design, it retains the stability of the original query optimizer while continuously optimizing decision quality through background learning, without significantly negatively impacting online query performance and without requiring system downtime for replacement.
[0125] Please refer to Figure 5 , Figure 5 This illustration shows a flowchart of a training method for a query decision model provided in an embodiment of this application. This training method for the query decision model can be applied to... Figure 2 On the terminal device 240 or the backend server 210 shown. For example... Figure 5 As shown, the training method for a query decision model according to an embodiment of this application includes, but is not limited to, the following steps:
[0126] Step 510: Obtain multiple sample query statements for the database;
[0127] Step 520: Input each sample query statement into the original query optimizer, and generate a sample query plan set corresponding to each sample query statement through the original query optimizer; wherein, the sample query plan set includes at least one first sample query plan tree;
[0128] Step 530: Predict the execution cost of each first sample query plan tree to obtain the predicted execution cost data for each first sample query plan tree;
[0129] Step 540: Determine the state value based on the sample query statement and the database, and determine any first sample query plan tree from the sample query plan set corresponding to the sample query statement as the first action decision corresponding to the sample query statement through the reinforcement learning model;
[0130] Step 550: Determine the reward value corresponding to the first action decision based on the predicted execution cost data corresponding to the first action decision, and update the parameters of the reinforcement learning model based on the reward value.
[0131] In this embodiment of the application, a training method for a query decision model is provided. This method can dynamically optimize the reinforcement learning model in the query decision model, improve the accuracy of the reinforcement learning model in determining action decisions, thereby improving the performance of the selected query plan tree in actual execution and improving the efficiency of data query.
[0132] The technical solution provided in this application embodiment includes a reinforcement learning model in the query decision model. Figure 5 The training of the query decision model primarily focuses on the training of its reinforcement learning model. In this application, the type of algorithm used in the reinforcement learning model within the query decision model is not limited. For example, in some embodiments, a reinforcement learning model based on a value function to guide decision-making can be used, such as a reinforcement learning model built based on the Q-learning algorithm; in some embodiments, a reinforcement learning model based on a policy function can be used, which can directly learn the policy function mapping from state to action, such as a reinforcement learning model built based on algorithms like REINFORCE and Actor-Critic; in some embodiments, a reinforcement learning model built using deep reinforcement learning algorithms, such as the DQN (Deep Q-Network) model, can also be used. This application does not impose any restrictions on this.
[0133] like Figure 4As shown in the embodiments of this application, the query decision model is mainly responsible for selecting the optimal query plan tree from at least one query plan tree, and providing it to the database to execute the corresponding query task. In the technical solution of this application, a reinforcement learning strategy is used to help build an intelligent query decision model, guiding the query decision model to select the optimal query plan tree.
[0134] For example, please refer to Figure 6 , Figure 6 The illustration shows a schematic diagram of the principle of reinforcement learning provided in an embodiment of this application, such as... Figure 6 As shown, reinforcement learning applications include concepts such as agent, environment, state, action, and reward. An agent is an object that perceives changes in the environment and performs corresponding actions. In the application of this embodiment, it can be a software program in a database responsible for handling query tasks. The environment is the world in which the agent interacts; in the application scenario of this application, the environment can be a database environment. When the agent interacts with the environment, it observes the current state of the environment and decides what action to take based on that state. After the agent performs an action, the environment changes (or may remain unchanged), resulting in a new state. Furthermore, the agent receives a reward from the environment, representing the impact of the agent's action on the environment—for example, whether the environment improves or deteriorates relative to a pre-set goal. The agent's goal is to maximize the cumulative reward obtained from the environment; reinforcement learning is the way the agent achieves this goal by learning behaviors.
[0135] In the embodiments of this application, it is desirable for the query decision model to select a query plan tree that executes faster and requires less data processing; that is, the action decisions given by the reinforcement learning model need to favor query plan trees that execute faster and require less data processing. Therefore, the relevant reward value can be determined based on the execution cost data (such as execution data and resource consumption) corresponding to the query plan tree, thereby guiding the training and learning of the reinforcement learning model.
[0136] In this application, the timing of training the query decision model is not limited and can be implemented according to actual needs. For example, in some embodiments, when the query decision model is initially deployed to the database system and the original query optimizer for collaborative application, it can be trained to adapt to specific database query application scenarios. In some embodiments, when the usage time of the deployed query decision model reaches a certain time threshold, or when there are many updates to the data in the database, it can be trained to update its parameters to better provide decision services.
[0137] In step 510, when training the query decision model, multiple sample query statements for the database can be obtained.
[0138] In this embodiment of the application, the query decision model can be deployed to a database. When training the query decision model, some query statements applicable to the database can be obtained based on the database. In this embodiment of the application, these query statements are recorded as sample query statements.
[0139] This application does not limit the specific source of the sample query statements. For example, in some embodiments, the sample query statements can be derived from summaries of real data query needs. For instance, historical execution records can be extracted from database query logs, and the sample query statements can be determined based on these records. In some embodiments, the sample query statements can be automatically generated based on the database schema and pre-defined query templates. For example, by analyzing the database's table structure, field types, index distribution, and other information, sample query statements conforming to syntax rules can be automatically constructed. In some embodiments, the sample query statements can also be generated based on database testing tools. Database testing tools can be used to evaluate database performance, including tools for testing database query performance. In this application embodiment, sample query statements can be generated based on such tools.
[0140] In this embodiment, the specific query function implemented by the sample query statement can be set according to the application scenario and requirements of the database. For example, in some embodiments, for databases in e-commerce transaction system scenarios, the sample query statement can be used to query inventory data, order status, or sales data of certain products; in some embodiments, for databases in financial risk control analysis scenarios, the sample query statement can be used to query related transaction data, customer account information, etc.; in some embodiments, for databases in IoT scenarios, the sample query statement can be used to query device status trend data, sensor detection data, etc.
[0141] It is understood that in the embodiments of this application, the number of sample query statements can be multiple, such as two or more, and this application does not limit this.
[0142] In some embodiments, after obtaining each sample query statement, preprocessing operations can be performed on the sample query statements. The specific methods of preprocessing can be flexibly selected according to actual needs. For example, parameter normalization, syntax standardization, and anomaly filtering can be performed on the sample query statements. Parameter normalization can be performed by using regular expression matching to identify all literal parameters of the sample query statements and perform standardized replacement. Syntax standardization can be performed by using formatting tools to restructure the sample query statements. For example, unifying keyword case, standardizing space and line break rules, eliminating redundant brackets, and standardizing table alias naming, etc. Anomaly filtering can be used to remove malformed statements that do not conform to relevant standards to facilitate subsequent processing.
[0143] In step 520, after obtaining each sample query statement, these sample query statements can be input into the original query optimizer to generate a set of query plans corresponding to each sample query statement. Here, the set of query plans corresponding to the sample query statements is denoted as the sample query plan set. For each sample query plan set, it may include at least one query plan tree, and these query plan trees are denoted as the first sample query plan tree.
[0144] Specifically, in this embodiment, after obtaining (preprocessed) sample query statements, these sample query statements can be input into the database's original query optimizer (i.e., the original query optimizer) to trigger the query plan generation process. The original query optimizer will generate at least one candidate execution plan for each sample query statement based on its built-in rule engine, forming a set of sample query plans corresponding to that sample query statement.
[0145] The sample query plan set may include at least one first sample query plan tree, and each first sample query plan tree is a candidate execution scheme. In this embodiment, the query plan tree is a tree structure representation of the database converting query statements into executable operation flows; it is essentially a tree diagram of the execution schemes designed by the query optimizer. A query plan tree generally includes multiple nodes belonging to different levels, and nodes at different levels can form parent-child relationships. Each node represents a specific database operation (such as table scan, join, sort, etc.), and the parent-child relationship between nodes defines the direction of data flow and the order of operation execution. For example, a query statement containing a join of two tables may generate a plan tree like this: the bottom-level leaf nodes are the scan operations of the two tables, the middle layer is the join operation of the scan results, and the top-level root node is the return operation of the final result.
[0146] For the same query statement, the database query optimizer can construct multiple logically equivalent but physically different query plan tree variants. These query plan trees can achieve performance differences by adjusting the order of operations, selecting different algorithms, or access paths, while ensuring the accuracy of the final query result. For example, the query optimizer can achieve different query plan tree outputs by adjusting the following dimensions: In some embodiments, different query plan trees can be generated through differentiated processing of table access methods, such as choosing between a full table scan and an index scan (e.g., for the condition WHERE id = 100, a query plan tree using a primary key index and a query plan tree with a full table scan can be generated); in some embodiments, different query plan trees can be generated through differentiated processing of join strategies, such as using different algorithms like nested loop joins, hash joins, or merge joins for multi-table queries; in some embodiments, different query plan trees can also be generated through differentiated processing of operation timing, such as determining the execution order of filtering, aggregation, and other operations, thereby obtaining different query plan trees.
[0147] It is understood that, in this embodiment of the application, for a sample query statement, the original query optimizer can generate one or more (i.e., any number of two or more) first sample query plan trees corresponding to it. These first sample query plan trees can constitute the sample query plan set corresponding to the sample query statement. In this embodiment of the application, there is no limit to the number of first sample query plan trees in the sample query plan set corresponding to each sample query statement, and the number of first sample query plan trees in each sample query plan set can be the same or different.
[0148] In step 530, for the set of sample query plans corresponding to each sample query statement, the execution cost of the first sample query plan tree can be predicted to obtain the predicted execution cost data corresponding to each first sample query plan tree.
[0149] In this embodiment, the execution overhead of the first sample query plan tree is predicted, which can be done in one or more dimensions to obtain predicted execution overhead data for the corresponding dimensions. For example, in some embodiments, the execution time data of the first sample query plan tree can be predicted, such as predicting the total time taken from the start of the query to the return of the last data result, or predicting some sub-times during the execution process (such as I / O time, CPU computation time, or network transmission time). In some embodiments, the resource consumption data of the first sample query plan tree can be predicted, such as predicting memory consumption and the number of threads / processes used during the execution of the first sample query plan tree. In some embodiments, the system-level impact data of the first sample query plan tree can be predicted, such as predicting the amount of disk read data, cache hit rate, and lock wait time during the execution of the first sample query plan tree; this application does not limit this.
[0150] When predicting the execution cost data corresponding to the first sample query plan tree, a multi-dimensional cost prediction model can be constructed by comprehensively analyzing the structural features, data distribution characteristics, and runtime environmental factors of the first sample query plan tree. For example, for each first sample query plan tree, its topological features can be extracted first, including the distribution of operator types (such as the proportion of scan, join, and sort operations), the depth and breadth of the tree structure, and key operation parameters (such as the estimated size of the hash table and the amount of data in sorting operations). Simultaneously, database statistics, such as the number of rows in the table, the selectivity of the index, and the data distribution histogram, can be combined to calculate the basic I / O cost (the number of data pages to be read) and CPU processing cost (such as the number of rows to be compared in a join operation). Based on these feature data, the execution cost data corresponding to the first sample query plan tree can be predicted using the cost prediction model. In this embodiment, the cost prediction model can be a machine learning model built based on artificial intelligence technology; the specific model algorithm used is not limited in this application.
[0151] In some embodiments, to improve prediction accuracy, real-time data such as buffer pool hit rate, disk I / O throughput, and system load can be dynamically collected from the current database environment. This data is used to appropriately adjust the data predicted by the overhead prediction model, thereby improving the accuracy of the predicted execution overhead data. For example, when a high disk load is detected, the estimated latency coefficient for I / O operations is automatically increased; if sufficient memory resources are found, the memory limit penalty for hash join operations is reduced. For complex operations (such as multi-table joins or subquery processing), a probabilistic model can be used to simulate the changes in data volume for different execution paths, generating a probability distribution of execution time data using the Monte Carlo method, rather than just a single estimate.
[0152] In some embodiments, the obtained predicted execution cost data can be multi-dimensional data, such as including not only execution time data, but also resource consumption data, system-level impact data, etc. Of course, in some embodiments, the predicted execution cost data can also be single-dimensional data, such as only including execution time data. This application does not limit this.
[0153] It should be noted that in this embodiment, the predicted execution cost data corresponding to the first sample query plan tree is predicted. If the first sample query plan tree is actually executed later, its actual execution cost data during the execution process can be recorded. Based on the deviation between the predicted result and the actual result, the parameters of the cost prediction model can be dynamically corrected through an online learning mechanism so that it can adapt to changes in data distribution and fluctuations in hardware performance, thereby gradually improving the accuracy of the evaluation of the query plan tree.
[0154] In step 540, after determining the predicted execution cost data corresponding to each first sample query plan tree, the state value can be determined based on the sample query statement and the database. Then, the optimal first sample query plan tree can be determined from the sample query plan set corresponding to the sample query statement through the reinforcement learning model as the action decision corresponding to the sample query statement. In this embodiment, it is referred to as the first action decision.
[0155] In this embodiment, after predicting the execution cost of the sample query plan tree, the decision-making phase of reinforcement learning can begin. In this embodiment, the optimization problem of the current query data is transformed into a Markov decision process within the reinforcement learning framework: that is, by analyzing the syntactic structure of the sample query statement, the characteristics of the accessed tables (such as data volume and index distribution), and the real-time state of the database (such as memory pressure and concurrent load), a state value representing the current environment is constructed. This state value can be a state vector, which can capture key factors affecting query performance, such as the query complexity level (whether it contains subqueries or complex joins), the size ratio of the tables involved, and the I / O throughput of the current system, forming the basis for the reinforcement learning model to perceive the environment.
[0156] After determining the state value, the reinforcement learning model can evaluate the potential value of each first sample query plan tree from the set of sample query plans corresponding to the sample query statement, based on the state value. The reinforcement learning model can calculate the long-term benefit of selecting a certain first sample query plan tree as the execution plan through the learned value function or policy network. Since the state value in this embodiment is determined jointly by the sample query statement and the database, the benefit evaluation of the reinforcement learning model will not only consider the immediate cost savings of the current query, but also implicitly consider the impact on the overall system load. For example, it may prioritize the first sample query plan tree with lower memory usage to reduce the resource load of subsequent queries.
[0157] In this embodiment of the application, the reinforcement learning model evaluates and compares all the first sample query plan trees in the sample query plan set, and finally outputs the first sample query plan tree that it considers to have the highest value as the current optimal decision, that is, the first action decision corresponding to the sample query statement.
[0158] It is easy to understand that if the sample query plan set contains only one first sample query plan tree, the first sample query plan tree can be directly identified as the first action decision corresponding to the sample query statement.
[0159] It is understood that in this embodiment, each sample query statement corresponds to a sample query plan set. When determining the first action decision corresponding to the sample query statement, it is necessary to determine the optimal first sample query plan tree in each sample query plan set as the first action decision corresponding to the sample query statement. Here, the optimal first sample query plan tree can be any first sample query plan tree in the sample query plan set, and its specific determination is made by the reinforcement learning model. Based on the difference in the type of algorithm used by the reinforcement learning model, the way it implements the prediction output of the first action decision may differ, and this application does not impose any restrictions on this.
[0160] In step 550, after determining the first action decision corresponding to each sample query statement, the reward value corresponding to the first action decision can be determined based on the predicted execution cost data corresponding to the first sample query plan tree obtained earlier. The parameters of the reinforcement learning model are then updated based on the reward value to obtain the trained query decision model.
[0161] In this embodiment, the first action decision is itself a first sample query plan tree corresponding to the sample query statement. In step 530, the prediction execution cost data corresponding to each first sample query plan tree has already been determined. Therefore, the reward value can be determined here based on the prediction execution cost data corresponding to the first action decision. The reward value is the core feedback signal for training the reinforcement learning model; its essence is to transform the prediction performance of the reinforcement learning model into a quantifiable optimization signal. Specifically, if the current prediction performance of the reinforcement learning model is good, then the first action decision will be more biased towards the optimal decision, and correspondingly, the prediction execution cost data corresponding to the first action decision will be lower; conversely, if the current prediction performance of the reinforcement learning model is poor, then the first action decision will be further away from the optimal decision, and correspondingly, the prediction execution cost data corresponding to the first action decision will be higher.
[0162] Therefore, in this embodiment, the reward value can be negatively correlated with the predicted execution cost data corresponding to the first action decision. That is, the smaller the predicted execution cost data corresponding to the first action decision, the larger the reward value, and the larger the predicted execution cost data corresponding to the first action decision, the smaller the reward value. This application does not limit the specific functional relationship between the two.
[0163] In this embodiment of the application, after obtaining the reward value corresponding to the first action decision, the parameters of the reinforcement learning model can be updated based on it to optimize the performance of the reinforcement learning model, thereby obtaining a trained reinforcement learning model, that is, completing the training of the query decision model.
[0164] Specifically, updating the parameters of a reinforcement learning model can be implemented in different ways depending on the type of algorithm used. For example, in some embodiments, the new action value corresponding to the first action decision can be determined based on the reward value of that first action decision. This new action value can be calculated using a value function and can then be used as a parameter of the reinforcement learning model. In some embodiments, the parameters can be updated using the prediction error of the reinforcement learning model. This error is the difference between the current estimate and the target value, and is negatively correlated with the reward value. To make the model predict the future more accurately, this error needs to be minimized.
[0165] In this embodiment, the training process for the reinforcement learning model can be iterative. After each update of the model's parameters, a new batch of sample query statements can be obtained, and the aforementioned steps can be executed again. This allows for iterative updates of the reinforcement learning model. This application does not impose any restrictions on the conditions for ending training.
[0166] For example, in some embodiments, a maximum number of training rounds or iterations can be set. When this limit is reached, updates stop, thus avoiding overtraining and ensuring that the reinforcement learning model has enough time to converge without falling into overfitting. In some embodiments, when the performance of the reinforcement learning model (such as the accumulated reward value) stabilizes within a reasonable range, or the change is very small (below a certain threshold), the model can be considered to have converged, and updates can be stopped at this point. In the embodiments of this application, the training termination conditions of the reinforcement learning model can be flexibly set as needed. After the reinforcement learning model is trained, a trained query decision model is obtained, which can then be used to perform database query operations.
[0167] It is understood that the training method for the query decision model provided in this application involves obtaining multiple sample query statements for the database, generating at least one first sample query plan tree corresponding to each original query optimizer through the original query optimizer, predicting the execution cost of each first sample query plan tree, determining the corresponding predicted execution cost data, and constructing a feedback mechanism for the reinforcement learning model based on this: determining the state value according to the sample query statements and the database, determining the first action decision from the candidate first sample query plan trees through the reinforcement learning model, and determining the reward value according to the predicted execution cost data corresponding to the first action decision, thereby dynamically adjusting the parameters of the reinforcement learning model. This training method can dynamically optimize the reinforcement learning model in the query decision model, improve the accuracy of the reinforcement learning model in determining action decisions, thereby improving the performance of the selected query plan trees in actual execution, and helping to improve the data query efficiency.
[0168] Specifically, in some embodiments, reference is made to Figure 6 Each sample query statement is input into the original query optimizer, which generates a set of sample query plans for each sample query statement, including:
[0169] The sample query statement is input into the original query optimizer, which parses the sample query statement to obtain the abstract syntax tree corresponding to the sample query statement.
[0170] By processing the abstract syntax tree using equivalent transformation rules, at least one logical query plan corresponding to the sample query statement is obtained.
[0171] Based on each logical query plan, the database operators are combined and enumerated by the original query optimizer to obtain at least one first sample query plan tree corresponding to the sample query statement.
[0172] In this embodiment of the application, when generating the set of sample query plans corresponding to the sample query statement through the original query optimizer, the sample query statement can be input into the original query optimizer. The original query optimizer first performs deep parsing on the input sample query statement and converts it into a structured abstract syntax tree (AST). The abstract syntax tree is a tree-like representation of the sample query statement, which can clearly express the logical structure of the sample query statement in a hierarchical node manner.
[0173] After obtaining the abstract syntax tree (AST) corresponding to the sample query statement, the original query optimizer enters the logical optimization phase, where a series of predefined equivalence transformation rules can be applied to reconstruct the AST. These equivalence transformation rules can be based on the equivalence principles of relational algebra, including but not limited to predicate pushdown (moving filtering conditions as close to the data source as possible), subquery expansion (converting EXISTS to JOIN), and constant expression evaluation. The application of each equivalence transformation rule will produce semantically equivalent but structurally different logical query plan variants. For example, for queries containing WHERE and GROUP BY, two logical plans can be generated: one filtering followed by grouping, and the other grouping followed by filtering. Through the processing of equivalence transformation rules, the search space can be expanded, providing diverse candidate solutions for the subsequent physical optimization phase.
[0174] Specifically, during the physical optimization phase, the raw query optimizer enumerates all feasible combinations of physical operators for each logical query plan. The raw query optimizer can combine all available access paths (such as full table scans and index scans), join algorithms (such as hash joins and nested loop joins), and sorting methods based on the actual implementation capabilities of the database. For example, for a JOIN operation in the logical query plan, the physical optimization phase may generate three variants: a nested loop join using an index, a hash join utilizing an in-memory hash table, and a sort-based merge join. By enumerating and combining database operators according to the logical query plan, multiple query plan trees can be obtained on a single logical query plan. In this way, one or more first sample query plan trees corresponding to the sample query statement can be obtained.
[0175] In this embodiment, the abstract syntax tree is processed by equivalent transformation rules, and then the operators of the database are combined and enumerated according to the logical query plan. This can effectively improve the diversity of the first sample query plan tree, provide rich decision options for the subsequent reinforcement learning model, and help improve the model training effect.
[0176] Specifically, in some embodiments, the sample query statement is parsed to obtain the abstract syntax tree corresponding to the sample query statement, including:
[0177] Lexical analysis was performed on the sample query statement to obtain multiple lexical units;
[0178] Lexical verification is performed on the sample query statement based on the lexical unit;
[0179] If the sample query statement is determined to pass lexical verification, an abstract syntax tree corresponding to the sample query statement is constructed based on each lexical unit.
[0180] In this embodiment, when parsing the sample query statement and constructing its corresponding abstract syntax tree, lexical analysis can be performed first. This involves starting a lexical analyzer to finely break down the input sample query statement, transforming the continuous stream of characters into a meaningful sequence of lexical units. The lexical analyzer scans each character in the sample query statement, identifying and classifying basic elements such as keywords (e.g., SELECT, FROM), identifiers (e.g., table names, column names), operators (e.g., =, >), constants (e.g., the number 100, the string abc), and separators (e.g., commas, parentheses). Each basic element can serve as a lexical unit.
[0181] After lexical analysis is completed, the sample query statements can be lexically validated based on the obtained lexical units. Lexical validation can detect whether there are any anomalies in the sample query statements, facilitating timely adjustments to any abnormal sample query statements.
[0182] In this application, the method of performing lexical verification on sample query statements is not limited. For example, in some embodiments, the lexical unit can be used to determine whether the use of keywords in the sample query statement conforms to specifications (e.g., whether there is a spelling error in SLECT), whether identifiers exist in the database schema (e.g., verifying whether the users table actually exists), and whether the combination of operators and operands is valid (e.g., checking whether the age column in age>30 is a numeric type). By performing lexical verification on sample query statements, some simple errors can be caught, such as strings with missing quotation marks, mismatched parentheses, and other basic issues. These can be fed back to relevant business personnel for modification, improving the efficiency and accuracy of training. For sample query statements, only those that pass all lexical verifications will proceed to the subsequent processing flow.
[0183] Specifically, the sequence of lexical units that has passed lexical verification can be fed into the parser to begin constructing a structured abstract syntax tree. The parser will reorganize the linearly arranged lexical units into a tree structure according to predefined grammar rules (usually using a context-free grammar). The root node of the tree typically represents the entire sample query statement, the second-level nodes correspond to the main clauses of the sample query statement (such as SELECT, FROM, WHERE), and each clause node is further expanded into a finer-grained structure. For example, the WHERE clause node will derive a conditional expression subtree composed of the left operand, operator, and right operand.
[0184] It is understood that the abstract syntax tree obtained in this embodiment retains the hierarchical features of the sample query statement, which can facilitate the subsequent generation of the first sample query plan tree corresponding to the sample query statement based on the abstract syntax tree.
[0185] Specifically, in some embodiments, the database operators are combined and enumerated by the original query optimizer to obtain at least one first sample query plan tree corresponding to the sample query statement, including:
[0186] Multiple raw query plan trees are obtained by combining and enumerating the database operators through the raw query optimizer.
[0187] The execution cost data corresponding to each raw query plan tree is determined by the raw query optimizer;
[0188] The first sample query plan tree is determined by identifying at least one original query plan tree with the smaller corresponding execution cost data.
[0189] In this embodiment of the application, when generating the first sample query plan tree, the original query optimizer may initiate a combined enumeration process to explore various possible execution strategies, and record the resulting query plan trees as the original query plan trees. In some embodiments, the original query plan tree may be directly used as the first sample query plan tree.
[0190] In some embodiments, the number of original query plan trees determined by the original query optimizer may be large. If all of these original query plan trees are selected as the first sample query plan trees, the subsequent determination of prediction execution cost data and the determination of the first action decision through reinforcement learning models may consume a lot of computational resources. In reality, since the original query plan trees are obtained by combining and enumerating as many combinations as possible, some query plan trees with low application value may exist among them. Therefore, in order to reduce the training cost of the query decision model and improve training efficiency, the original query optimizer can first appropriately filter the original query plan trees, instead of directly using all the original query plan trees as the first sample query plan trees.
[0191] Specifically, in this embodiment, when appropriately filtering the original query plan trees by the original query optimizer, its built-in cost model can be invoked to calculate the corresponding execution cost data for each original query plan tree. This application does not impose restrictions on the rules set by the cost model in the original query optimizer. After determining the execution cost data corresponding to each original query plan tree, at least one original query plan tree with the smaller corresponding execution cost data can be determined as the first sample query plan tree. The specific number of the determined first sample query plan trees can be flexibly set according to actual needs, and this application does not impose any restrictions on this. For example, the number of first sample query plan trees can be determined to be 5.
[0192] It is understood that in this embodiment of the application, the original query plan tree is appropriately filtered by the original query optimizer to obtain the first sample query plan tree. This utilizes the selection performance of the original query optimizer itself, ensuring the high quality of the sample query plan set, providing diverse and reliable decision options for the subsequent reinforcement learning model, and improving the discrimination ability of the reinforcement learning model.
[0193] Specifically, in some embodiments, the query decision model also includes an expense prediction model; refer to Figure 7 The execution cost of each first-sample query plan tree is predicted to obtain the predicted execution cost data for each first-sample query plan tree, including:
[0194] Step 710: Input the first sample query plan tree into the pre-trained cost prediction model, and extract the first query feature corresponding to the first sample query plan tree through the cost prediction model;
[0195] Step 720: Based on the first query feature, perform regression prediction using the cost prediction model to obtain the predicted execution cost data corresponding to the first sample query plan tree.
[0196] In this embodiment of the application, an overhead prediction model can also be set in the query decision model, which can be used to predict the execution overhead data.
[0197] Specifically, in this embodiment, when determining the predicted execution cost data, the first sample query plan tree can be input into a pre-trained cost prediction model. The cost prediction model first initiates a feature extraction process to mine multi-dimensional features from the structure of the first sample query plan tree. These features can include basic operator types (such as scan, join, sort, etc.) and tree topology information, and can also capture deeper execution features, such as the algorithm selection for join operations (hash join or nested loop), data access path (whether an index is used), and the estimated size of the intermediate result set. In this embodiment, the obtained features can be recorded as the first query features.
[0198] Based on the extracted first query features, the cost prediction model can perform regression prediction analysis. In this embodiment, the complex nonlinear mapping relationship learned by the cost prediction model during the training phase is used to transform the structured first query features into multi-dimensional predicted execution cost data. Unlike the static cost model of traditional query optimizers, the cost prediction model in this embodiment can capture more influencing factors that are difficult to quantify, such as the impact of data skew on hash join performance and the limitation of memory bandwidth on sorting operations.
[0199] In this embodiment, the predicted execution overhead data output by the overhead prediction model can be comprehensive performance evaluation data, such as point estimates and confidence intervals of total execution time, predicted peak memory usage, and key indicators such as the number of I / O operations that may occur. In practical applications, the execution feedback of the latest query statements can be continuously collected, and the parameters of the overhead prediction model can be dynamically updated through an online learning mechanism, so that the prediction capability can continuously evolve as the database system runs.
[0200] Specifically, in some embodiments, the first sample query plan tree includes multiple levels, each level including at least one node; the first query features corresponding to the first sample query plan tree are extracted through a cost prediction model, including:
[0201] Obtain the node attribute information of each node;
[0202] The node attribute information is encoded by the cost prediction model to obtain the node features corresponding to each node;
[0203] The second-to-last layer in the first sample query plan tree is determined as the layer to be processed. The feature aggregation of each node to be processed in the layer to be processed is performed by the cost prediction model to obtain the new node features corresponding to each node to be processed.
[0204] Check whether the current layer to be processed is the first layer in the first sample query plan tree;
[0205] If the current layer to be processed is not the first layer in the first sample query plan tree, determine the layer above the layer to be processed in the first sample query plan tree as the new layer to be processed, and return to execute the step of feature aggregation of each node to be processed in the layer to be processed through the cost prediction model.
[0206] If the current layer to be processed is the first layer in the first sample query plan tree, the node feature corresponding to the root node of the first sample query plan tree is determined as the first query feature.
[0207] In this embodiment, the cost prediction model can employ a Tree-CNN pattern, using a hierarchical feature extraction method to extract features from the query plan tree. Here, the Tree-CNN is a convolutional neural network specifically designed for tree-shaped data structures. It can directly process the query plan tree structure through hierarchical convolution operations, automatically extracting node features (such as operator types and table statistics) while preserving topological relationships.
[0208] Specifically, in this embodiment, the first sample query plan tree can include multiple different levels, each level including at least one node. When extracting the first query features corresponding to the first sample query plan tree, each node in the first sample query plan tree can be parsed to extract node attribute information including operator type (e.g., scan, join, aggregation), estimated data processing volume, algorithm parameters (e.g., hash table bucket size), and resource requirements (e.g., memory buffer size). These original node attributes can be converted into high-dimensional numerical vectors through an embedding layer to form initial node features. The specific data format of the node features can be numerical, vector, etc., and this application does not impose any restrictions on this. For example, a hash join node may be encoded as a feature vector containing dimensions such as join type, estimated number of input rows, and memory usage markers. This encoding method preserves the original semantics and provides a suitable input format for subsequent neural network processing.
[0209] In this embodiment of the application, after determining the node features corresponding to each node, the cost prediction model can start from the second-to-last layer of the first sample query plan tree (because the last layer has no child nodes, so there is no need to aggregate features from the bottom) and perform feature fusion layer by layer upwards.
[0210] Specifically, the penultimate layer of the first sample query plan tree can be used as the starting layer to be processed. For each node in the current layer, the cost prediction model collects the node features of all its child nodes and performs aggregation calculations through the message passing mechanism of the graph neural network. This effectively captures the hierarchical features in the first sample query plan tree, fusing features from lower layers into nodes in higher layers. After the current layer to be processed is fused, it is checked whether the current layer is the first layer in the first sample query plan tree. If it is, it means that it has been fused to the root node of the first sample query plan tree, and the node features corresponding to the root node can be determined as the first query feature. If it is not the first layer in the first sample query plan tree, it means that fusion can continue upwards. At this point, the layer above the current layer in the first sample query plan tree can be determined as the new layer to be processed, and the feature fusion operation continues until it is fused to the first layer in the first sample query plan tree.
[0211] It is understood that in this embodiment of the application, the node feature fusion in the first sample query plan tree can be achieved by using hierarchical convolution, which can better reflect the features contained in the original topological structure of the first sample query plan tree without the need for manual flattening into feature vectors.
[0212] Specifically, in some embodiments, feature aggregation is performed on each node to be processed in the processing layer using an overhead prediction model, including:
[0213] Based on the cost prediction model, the shared convolutional kernel corresponding to the current layer to be processed is determined; wherein, the cost prediction model includes multiple different shared convolutional kernels, and each shared convolutional kernel corresponds to a level of the query plan tree;
[0214] Determine the first node from the nodes to be processed; wherein, the first node is the node to be processed that includes child nodes;
[0215] By sharing a convolutional kernel, feature aggregation is performed on the first node and its corresponding child nodes.
[0216] In this embodiment of the application, during the feature aggregation process of the first sample query plan tree, the cost prediction model can use a hierarchical shared convolutional kernel-based neural network architecture to achieve differentiated modeling of features at different levels.
[0217] Specifically, in this embodiment, the cost prediction model predefines specific shared convolutional kernels for each level of the query plan tree. These convolutional kernels are essentially a set of learnable weight matrices that can capture the feature interaction patterns between nodes at that level and their child nodes. Each shared convolutional kernel corresponds to a level in the query plan tree, and different levels correspond to different shared convolutional kernels. For example, for intermediate layers with dense join operations, the corresponding shared convolutional kernel can focus on learning the feature transformation rules of various join algorithms (such as hash joins and nested loop joins); while for the bottom layer where leaf nodes are located (and the parts close to the bottom layer), the corresponding shared convolutional kernel can focus more on feature extraction of data access paths (such as index scans and full table scans). This hierarchical parameter sharing mechanism not only ensures the model's ability to distinguish features at different levels, but also effectively controls the model complexity through weight reuse.
[0218] For each node in the processing layer, during feature aggregation, non-leaf nodes (i.e., nodes with child nodes) can be identified and designated as first nodes. For each first node, the cost prediction model loads the shared convolutional kernel of the corresponding layer and performs graph convolution on the node features of the first node and the node features of all its child nodes. This process is similar to extracting local features using a sliding convolutional kernel in image processing, but in structured data such as query plan trees, the convolution operation follows the tree topology. For example, when processing a hash join node, the convolutional kernel simultaneously analyzes the node's own attributes (such as join key and estimated result set size) and the features of its child nodes (such as left table scanning method and right table filtering conditions), generating a fused new feature representation through nonlinear transformation.
[0219] In this embodiment, the cost prediction model can obtain semantically rich node feature representations through hierarchical convolution, providing a reliable basis for subsequent execution cost prediction. Throughout the aggregation process, the structural information of the query plan tree is fully preserved, while parameter sharing achieves a lightweight approach to the cost prediction model.
[0220] Specifically, in some embodiments, reference is made to Figure 8 The cost prediction model is trained through the following steps:
[0221] Step 810: Obtain multiple second sample query plan trees and the labels corresponding to each second sample query plan tree; wherein, the labels are used to characterize the actual results of the execution overhead data corresponding to the second sample query plan tree;
[0222] Step 820: Input the second sample query plan tree into the cost prediction model to be optimized, and extract the second query features corresponding to the second sample query plan tree through the cost prediction model;
[0223] Step 830: Based on the second query features, perform regression prediction using the cost prediction model to obtain the second prediction execution cost data corresponding to the second sample query plan tree;
[0224] Step 840: Determine the training loss value based on the label corresponding to the second sample query plan tree and the second prediction execution overhead data;
[0225] Step 850: Update the parameters of the cost prediction model based on the loss value to obtain the trained cost prediction model.
[0226] For cost prediction models, training is required before deployment to achieve optimal performance. This application also provides a training method for a cost prediction model. Specifically, during training, training data can be acquired. This training data may include batches of query plan trees and their corresponding labels. In this application, these query plan trees are referred to as second sample query plan trees, and the labels can be used to characterize the actual results of the execution cost data corresponding to the second sample query plan trees. The specific type of execution cost data can be implemented as described in the foregoing embodiments, and this application does not impose any limitations on it.
[0227] During training, the second sample query plan tree can be input into the cost prediction model to be optimized. The cost prediction model extracts the features corresponding to the second sample query plan tree, which are denoted as the second query features. The extraction method is similar to that of the first query features and will not be elaborated here. Based on the second query features, regression prediction can be performed through the cost prediction model to obtain the predicted execution cost data corresponding to the second sample query plan tree. In this embodiment, this is denoted as the second predicted execution cost data.
[0228] It is understood that in this embodiment, if the query decision model has a good predictive performance, then the second prediction execution cost data and labels corresponding to the second sample query plan tree should be relatively close. Therefore, in this embodiment, the accuracy of the query decision model's prediction can be determined based on the second prediction execution cost data and labels. Specifically, the deviation between the second prediction execution cost data and labels can be determined to obtain the loss value predicted by the query decision model. After obtaining the loss value, the prediction accuracy of the query decision model can be evaluated based on the magnitude of the loss value, so as to train the query decision model and update its internal parameters.
[0229] Specifically, in the field of artificial intelligence, the accuracy of a model's predictions can be measured by a loss function. The loss function is defined on a single training data point and measures the prediction error of that data point. Specifically, the loss value is determined by the label of that individual training data point and the model's prediction result for that data. However, in actual training, a training dataset contains many data points. Therefore, a cost function is generally used to measure the overall error of the training dataset. The cost function is defined on the entire training dataset and calculates the average prediction error of all training data points, providing a better measure of the model's prediction performance. For a typical model, the aforementioned cost function, plus a regularization term to measure model complexity, forms the training objective function. Based on this objective function, the loss value for the entire training dataset can be calculated.
[0230] For example, in some embodiments, the labels may include execution time labels and resource consumption labels, representing the actual results of the predicted execution time data and predicted resource consumption data of the second sample query plan tree, respectively. The second predicted execution cost data may correspond to predicted execution time data and predicted resource consumption data. When determining the training loss value, a training loss value can be determined based on the execution time label and the predicted execution time data, denoted as the first sub-loss value. Then, another training loss value can be determined based on the resource consumption label and the predicted resource consumption data, denoted as the second sub-loss value. Next, the first sub-loss value and the second sub-loss value can be weighted and summed to obtain the training loss value. The relevant formula can be expressed as:
[0231] Loss=α·|T_pred-T_real|2+β·|R_pred-R_monitor|2
[0232] In the formula, Loss represents the loss value, T_pred represents the predicted execution time data, T_real represents the execution time label, R_pred represents the predicted resource consumption data, R_monitor represents the resource consumption label, and α and β are weighted weights, the sum of which can be set to 1.
[0233] Correspondingly, for the data format of the aforementioned predicted execution cost data, the reward value corresponding to the first action decision can be calculated using the following formula:
[0234] R=-log(Query Latency)-λ·Resource Cost
[0235] In the formula, R represents the reward value, Query Latency represents the execution time data, and Resource Cost represents the resource consumption data.
[0236] In this embodiment, the conditions for training termination can be flexibly set according to requirements. For example, in some embodiments, a target number of training iterations can be set as the condition for training termination. When the update cycle of the query decision model's parameters reaches the target number of iterations, training can be considered complete. In some embodiments, relevant evaluation metrics can be set. When the evaluation metrics meet preset requirements, training can be considered complete. These evaluation metrics can include accuracy, precision, recall, F1 score, etc. To ensure the stability and reliability of the evaluation results, cross-validation can be used, that is, the dataset is divided into a training set and a test set, training is performed on the training set, and the evaluation metrics are validated on the test set.
[0237] Of course, the above are merely exemplary descriptions of some optional training termination conditions in the embodiments of this application, and do not imply any limitation on the actual implementation.
[0238] Please refer to Figure 9 , Figure 9 This illustration shows a flowchart of a database query method provided in an embodiment of this application. This database query method can be applied to an application client or a backend server, and the client can be installed and deployed on, for example, a... Figure 2 On the terminal device 240 shown, the backend server can be Figure 2 The backend server 210 is shown. (For example...) Figure 9 As shown, a database query method according to one embodiment of this application includes, but is not limited to, the following steps:
[0239] Step 910: Obtain the target query statement;
[0240] Step 920: Input the target query statement into the original query optimizer, and generate a set of target query plans corresponding to the target query statement through the original query optimizer; wherein, the set of target query plans includes at least one target query plan tree;
[0241] Step 930: Determine the state value based on the target query statement and the database, and determine the target action decision corresponding to the target query statement from the target query plan tree using the query decision model trained by the aforementioned training method; wherein, the query decision model includes a reinforcement learning model;
[0242] Step 940: Execute the target action decision in the database and obtain the query results.
[0243] In this embodiment of the application, based on the aforementioned training method for the query decision model, a database query method is also provided. Specifically, after the query decision model is trained, it can be put into use; for example, data queries within a database can be performed based on the trained query decision model.
[0244] Please refer to Figure 10 , Figure 10 This illustration shows a schematic diagram of the specific implementation process of a database query method provided in an embodiment of this application, such as... Figure 10 As shown in this embodiment, when performing a data query, a target query statement can be obtained, and one or more target query plan trees can be determined by the original query optimizer. Then, based on the query decision model trained in this embodiment, the target action decision corresponding to the target query statement can be determined from the target query plan tree. The target action decision is executed through the database, and the overhead data during the execution process can be collected to facilitate updating the query decision model (such as the overhead prediction model).
[0245] Specifically, in this embodiment, the query decision model can first mimic the decisions of the traditional original query optimizer to avoid the cold start disaster. Furthermore, a near-end strategy optimization can be used for reinforcement learning fine-tuning. Before deploying new query business logic, it runs in shadow mode, comparing its decisions with the original query optimizer's performance. Only when the new query business logic outperforms the original query optimizer is it deployed to the production environment. If anomalies are found after deployment, such as increased query latency, the system can roll back to the original query optimizer version.
[0246] The technical solution of this application has at least the following advantages:
[0247] (1) Significantly improves the execution efficiency of complex queries. In complex scenarios such as multi-table joins (>5-table joins) and nested subqueries, this application reduces the estimation bias of traditional optimizers by accurately modeling the query plan tree structure, achieving an average query speedup of 20% to 50%. Compared with cost models based on static rules, this application can more accurately evaluate the true performance of different execution plans and avoid inefficient plan selection due to incorrect cost estimation.
[0248] (2) Significantly improves tail latency, enhances stability, and reduces the cliff effect: Traditional optimizers may suddenly generate extremely slow execution plans (such as incorrectly choosing a full table scan instead of an index scan) due to inaccurate statistical information or defects in the cost model. This application reduces tail latency by more than 40% by combining the end-to-end learning capability of the cost prediction model with dynamic adjustment through online reinforcement learning, thus reducing the occurrence of abnormally slow queries. Even when data distribution changes abruptly (such as index failure or a surge in table size), the model can still adjust its strategy based on real-time feedback to avoid a precipitous drop in performance.
[0249] (3) Adaptive dynamic load, continuous optimization without manual intervention. Traditional optimizers require periodic manual updates of statistics or adjustment of cost parameters, while this application uses a reinforcement learning-based continuous fine-tuning mechanism to automatically adapt to changes in data distribution (such as the addition of new indexes or increased data skew), and the model performance can continuously improve with changes in query load after deployment.
[0250] It is understandable that, such as Figure 5 The content of the training method embodiment of the query decision model shown is applicable to the database query method embodiment of this invention. The specific functions implemented in the database query method embodiment of this invention are the same as those shown in the figure. Figure 5 The training method of the query decision model shown is the same as that of the example, and the beneficial effects achieved are the same as those shown. Figure 5 The beneficial effects achieved by the training method embodiment of the query decision model shown are also the same.
[0251] Reference Figure 11 In this embodiment of the application, a training apparatus for a query decision model is also provided, the training apparatus for the query decision model comprising:
[0252] The first acquisition unit 1110 is used to acquire multiple sample query statements for the database;
[0253] The first generation unit 1120 is used to input each sample query statement into the original query optimizer and generate a sample query plan set corresponding to each sample query statement through the original query optimizer; wherein, the sample query plan set includes at least one first sample query plan tree;
[0254] The prediction unit 1130 is used to predict the execution cost of each first sample query plan tree and obtain the predicted execution cost data corresponding to each first sample query plan tree.
[0255] The first selection unit 1140 is used to determine the state value based on the sample query statement and the database, and to determine any first sample query plan tree as the first action decision corresponding to the sample query statement from the sample query plan set corresponding to the sample query statement through a reinforcement learning model.
[0256] The update unit 1150 is used to determine the reward value corresponding to the first action decision based on the predicted execution cost data corresponding to the first action decision, and update the parameters of the reinforcement learning model based on the reward value.
[0257] Optionally, in some embodiments, the first generating unit is specifically used for:
[0258] The sample query statement is input into the original query optimizer, which parses the sample query statement to obtain the abstract syntax tree corresponding to the sample query statement.
[0259] By processing the abstract syntax tree using equivalent transformation rules, at least one logical query plan corresponding to the sample query statement is obtained.
[0260] Based on each logical query plan, the database operators are combined and enumerated by the original query optimizer to obtain at least one first sample query plan tree corresponding to the sample query statement.
[0261] Optionally, in some embodiments, the first generating unit is specifically used for:
[0262] Lexical analysis was performed on the sample query statement to obtain multiple lexical units;
[0263] Lexical verification is performed on the sample query statement based on the lexical unit;
[0264] If the sample query statement is determined to pass lexical verification, an abstract syntax tree corresponding to the sample query statement is constructed based on each lexical unit.
[0265] Optionally, in some embodiments, the first generating unit is specifically used for:
[0266] Multiple raw query plan trees are obtained by combining and enumerating the database operators through the raw query optimizer.
[0267] The execution cost data corresponding to each raw query plan tree is determined by the raw query optimizer;
[0268] The first sample query plan tree is determined by identifying at least one original query plan tree with the smaller corresponding execution cost data.
[0269] Optionally, in some embodiments, the query decision model further includes an expense prediction model; the prediction unit is specifically used for:
[0270] The first sample query plan tree is input into the pre-trained cost prediction model, and the first query feature corresponding to the first sample query plan tree is extracted through the cost prediction model.
[0271] Based on the first query feature, regression prediction is performed using an overhead prediction model to obtain the predicted execution overhead data corresponding to the first sample query plan tree.
[0272] Optionally, in some embodiments, the first sample query plan tree includes multiple levels, each level including at least one node; the prediction unit is specifically used for:
[0273] Obtain the node attribute information of each node;
[0274] The node attribute information is encoded by the cost prediction model to obtain the node features corresponding to each node;
[0275] The second-to-last layer in the first sample query plan tree is determined as the layer to be processed. The feature aggregation of each node to be processed in the layer to be processed is performed by the cost prediction model to obtain the new node features corresponding to each node to be processed.
[0276] Check whether the current layer to be processed is the first layer in the first sample query plan tree;
[0277] If the current layer to be processed is not the first layer in the first sample query plan tree, determine the layer above the layer to be processed in the first sample query plan tree as the new layer to be processed, and return to execute the step of feature aggregation of each node to be processed in the layer to be processed through the cost prediction model.
[0278] If the current layer to be processed is the first layer in the first sample query plan tree, the node feature corresponding to the root node of the first sample query plan tree is determined as the first query feature.
[0279] Optionally, in some embodiments, the prediction unit is specifically used for:
[0280] Based on the cost prediction model, the shared convolutional kernel corresponding to the current layer to be processed is determined; wherein, the cost prediction model includes multiple different shared convolutional kernels, and each shared convolutional kernel corresponds to a level of the query plan tree;
[0281] Determine the first node from the nodes to be processed; wherein, the first node is the node to be processed that includes child nodes;
[0282] By sharing a convolutional kernel, feature aggregation is performed on the first node and its corresponding child nodes.
[0283] Optionally, in some embodiments, the training device further includes a first training unit, which is specifically used for:
[0284] Obtain multiple second-sample query plan trees and the corresponding labels for each second-sample query plan tree; where the labels are used to characterize the actual results of the execution overhead data corresponding to the second-sample query plan tree;
[0285] The second sample query plan tree is input into the cost prediction model to be optimized, and the second query features corresponding to the second sample query plan tree are extracted through the cost prediction model.
[0286] Based on the second query features, regression prediction is performed using the cost prediction model to obtain the second prediction execution cost data corresponding to the second sample query plan tree;
[0287] The training loss value is determined based on the label corresponding to the second sample query plan tree and the second prediction execution overhead data.
[0288] Based on the loss value, the parameters of the cost prediction model are updated to obtain the trained cost prediction model.
[0289] Optionally, in some embodiments, the labels include execution time labels and resource consumption labels, and the second predicted execution overhead data includes predicted execution time data and predicted resource consumption data; the first training unit is specifically used for:
[0290] The first sub-loss value for training is determined based on the execution time label and the predicted execution time data;
[0291] The second sub-loss value for training is determined based on the resource consumption labels and predicted resource consumption data;
[0292] The first and second sub-loss values are weighted and summed to obtain the training loss value.
[0293] It is understandable that, such as Figure 5 The content of the training method embodiments of the query decision model shown is applicable to the training device embodiments of this query decision model. The specific functions implemented by the training device embodiments of this query decision model are as follows: Figure 5 The training method of the query decision model shown is the same as that of the example, and the beneficial effects achieved are the same as those shown. Figure 5 The beneficial effects achieved by the training method embodiment of the query decision model shown are also the same.
[0294] On the other hand, embodiments of this application provide a database query apparatus, the apparatus comprising:
[0295] The second acquisition unit is used to acquire the target query statement;
[0296] The second generation unit is used to input the target query statement into the original query optimizer and generate a set of target query plans corresponding to the target query statement through the original query optimizer; wherein, the set of target query plans includes at least one target query plan tree;
[0297] The second selection unit is used to determine the state value based on the target query statement and the database, and to determine the target action decision corresponding to the target query statement from the target query plan tree through the query decision model trained by the aforementioned training method; wherein, the query decision model includes a reinforcement learning model;
[0298] The execution unit is used to execute target action decisions in the database and obtain query results.
[0299] It is understandable that, such as Figure 9 The content of the database query method embodiments shown is applicable to the database query device embodiments. The specific functions implemented by the database query device embodiments are the same as those shown in the examples. Figure 9 The database query method shown in the embodiment is the same, and the beneficial effects achieved are the same as those shown. Figure 9 The beneficial effects achieved by the database query method embodiment shown are also the same.
[0300] This application also discloses an electronic device, including:
[0301] At least one processor;
[0302] At least one memory for storing at least one program;
[0303] When at least one program is executed by at least one processor, such that at least one processor implements as Figure 5 The training method embodiment of the query decision model shown is or Figure 9 The database query method shown is an example.
[0304] The electronic device in the embodiments of this application may be a terminal device, a computer device, or a server device.
[0305] For example, refer to Figure 12 , Figure 12 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Taking a terminal device as an example, Figure 12 In this context, the electronic device 1200 may include an RF (Radio Frequency) circuit 1210, a memory 1220 including one or more computer-readable storage media, an input unit 1230, a display unit 1240, a sensor 1250, an audio circuit 1260, a short-range wireless transmission module 1270, a processor 1280 including one or more processing cores, and a power supply 1290, among other components. Those skilled in the art will understand that... Figure 12 The device structure shown does not constitute a limitation on the terminal device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0306] RF circuit 1210 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink information from the base station and hands it over to one or more processors 1280 for processing; additionally, it transmits uplink data to the base station. Typically, RF circuit 1210 includes, but is not limited to, an antenna, at least one amplifier, a tuner, one or more oscillators, a SIM card, a transceiver, a coupler, an LNA (Low Noise Amplifier), a duplexer, etc. Furthermore, RF circuit 1210 can also communicate wirelessly with networks and other devices. Wireless communication can use any communication standard or protocol, including but not limited to GSM (Global System for Mobile communication), GPRS (General Packet Radio Service), CDMA (Code Division Multiple Access), WCDMA (Wideband Code Division Multiple Access), LTE (Long Term Evolution), email, SMS (Short Messaging Service), etc.
[0307] Memory 1220 can be used to store software programs and modules (or units). Processor 1280 executes various functional applications and data processing by running the software programs and modules (or units) stored in memory 1220. Memory 1220 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created based on the use of electronic device 1200 (such as audio data, telephone directory, etc.). Furthermore, memory 1220 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, memory 1220 may also include a memory controller to provide access to memory 1220 for processor 1280 and input unit 1230. Although Figure 12 The RF circuit 1210 is shown, but it is understood that it is not a necessary component of the electronic device 1200 and can be omitted as needed without changing the nature of the invention.
[0308] The input unit 1230 can be used to receive input numerical or character information, and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to object settings and function control. Specifically, the input unit 1230 may include a touch-sensitive surface 1231 and other input devices 1232. The touch-sensitive surface 1231, also known as a touch display screen or touchpad, can collect touch operations on or near the object (such as operations performed by the object using a finger, stylus, or any suitable object or accessory on or near the touch-sensitive surface 1231), and drive the corresponding connection device according to a pre-set program. Optionally, the touch-sensitive surface 1231 may include two parts: a touch detection device and a touch controller. The touch detection device detects the touch position of the object and detects the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, sends it to the processor 1280, and can receive and execute instructions from the processor 1280. In addition, the touch-sensitive surface 1231 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. Besides the touch-sensitive surface 1231, the input unit 1230 may also include other input devices 1232. Specifically, other input devices 1232 may include, but are not limited to, one or more of the following: a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), a trackball, a mouse, and a joystick.
[0309] The display unit 1240 can be used to display information input by an object or information provided to an object, as well as various graphical object interfaces for controlling the electronic device 1200. These graphical object interfaces can be composed of graphics, text, icons, video, and any combination thereof. The display unit 1240 may include a display panel 1241, which may optionally be configured as an LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode), or similar display. Further, a touch-sensitive surface 1231 may cover the display panel 1241. When the touch-sensitive surface 1231 detects a touch operation on or near it, it transmits the information to the processor 1280 to determine the type of touch event. Subsequently, the processor 1280 provides corresponding visual output on the display panel 1241 according to the type of touch event. Although in Figure 12 In this embodiment, the touch-sensitive surface 1231 and the display panel 1241 are implemented as two separate components to realize input and output functions. However, in some embodiments, the touch-sensitive surface 1231 and the display panel 1241 can be integrated to realize input and output functions.
[0310] The electronic device 1200 may also include at least one sensor 1250, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 1241 according to the ambient light level, and the proximity sensor can turn off the display panel 1241 or the backlight when the electronic device 1200 is moved to the ear. As a type of motion sensor, a gravity acceleration sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used for applications that recognize the phone's posture (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition-related functions (such as pedometers, taps), etc. Other sensors that the electronic device 1200 may also be configured with, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here.
[0311] Audio circuitry 1260, speaker 1261, and microphone 1262 provide an audio interface between the device and electronic device 1200. Audio circuitry 1260 converts received audio data into electrical signals and transmits them to speaker 1261, where speaker 1261 converts them into sound signals for output. Conversely, microphone 1262 converts collected sound signals into electrical signals, which are then received by audio circuitry 1260, converted back into audio data, processed by processor 1280, and transmitted via RF circuitry 1210 to another electronic device, or output to memory 1220 for further processing. Audio circuitry 1260 may also include an earphone jack to facilitate communication between external headphones and electronic device 1200.
[0312] The short-range wireless transmission module 1270 can be a WIFI (wireless fidelity) module, Bluetooth module, or infrared module, etc. The electronic device 1200 can transmit information with wireless transmission modules on other devices via the short-range wireless transmission module 1270.
[0313] The processor 1280 is the control center of the electronic device 1200. It connects various parts of the device via various interfaces and lines, and performs various functions and processes data of the electronic device 1200 by running or executing software programs or modules stored in the memory 1220 and calling data stored in the memory 1220, thereby providing overall control of the device. Optionally, the processor 1280 may include one or more processing cores; optionally, the processor 1280 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and application programs, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor 1280.
[0314] Electronic device 1200 also includes a power supply 1290 (such as a battery) for supplying power to various components. Optionally, the power supply 1290 can be logically connected to the processor 1280 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 1290 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0315] Although not shown, the electronic device 1200 may also include a camera, Bluetooth module, etc., which will not be described in detail here.
[0316] This application also discloses a computer-readable storage medium storing a processor-executable program, which, when executed by a processor, is used to implement, for example... Figure 5 The training method embodiment of the query decision model shown is or Figure 9 The database query method shown is an example.
[0317] Understandable, Figure 5 The training method embodiment of the query decision model shown is or Figure 9 The content of the database query method embodiments shown is applicable to the embodiments of this computer-readable storage medium. The specific functions implemented by the embodiments of this computer-readable storage medium are the same as those shown in the embodiments. Figure 5 The training method embodiment of the query decision model shown is or Figure 9 The database query method shown in the embodiment is the same, and the beneficial effects achieved are the same. Figure 5 The training method embodiment of the query decision model shown is or Figure 9 The beneficial effects achieved by the database query method embodiment shown are also the same.
[0318] This application also discloses a computer program product or computer program, which includes computer instructions stored in the aforementioned computer-readable storage medium. Figure 12 The processor of the illustrated electronic device can read the computer instructions from the aforementioned computer-readable storage medium, and the processor executes the computer instructions, causing the computer device to perform... Figure 5 The training method embodiment of the query decision model shown is or Figure 9 The database query method shown is an example.
[0319] Understandable, Figure 5 The training method embodiment of the query decision model shown is or Figure 9The content of the database query method embodiments shown is applicable to this computer program product or computer program embodiment. The specific functions implemented by this computer program product or computer program embodiment are the same as those shown in the embodiments. Figure 5 The training method embodiment of the query decision model shown is or Figure 9 The database query method shown in the embodiment is the same, and the beneficial effects achieved are the same. Figure 5 The training method embodiment of the query decision model shown is or Figure 9 The beneficial effects achieved by the database query method embodiment shown are also the same.
[0320] In some alternative embodiments, the functions / operations mentioned in the block diagrams may not occur in the order shown in the operation diagrams. For example, depending on the functions / operations involved, two consecutively shown blocks may actually be executed substantially simultaneously, or the blocks may sometimes be executed in reverse order. Furthermore, the embodiments presented and described in the flowcharts of this application are provided by way of example to provide a more comprehensive understanding of the technology. The disclosed methods are not limited to the operations and logic flows presented herein. Alternative embodiments are contemplated in which the order of various operations is changed and sub-operations described as part of a larger operation are executed independently.
[0321] Furthermore, although this application is described in the context of functional modules, it should be understood that, unless otherwise stated to the contrary, one or more of the functions and / or features may be integrated into a single physical device and / or software module, or one or more functions and / or features may be implemented in a separate physical device or software module. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding this application. Rather, given the properties, functions, and internal relationships of the various functional modules in the apparatus disclosed herein, the actual implementation of the module will be understood within the scope of conventional technology for an engineer. Therefore, those skilled in the art can implement the application set forth in the claims using ordinary techniques without excessive experimentation. It is also understood that the specific concepts disclosed are merely illustrative and not intended to limit the scope of this application, which is determined by the full scope of the appended claims and their equivalents.
[0322] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes at least one instruction to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0323] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0324] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable storage medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable storage medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0325] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0326] In the foregoing description of this specification, the references to terms such as "one embodiment," "another embodiment," or "some embodiments," etc., indicate that a specific feature, structure, material, or characteristic described in connection with an embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0327] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
[0328] The above is a detailed description of the preferred embodiments of this application, but this application is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application, and these equivalent modifications or substitutions are all included within the scope defined by the claims of this application.
Claims
1. A training method for a query decision model, characterized in that, The query decision model includes a reinforcement learning model; the method includes: Retrieve multiple sample query statements for the database; Each of the sample query statements is input into the original query optimizer, which generates a set of sample query plans for each sample query statement; wherein the set of sample query plans includes at least one first sample query plan tree; The execution cost of each first sample query plan tree is predicted to obtain the predicted execution cost data for each first sample query plan tree; Based on the sample query statement and the database, a state value is determined, and any first sample query plan tree is determined from the sample query plan set corresponding to the sample query statement as the first action decision corresponding to the sample query statement through the reinforcement learning model; Based on the predicted execution cost data corresponding to the first action decision, the reward value corresponding to the first action decision is determined, and the parameters of the reinforcement learning model are updated based on the reward value.
2. The training method for the query decision model according to claim 1, characterized in that, The step of inputting each of the sample query statements into the original query optimizer, and generating a set of sample query plans corresponding to each sample query statement through the original query optimizer, includes: The sample query statement is input into the original query optimizer, which parses the sample query statement to obtain the abstract syntax tree corresponding to the sample query statement. The abstract syntax tree is processed by equivalent transformation rules to obtain at least one logical query plan corresponding to the sample query statement; Based on each of the logical query plans, the original query optimizer performs combined enumeration of the database operators to obtain at least one first sample query plan tree corresponding to the sample query statement.
3. The training method for the query decision model according to claim 2, characterized in that, The step of parsing the sample query statement to obtain the abstract syntax tree corresponding to the sample query statement includes: Lexical analysis was performed on the sample query statement to obtain multiple lexical units; The sample query statement is lexically verified based on the lexical unit. If the sample query statement is determined to pass lexical verification, an abstract syntax tree corresponding to the sample query statement is constructed based on each lexical unit.
4. The training method for the query decision model according to claim 2, characterized in that, The step of combining and enumerating the operators of the database through the original query optimizer to obtain at least one first sample query plan tree corresponding to the sample query statement includes: The original query optimizer combines and enumerates the operators of the database to obtain multiple original query plan trees; The execution cost data corresponding to each of the original query plan trees is determined by the original query optimizer. The first sample query plan tree is determined by identifying at least one original query plan tree with the smaller corresponding execution cost data.
5. The training method for the query decision model according to claim 1, characterized in that, The query decision model also includes an overhead prediction model; the step of predicting the execution overhead of each first sample query plan tree to obtain the predicted execution overhead data corresponding to each first sample query plan tree includes: The first sample query plan tree is input into a pre-trained cost prediction model, and the first query feature corresponding to the first sample query plan tree is extracted through the cost prediction model. Based on the first query feature, regression prediction is performed using the cost prediction model to obtain the predicted execution cost data corresponding to the first sample query plan tree.
6. The training method for the query decision model according to claim 5, characterized in that, The first sample query plan tree includes multiple levels, and each level includes at least one node; the step of extracting the first query feature corresponding to the first sample query plan tree through the cost prediction model includes: Obtain the node attribute information of each of the nodes; The node attribute information is encoded using the overhead prediction model to obtain the node features corresponding to each node; The second-to-last layer in the first sample query plan tree is determined as the layer to be processed. The feature aggregation of each node to be processed in the layer to be processed is performed by the cost prediction model to obtain new node features corresponding to each node to be processed. Detect whether the current layer to be processed is the first layer in the first sample query plan tree; If the current layer to be processed is not the first layer in the first sample query plan tree, the layer above the layer to be processed in the first sample query plan tree is determined as the new layer to be processed, and the step of performing feature aggregation on each node to be processed in the layer to be processed by the cost prediction model is returned. If the current layer to be processed is the first layer in the first sample query plan tree, the node feature corresponding to the root node of the first sample query plan tree is determined as the first query feature.
7. The training method for the query decision model according to claim 6, characterized in that, The step of performing feature aggregation on each node of the layer to be processed using the overhead prediction model includes: Based on the cost prediction model, the shared convolutional kernel corresponding to the current layer to be processed is determined; wherein, the cost prediction model includes multiple different shared convolutional kernels, and each shared convolutional kernel corresponds to a level in the query plan tree; A first node is determined from the nodes to be processed; wherein the first node is a node to be processed that includes child nodes; The first node and its corresponding child nodes are feature aggregated using the shared convolutional kernel.
8. The training method for the query decision model according to claim 5, characterized in that, The cost prediction model is trained through the following steps: Obtain multiple second sample query plan trees and the labels corresponding to each second sample query plan tree; wherein, the labels are used to characterize the actual results of the execution overhead data corresponding to the second sample query plan tree; The second sample query plan tree is input into the cost prediction model to be optimized, and the second query feature corresponding to the second sample query plan tree is extracted through the cost prediction model. Based on the second query feature, regression prediction is performed through the cost prediction model to obtain the second prediction execution cost data corresponding to the second sample query plan tree; The training loss value is determined based on the label corresponding to the second sample query plan tree and the second prediction execution overhead data; Based on the loss value, the parameters of the cost prediction model are updated to obtain a trained cost prediction model.
9. The training method for the query decision model according to claim 8, characterized in that, The labels include execution time labels and resource consumption labels, and the second predicted execution cost data includes predicted execution time data and predicted resource consumption data; the step of determining the training loss value based on the labels corresponding to the second sample query plan tree and the second predicted execution cost data includes: Based on the execution time label and the predicted execution time data, determine the first sub-loss value for training; Based on the resource consumption label and the predicted resource consumption data, determine the second sub-loss value for training; The first sub-loss value and the second sub-loss value are weighted and summed to obtain the training loss value.
10. A database query method, characterized in that, The method includes: Retrieve the target query statement; The target query statement is input into the original query optimizer, which generates a set of target query plans corresponding to the target query statement; wherein the set of target query plans includes at least one target query plan tree; Based on the target query statement and the database, a state value is determined, and a query decision model trained using any one of the training methods described in claims 1-9 determines the target action decision corresponding to the target query statement from the target query plan tree; wherein, the query decision model includes a reinforcement learning model; The target action decision is executed in the database to obtain the query results.
11. A training device for a query decision model, characterized in that, The query decision model includes a reinforcement learning model; the device includes: The first acquisition unit is used to acquire multiple sample query statements for the database; The first generation unit is used to input each of the sample query statements into the original query optimizer, and generate a sample query plan set corresponding to each sample query statement through the original query optimizer; wherein, the sample query plan set includes at least one first sample query plan tree; The prediction unit is used to predict the execution cost of each of the first sample query plan trees and obtain the predicted execution cost data corresponding to each of the first sample query plan trees. The first selection unit is used to determine a state value based on the sample query statement and the database, and to determine any first sample query plan tree as the first action decision corresponding to the sample query statement from the sample query plan set corresponding to the sample query statement through the reinforcement learning model. The update unit is configured to determine the reward value corresponding to the first action decision based on the prediction execution cost data corresponding to the first action decision, and update the parameters of the reinforcement learning model based on the reward value.
12. A database query device, characterized in that, The device includes: The second acquisition unit is used to acquire the target query statement; The second generation unit is used to input the target query statement into the original query optimizer, and generate a set of target query plans corresponding to the target query statement through the original query optimizer; wherein, the set of target query plans includes at least one target query plan tree; The second selection unit is configured to determine a state value based on the target query statement and the database, and determine the target action decision corresponding to the target query statement from the target query plan tree using a query decision model trained by the training method as described in any one of claims 1-9; wherein the query decision model includes a reinforcement learning model; The execution unit is used to execute the target action decision in the database and obtain the query results.
13. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the training method of the query decision model according to any one of claims 1 to 9 or the database query method according to claim 10.
14. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the training method of the query decision model according to any one of claims 1 to 9 or the database query method according to claim 10.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the training method of the query decision model according to any one of claims 1 to 9 or the database query method according to claim 10.
