Data query method, device, equipment, medium and program product
Patent Information
- Application Number
- CN202510615421.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-13
- Publication Date
- 2026-10-30
AI Technical Summary
[0004]然而,当数据库的复杂性增加时,基于代价的优化器需要枚举的候选执行计划数量会显著增加,从而大大的增加对执行计划的分析时长,降低了查询语句的执行效率
[0018]根据本申请实施例的一个方面,提供了一种计算机程序产品,所述计算机程序产品包括计算机程序,所述计算机程序存储在计算机可读存储介质中,处理器从所述计算机可读存储介质读取并执行所述计算机程序,以实现上述数据查询方。
Smart Images

Figure CN123011940A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data query method, apparatus, device, medium, and program product. Background Technology
[0002] An execution plan is a detailed operational plan generated by the database optimizer for a given query statement. The execution plan includes the specific steps taken when executing a given query statement in the database, such as the table access method, the join order, and the use of indexes.
[0003] In related technologies, during database runtime, a cost-based optimizer can be used to analyze a given query statement. The cost-based optimizer uses the database's statistical information to enumerate multiple candidate execution plans, and then selects the candidate execution plan with the lowest execution time from the enumerated candidate execution plans as the final execution plan to be used.
[0004] However, as the complexity of the database increases, the number of candidate execution plans that the cost-based optimizer needs to enumerate increases significantly, thereby greatly increasing the time spent analyzing the execution plans and reducing the execution efficiency of the query statements. Summary of the Invention
[0005] This application provides a data query method, apparatus, device, medium, and program product. The technical solution provided by this application includes the following aspects.
[0006] According to one aspect of the embodiments of this application, a data query method is provided, the method comprising:
[0007] A first execution plan for a first query statement is generated using a plan generation model. The first execution plan includes a first query operation performed by the database based on the first query statement. The plan generation model is a pre-trained machine learning model used to generate execution plans.
[0008] If the first execution plan meets the preset execution requirements, obtain the plan prompt information corresponding to the first query operation. The plan prompt information is used to prompt the operation method of the first query operation.
[0009] During the operation of the database, based on the first query statement and the plan prompt information, a second execution plan for the first query statement is determined. The second execution plan includes at least one second query operation performed by the database according to the first query statement.
[0010] Execute the at least one second query operation in the database to obtain query results.
[0011] According to one aspect of the embodiments of this application, a data query apparatus is provided, the apparatus comprising:
[0012] The first processing module is configured to generate a first execution plan for a first query statement using a plan generation model. The first execution plan includes a first query operation performed by the database based on the first query statement. The plan generation model is a pre-trained machine learning model used to generate execution plans.
[0013] The first processing module is used to obtain plan prompt information corresponding to the first query operation when the first execution plan meets the preset execution requirements. The plan prompt information is used to prompt the operation method of the first query operation.
[0014] The second processing module is used to determine a second execution plan for the first query statement based on the first query statement and the plan prompt information during the operation of the database. The second execution plan includes the database performing at least one second query operation according to the first query statement.
[0015] The second processing module is used to execute the at least one second query operation in the database to obtain query results.
[0016] According to one aspect of the embodiments of this application, a computer device is provided, the computer device including a processor and a memory, the memory storing a computer program, the computer program being loaded and executed by the processor to implement the above-described data query method.
[0017] According to one aspect of the embodiments of this application, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and the computer program is loaded and executed by a processor to implement the above-described data query method.
[0018] According to one aspect of the embodiments of this application, a computer program product is provided, the computer program product including a computer program stored in a computer-readable storage medium, and a processor reading from the computer-readable storage medium and executing the computer program to realize the above-mentioned data query method.
[0019] The beneficial effects of the technical solutions provided in this application include at least the following:
[0020] A first execution plan for a first query statement is generated using a pre-trained plan generation model, and then the corresponding plan hint information is obtained. During database runtime, a second execution plan is quickly generated and executed by combining the first query statement and the existing plan hint information to obtain the query results. Compared to related technologies that use a cost-based optimizer to generate execution plans during database runtime, this application, on the one hand, uses an AI model (i.e., a plan generation model) to generate the first execution plan, and its corresponding plan hint information ensures that the second execution plan generated during database runtime can refer to the optimization strategy of the first execution plan, thereby guaranteeing the quality of the execution plan. On the other hand, this application generates the first execution plan using a plan generation model before database runtime and represents the first execution plan through plan hint information. During database runtime, the system can directly obtain the AI analysis results (i.e., the first execution plan) based on the plan hint information, avoiding the AI inference process during database runtime. This improves the generation efficiency of the execution plan while ensuring the quality of the execution plan generation, thereby improving data query efficiency. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a schematic diagram of a computer system provided in an exemplary embodiment of this application;
[0023] Figure 2 This is a flowchart of a data query method provided in an exemplary embodiment of this application;
[0024] Figure 3 This is a schematic diagram of a data query method provided in an exemplary embodiment of this application;
[0025] Figure 4 This is a flowchart of a data query method provided in another exemplary embodiment of this application;
[0026] Figure 5 This is a flowchart of a data query method provided in yet another exemplary embodiment of this application;
[0027] Figure 6 This is a flowchart of a data query method provided in another exemplary embodiment of this application;
[0028] Figure 7 This is a schematic diagram of a data query method provided in another exemplary embodiment of this application;
[0029] Figure 8 This is a structural block diagram of a data query apparatus provided in an exemplary embodiment of this application;
[0030] Figure 9 This is a structural block diagram of a computer device provided in an exemplary embodiment of this application. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0032] It should be noted that this application may display prompt interfaces, pop-ups, or output voice prompts before and during the collection of user data. These prompt interfaces, pop-ups, or voice prompts are used to inform the user that their data is being collected. This ensures that the application only begins the steps for collecting user data after receiving confirmation from the user regarding the prompt interface or pop-up; otherwise (i.e., without user confirmation), the steps for collecting user data end, meaning no user data is collected. In other words, all user data collected in this application is collected with the user's consent and authorization, and the collection, use, and processing of related user data must comply with relevant laws, regulations, and standards.
[0033] An execution plan is a detailed operational scheme generated by a database optimizer for a given query statement. The execution plan includes the specific steps taken to execute the given query statement in the database, such as table access methods, join order, and index usage. In related technologies, database optimizers include traditional optimizers and AI optimizers (i.e., optimizers based on AI learning). Traditional optimizers include rule-based optimizers and cost-based optimizers. Rule-based optimizers generate execution plans based on a series of predefined fixed rules. Cost-based optimizers select the optimal solution by estimating the cost of different execution plans. It mainly consists of cardinality estimation, cost modeling, and plan enumeration. Cost-based optimizers utilize database statistics to enumerate multiple candidate execution plans and then select the candidate execution plan with the lowest execution time as the final execution plan. AI optimizers primarily use artificial intelligence technology to analyze the given query statement and the current database statistics to obtain the optimal execution plan for the given query statement.
[0034] However, rule-based optimizers rely on predefined, fixed rules to generate execution plans, making them unable to adapt to dynamic changes in the database. This can lead to suboptimal or even incorrect execution plans. Cost-based optimizers, on the other hand, have extremely high requirements for the accuracy of statistical information. If the statistical information is outdated or incomplete, it can lead to incorrect cost estimations and the selection of suboptimal plans. Furthermore, as the complexity of the database increases, the number of candidate execution plans that cost-based optimizers need to enumerate increases significantly, greatly increasing the time spent analyzing execution plans and reducing the execution efficiency of query statements.
[0035] Based on this, this application provides a data query method. A first execution plan for a first query statement is generated using a pre-trained plan generation model (i.e., an AI optimizer), and then the corresponding plan hint information is obtained. During database runtime, a second execution plan is quickly generated and executed by combining the first query statement and the existing plan hint information to obtain the query results. Compared to traditional optimizers in related technologies, on the one hand, in this application, the first execution plan is generated by an AI model (i.e., a plan generation model), and its corresponding plan hint information ensures that the second execution plan generated during database runtime can refer to the optimization strategy of the first execution plan, thereby guaranteeing the quality of the execution plan. On the other hand, this application generates the first execution plan using the plan generation model before database runtime and represents the first execution plan through plan hint information. During database runtime, the system can directly obtain the AI analysis results (i.e., the first execution plan) based on the plan hint information, avoiding the AI inference process during database runtime. This improves the generation efficiency of the execution plan while ensuring its quality, thereby improving data query efficiency.
[0036] The computer system used to implement the data query method provided in this application is described below.
[0037] Figure 1 This is a schematic diagram of a computer system provided in an exemplary embodiment of this application. The computer system can implement a system architecture that serves as a data query method. The computer system includes a terminal 110 and a server 120. The terminal 110 is connected to the server 120 via a wireless network or a wired network.
[0038] Terminal 110 can be an electronic device such as a mobile phone, tablet computer, vehicle terminal (vehicle system), wearable device, PC (Personal Computer), virtual reality (VR) device, augmented reality (AR) device, etc. A client application for a first application can be installed and run on terminal 110. This first application is an application that provides data query functions, and this application is not limited in its form. Furthermore, this application is not limited in the form of the first application, including but not limited to Apps (Applications), mini-programs, etc., installed on terminal 110, and it can also be in the form of a webpage.
[0039] Server 120 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, a cloud server providing basic cloud computing services, or a node in a blockchain system. Server 120 can be the backend server of the aforementioned first application, used to provide backend services to the clients of the first application.
[0040] Optionally, server 120 runs a database management system (such as MySQL) for managing the database. Clients of the first application can connect to the database management system on server 120. The database management system can receive database query requests sent by clients of the first application and return query results. Alternatively, the database management system can also run on terminal 110; this application does not limit its use in this regard.
[0041] The data query method provided in this application embodiment can be executed by a computer device, which refers to an electronic device with data calculation, processing, and storage capabilities. For example... Figure 1 As shown, the data query method can be executed by terminal 110 (e.g., by a database management system installed and running on terminal 110), by server 120, or by interaction between terminal 110 and server 120. This application does not limit this.
[0042] The following explanation uses server 120 as an example to illustrate how to perform a data query.
[0043] The database management system 121 in server 120 obtains a first query statement for the database and generates a first execution plan for the first query statement using a plan generation model. The first execution plan includes the first query operation executed by the database based on the first query statement. The plan generation model is a pre-trained machine learning model used to generate execution plans. Then, if the first execution plan meets preset execution requirements, the server obtains the corresponding plan hint information, which indicates the operation method of the first query operation. Illustratively, before the database runs, server 120 pre-obtains the SQL statement (i.e., the first query statement) and analyzes it using an AI optimizer (i.e., the plan generation model) to obtain the first execution plan. If the first execution plan meets preset execution requirements (e.g., the execution time is less than the preset time), the server represents the first query operation using first hint information (i.e., plan hint information). Then, the first hint information is added to the OUTLINE table of the database management system.
[0044] During database operation, a second execution plan is determined based on the first query statement and plan hints. The second execution plan includes at least one second query operation executed by the database according to the first query statement. Optionally, the at least one second query operation includes the first query operation. Optionally, the first query statement and plan hints are input into the optimizer to obtain the second execution plan; then, the second execution plan is executed in the database (i.e., at least one second query operation is executed) to obtain the query result. Optionally, the optimizer is the traditional optimizer described above. Illustratively, during database operation, the OUTLINE table is first queried based on the SQL statement. Since the OUTLINE table stores the first hint information of the SQL statement, the first hint information is added to the SQL statement. Then, the SQL statement with the added first hint information is input into the traditional optimizer, which outputs the second execution plan. The first hint information serves as a constraint for the traditional optimizer, affecting the generation and selection process of the second execution plan. For example, if the first hint information specifies that the traditional optimizer should select an index scan for a given query operation, then the traditional optimizer needs to select an index scan for the given query operation during the generation of the second execution plan. After generating the second execution plan, the database will execute the second execution plan to obtain the query results. Optionally, after obtaining the query results, the server 120 can send the query results back to the terminal 110.
[0045] Those skilled in the art will understand that the number of terminals 110 described above can be more or less. For example, there may be only one terminal 110, or there may be dozens or hundreds of terminals 110, or even more. This application does not limit the number or type of terminals 110.
[0046] Next, the flow of the data query method provided in the embodiments of this application will be described.
[0047] Figure 2 This is a flowchart illustrating a data query method provided in an embodiment of this application. The method is executed by a computer device, which may be... Figure 1 The terminal 110 and / or server 120 are shown. The method includes steps 210 to 240.
[0048] Step 210: Generate the first execution plan for the first query statement using the plan generation model.
[0049] The first query statement refers to a query statement targeting the database. Optionally, the database includes at least one of relational databases, non-relational databases, and distributed databases. A query statement is an instruction used to retrieve, manipulate, or manage data from a database; the syntax and functionality of query statements differ depending on the database type.
[0050] Optionally, the first query statement can be implemented as an SQL (Structured Query Language) statement. SQL is a standard programming language used to manage and manipulate relational databases. For example, SQL statements can be used to manage and manipulate relational databases through relational database management systems (such as MySQL, Oracle, SQL Server, etc.).
[0051] An execution plan is a detailed sequence of operation steps generated to execute a query statement. Optionally, a single execution plan includes at least one query operation. The execution plan determines how the database retrieves data and returns the retrieval results. Optionally, the execution plan consists of a series of operators in a specific order. The operators include, but are not limited to: (1) Table scan: a full table scan or index scan used to obtain raw data. (2) Index lookup: determining data rows through an index. (3) Filtering: filtering data using WHERE conditions. (4) Join: merging data from multiple tables; joins include nested loop joins, hash joins, merge joins, etc. (5) Grouping and aggregation: applying aggregate functions after grouping data. (6) Sorting: sorting data by a specified column. (7) Deduplication: removing duplicate rows. It should be noted that the above examples of operators are only illustrative and are not limited in this application embodiment. Optionally, in the execution plan, a single query operation is defined by at least one operator.
[0052] The first execution plan includes at least one first query operation executed by the database according to the first query statement, and the first query operation is defined by at least one operator. Optionally, the first execution plan contains at least two first query operations, and the plan hint information is used to indicate some of the first query operations in the first execution plan, or the plan hint information is used to indicate all the first query operations in the first execution plan.
[0053] Among them, the plan generation model is a pre-trained machine learning model used to generate execution plans.
[0054] Optionally, the model type of the plan generation model includes at least one of the following: a contrastive model, a reinforcement learning model, and a diffusion model. Illustratively, a contrastive model distinguishes between effective and ineffective execution plans (such as execution plans that meet abnormal execution conditions as described below) through contrastive learning, thereby generating an execution plan that meets the execution objective (such as an execution time shorter than a preset time). A reinforcement learning model can train an agent through a reward mechanism to generate execution plans that meet the execution objective (such as an execution time shorter than a preset time). A diffusion model generates execution plans that meet the execution objective (such as an execution time shorter than a preset time) through a progressive denoising process. It should be noted that the above examples of plan generation models are merely illustrative and are not intended to limit the scope of this application.
[0055] In some embodiments, the plan generation model can be implemented as an end-to-end model. Optionally, at least two candidate execution plans corresponding to the first query statement are obtained; plan features corresponding to the at least two candidate execution plans are extracted through the plan generation model; the plan features are analyzed through the plan generation model to obtain the quality scores of the candidate execution plans; and the candidate execution plan whose quality score meets the preset quality standard among the at least two candidate execution plans is used as the execution plan of the query statement.
[0056] At least two candidate execution plans can be determined by a plan generation model through analysis of the query statement; or, at least two candidate execution plans can be obtained by a traditional optimizer (e.g., a rule-based optimizer, a cost-based optimizer, etc.) after analyzing the first query statement. Optionally, the traditional optimizer can be guided to generate multiple different candidate execution plans through at least one of the following methods: inserting hint information into the first query statement to change the execution plan generated by the traditional optimizer; or adjusting the internal parameters of the traditional optimizer (e.g., optimizer weights, etc.) to indirectly affect the traditional optimizer's output of different execution plans.
[0057] The plan features can be implemented as a feature vector tree. For example, a feature vector is generated for each query operation in the candidate execution plan, and the feature vectors corresponding to multiple query operations in the candidate execution plan are combined to obtain a feature vector tree.
[0058] The quality score characterizes the quality of the candidate execution plan. Optionally, the execution time of the candidate execution plan is negatively correlated with the quality score; that is, the shorter the execution time, the higher the quality score. Optionally, after obtaining the quality scores of at least two candidate execution plans, the candidate execution plan with the highest quality score is selected as the execution plan for the query statement.
[0059] In other embodiments, the plan generation model primarily uses artificial intelligence techniques to optimize the cardinality estimation, cost calculation, and plan enumeration of traditional optimizers, thereby accurately generating the optimal execution plan. Optionally, the plan generation model includes at least one of a cardinality prediction sub-model, a cost calculation sub-model, and a plan enumeration sub-model.
[0060] Optionally, the cardinality prediction sub-model is a pre-trained machine learning model used for cardinality estimation. The query features of the first query statement are extracted; the query features and database metadata are input into the cardinality prediction sub-model, and the cardinality estimate is output. Query features include, but are not limited to, the syntax tree, predicate conditions, table join relationships, aggregate functions, and other features of the query statement. Database metadata includes table structure (such as column types, index information), statistical information (such as histograms, cardinality, data distribution), and other data. The cardinality estimate represents the number of rows of intermediate results expected to be generated when the first query statement is executed in the database. For example, the cardinality estimate represents the number of rows of intermediate results expected to be generated when a certain query operation (such as a join) corresponding to the first query statement is executed.
[0061] Optionally, the cost calculation sub-model is a pre-trained machine learning model used to generate candidate execution plans. The query features of the first query statement are extracted; the query features and optimization objective are input into the plan enumeration sub-model, outputting a set of candidate execution plans. The optimization objective represents a user-specified or system-default objective (such as minimizing the execution time of the execution plan). The set of candidate execution plans includes at least two candidate execution plans.
[0062] Optionally, the cardinality estimate and the set of candidate execution plans are input into the cost calculation sub-model, and the cost estimate of each candidate execution plan in the set of candidate execution plans is output, wherein the cost estimate can be implemented as the expected execution time of the candidate execution plan.
[0063] Optionally, after obtaining the cost estimate of each candidate execution plan in the candidate execution plan set, the candidate execution plan with the lowest cost estimate is selected as the first execution plan of the first query statement.
[0064] In some embodiments, at least one query statement is obtained during the database preprocessing stage, and the at least one query statement includes a first query statement. Optionally, the at least one query statement is a pre-obtained query statement to be processed.
[0065] Step 220: If the first execution plan meets the preset execution requirements, obtain the plan prompt information corresponding to the first query operation.
[0066] Among them, the preset execution requirements are pre-set constraints, which are illustrative. The preset execution requirements are used to filter the execution plans generated by the plan generation model.
[0067] In some embodiments, if the first simulated execution data of the first execution plan meets preset execution requirements, plan prompt information corresponding to the first query operation is obtained. The first simulated execution data represents the execution data of simulating the execution of the first execution plan in the database, and includes execution duration, resources consumed during execution (such as memory resources, processor resources, etc.). Illustratively, if the execution duration in the first simulated execution data is less than a preset duration, and / or the resources consumed during execution in the first simulated execution data are less than a preset resource amount, it is determined that the first simulated execution data meets the preset execution requirements.
[0068] In other embodiments, if the second simulated execution data of the first execution plan meets preset execution requirements, plan prompt information corresponding to the first query operation is obtained. The second simulated execution data represents the execution data of the first query operation when the first execution plan is simulated in the database. The second simulated execution data includes execution duration, computational resources consumed, etc. Illustratively, if the execution duration in the second simulated execution data is less than a preset duration, and / or the resources consumed in the second simulated execution data are less than a preset resource amount, it is determined that the second simulated execution data meets the preset execution requirements.
[0069] The following explanation uses the first and second simulated execution data as examples to illustrate the execution duration. The first execution plan meets the preset execution requirements under at least one of the following conditions:
[0070] (1) The first simulation duration corresponding to the first execution plan is less than the preset first execution duration.
[0071] The first simulation duration represents the execution time required to simulate the execution of the first execution plan in the database.
[0072] Optionally, if the first simulation duration of the first execution plan is less than the preset first execution duration, the plan prompt information corresponding to the first execution plan is obtained.
[0073] In a schematic manner, a first execution duration is preset for the first query statement, and the database is simulated based on the model's operating conditions. The first execution plan is executed in the simulated database, and the simulated execution duration corresponding to the first execution plan is obtained. The simulated execution duration is the total execution duration of the first execution plan. If the simulated execution duration corresponding to the first execution plan is less than the preset first execution duration, the first execution plan is determined to meet the preset execution requirements.
[0074] In the above scheme, setting a first execution duration to select execution plans with higher execution efficiency as subsequent inheritance execution plans improves the quality of execution plans generated by the database at runtime.
[0075] In some embodiments, at least two simulated running conditions are obtained; the database is simulated and run according to the at least two simulated running conditions, and the first candidate duration corresponding to the at least two simulated running conditions is obtained; the first candidate duration represents the execution duration required to execute the first execution plan in the database based on the simulated running conditions; the first simulation duration is determined based on the at least two first candidate durations.
[0076] The simulated operating conditions of the database include at least one of the following: data scale (the amount of data in the tables in the database, including the number of rows, columns, and data storage size), hardware resource configuration (the hardware environment required for database operation, including the number of CPUs, memory capacity, disk I / O speed, network bandwidth, etc.), load conditions (the concurrent query pressure, lock contention, buffer status, and other load characteristics of the database), and statistical information version (such as using statistical information from historical time points in the database).
[0077] Optionally, the average or weighted average duration of at least two first candidate durations can be obtained as the first simulation duration. For the weighted average duration, the weight of different first candidate durations is determined by the simulation running conditions corresponding to the first candidate duration. For example, the database administrator can configure different weights for different simulation running conditions.
[0078] In the above scheme, at least two simulated running conditions are considered to simulate the operation of the database and obtain the corresponding first candidate duration, and then the first simulation duration is determined. This fully simulates the actual running state of the database, improves the simulation accuracy of the first simulation duration, and uses the first simulation duration to filter the execution plan, making the filtered execution plan more accurate.
[0079] (2) The simulated execution time corresponding to the first query operation is less than the preset second execution time.
[0080] The second simulation duration represents the execution time required for the first query operation when simulating the execution of the first execution plan in the database.
[0081] Optionally, if the second simulation duration of the first query operation is less than the preset second execution duration, the plan prompt information corresponding to the first execution plan is obtained.
[0082] In a schematic manner, a second execution duration corresponding to the first query operation is pre-set, and the database is simulated based on the model's operating conditions. The first execution plan is executed in the simulated database, and the simulated execution duration corresponding to each query operation in the first execution plan is obtained. If the simulated execution duration corresponding to the first query operation is less than the second execution duration, the first execution plan is determined to meet the preset execution requirements.
[0083] Optionally, if some of the first query operations in the first execution plan are less than the corresponding second execution duration, the first execution plan is determined to meet the preset execution requirements. Alternatively, if every query operation in the first execution plan is less than the corresponding second execution duration, the first execution plan is determined to meet the preset execution requirements.
[0084] In the above scheme, a second execution duration is set to evaluate the simulated execution duration of the query operation in the first execution plan, and the execution plan is filtered in a more granular way, which realizes the accurate filtering of the execution plan and further improves the quality of the execution plan generated by the database runtime.
[0085] In some embodiments, at least two simulated running conditions are obtained; the database is simulated and run according to the at least two simulated running conditions, and second candidate durations corresponding to the at least two simulated running conditions are obtained respectively; the second candidate duration represents the execution time required for the first query operation when the first execution plan is executed in the database based on the simulated running conditions; and the second simulation duration is determined based on the at least two second candidate durations.
[0086] Optionally, the average or weighted average duration of at least two second candidate durations can be obtained as the first simulation duration. For the weighted average duration, the weight of different second candidate durations is determined by the simulation running conditions corresponding to the second candidate duration. For example, the database administrator can configure different weights for different simulation running conditions.
[0087] If the first execution plan meets the preset execution requirements, the first query operation is analyzed to obtain plan hint information. This plan hint information indicates the operation mode of the first query operation. Optionally, it indicates at least one of the following: the lookup method (e.g., full table scan or index scan), the scan method (if index lookup), the table join order, and the table join method (e.g., nested loop join, hash join, merge join). For example, if the first query operation uses a hash join to connect tables A and B, then the plan hint information indicates the specific operation mode of the first query operation, namely: using a hash join to connect tables A and B. Optionally, the plan hint information can be implemented as HINT information. In the database field, HINT information is execution hint information provided by the database to force the optimizer to select a specific query operation, such as specifying an index lookup, specifying an index scan, specifying the table join order, and specifying the table join method.
[0088] It should be noted that the above-mentioned plan prompts, in addition to indicating the operation method of the first query operation, can also indicate the resource strategy during the generation of the second execution plan. Optionally, the resource strategy is used to restrict the resource usage corresponding to the query operation. For example, when generating the second execution plan, the first query operation can only be selected as at least one of the final generated second query operations if the current memory usage of the database is greater than a preset usage rate; if the current memory usage of the database is less than or equal to the preset usage rate, the first query operation cannot be selected as at least one of the final generated second query operations. Optionally, if the current memory usage of the database is less than or equal to the preset usage rate, the optimizer can reselect the query operation to be added to the final generated second execution plan based on the current running state of the database.
[0089] In some embodiments, at least two execution plans for a first query statement are generated by a plan generation model, and the first execution plan is included among the at least two execution plans. If the first execution plan among the at least two execution plans meets preset execution requirements, plan prompt information corresponding to the first query operation is obtained. Illustratively, taking an end-to-end model implementation of the plan generation model as an example, after obtaining the quality scores corresponding to at least two candidate execution plans for the first query statement, the plan generation model selects the at least two candidate execution plans with the highest quality scores as the at least two execution plans for the first query statement.
[0090] In some embodiments, if the first execution plan meets the preset execution requirements, the first execution plan is parsed to obtain the first operation data corresponding to the first query operation; the prompt information template corresponding to the operation mode of the first query operation is obtained; and a plan prompt information is generated based on the first operation data and the prompt information template.
[0091] The first operation data includes the specific operation parameters of the first query operation, including but not limited to: table name, operation type, and execution parameters. The operation type may include, for example, a full table scan or index scan, nested loop join or hash join; the execution parameters may include, for example, table join order and filtering conditions. Optionally, a prompt message template is populated based on the first operation data to generate a planned prompt message.
[0092] Optionally, the hint template can be implemented as a database-supported HINT template. That is, the first execution plan is parsed to obtain the first operation data corresponding to the first query operation; if the HINT template corresponding to the first query operation is a database-supported HINT template, the HINT template is filled according to the first operation data to obtain the first HINT information.
[0093] The database supports at least one of the following HINT templates: performing a full table scan, specifying an index scan, specifying the table join order, specifying the table join method, and specifying an index lookup.
[0094] In the above solution, the operation data of the query operation is obtained by parsing the execution plan. Then, the operation data is combined with the prompt information template to generate the plan prompt information. The plan prompt information is automatically generated by the prompt information template, which avoids the tedious process of manually designing the plan prompt information based on the execution plan and improves the efficiency of plan prompt information generation.
[0095] Step 230: During the operation of the database, based on the first query statement and the plan hint information, determine the second execution plan for the first query statement.
[0096] The second execution plan includes at least one second query operation executed by the database based on the first query statement. Optionally, the second query operation is defined by at least one operator.
[0097] Among them, the plan prompt information serves as a constraint in the second execution plan generation process.
[0098] Optionally, at least one second query operation includes the first query operation in the first execution plan. Illustratively, during the generation of the second execution plan, based on prompts in the plan hint information, the system selects the first query operation to add to the second execution plan.
[0099] In some embodiments, the first execution plan and the second execution plan are identical. Illustratively, assuming the first execution plan contains only query operation a and query operation b, and the execution order of operations in the first execution plan is query operation a first, then query operation b, then the first execution plan and the second execution plan being identical means that the second execution plan also contains query operation a and query operation b, and the execution order of operations is query operation a first, then query operation b.
[0100] In other embodiments, the first execution plan and the second execution plan are different. Optionally, the second execution plan includes at least two second query operations, and the at least two second query operations include the first query operation. For example, the first execution plan includes query operation a and query operation b, and the second execution plan includes query operation a, query operation b, and query operation c. That is, the first query operation indicated by the plan hint information only affects some optimization strategies (such as table join order, index selection, etc.). In this case, the first query operation indicated by the plan hint information refers to a portion of the query operations in the first execution plan, so the generated second execution plan is different from the first execution plan, but the second execution plan may include the first query operation; or, the first query operation indicated by the plan hint information refers to all the query operations in the first execution plan, but since the system (or the traditional optimizer described below) generates additional query operations based on the real-time running status of the database (such as temporary table strategies, etc.), the generated second execution plan is not exactly the same as the first execution plan.
[0101] In some embodiments, plan hints are inserted into the first query statement to obtain a second query statement; the optimizer analyzes the second query statement to obtain a second execution plan. Illustratively, if the plan hints are implemented as the first HINT information of the first execution plan, and the first query statement is implemented as a first SQL statement, the first HINT information is inserted into the first SQL statement in a specified syntax format to obtain the second SQL statement. Illustratively, / *+...* / represents the execution syntax format (comment format), and the "..." is filled with HINT statements, i.e., HINT information.
[0102] Optionally, the optimizer is implemented as a conventional optimizer, wherein the optimizer includes at least one of a rule-based optimizer and a cost-based optimizer.
[0103] In the above scheme, the plan hint information is inserted into the first query statement to obtain the second query statement. Then, the traditional optimizer based on rules and / or cost is used to analyze and obtain the second execution plan. The plan hint information is used as a constraint condition for the traditional optimizer to generate the execution plan. During the analysis process, the traditional optimizer will refer to the efficient execution plan obtained by the AI optimizer (i.e., the plan generation model) based on the plan hint information. This improves the efficiency of execution plan generation while ensuring the quality of the final effective execution plan.
[0104] Optionally, the insertion position of the plan hint information in the first query statement is determined; the plan hint information is inserted at the insertion position of the first query statement to obtain the second query statement. Illustratively, if the plan hint information is implemented as the first HINT information of the first execution plan, and the first query statement is implemented as the first SQL statement, the insertion position of the first HINT information is determined, and the first HINT information is inserted at the insertion position of the first SQL statement in a specified syntax format to obtain the second SQL statement. For example, if the insertion position is after the SELECT keyword, that is, the first HINT information is added after the SELECT keyword in the first SQL statement in the form of / *+...* / (comment form) to obtain the second query statement. In some embodiments, the scope of the first HINT information in the first SQL statement is determined, and the first HINT information is inserted after the SELECT keyword within the scope of the first SQL statement in the form of a comment. For example, if the first HINT information specifies the scan method of a single table, then the first HINT information is inserted after the SELECT of the query block corresponding to the specified single table.
[0105] In the above scheme, the insertion position of the plan prompt information in the first query statement is determined, and then the insertion is performed to obtain the second query statement. This ensures the accuracy of the second query statement generation process and avoids generating an incorrect second query statement due to an incorrect insertion position.
[0106] In some embodiments, a first query request is received during database operation; the first query request is parsed to obtain a first query statement; and a second execution plan for the first query statement is determined based on the first query statement and plan hint information. Optionally, the client of the first application sends the first query request to the database management system, which parses the first query request to obtain the first query statement and determines a second execution plan for the first query statement based on the first query statement and plan hint information.
[0107] In some embodiments, the plan hint information of the first execution plan is stored in a plan hint table. During database operation, the first query statement and the plan hint table need to be matched to obtain the plan hint information. Optionally, during database operation, the first query statement and the plan hint table are matched; if the first query statement and the plan hint information of the first execution plan stored in the plan hint table match, the plan hint information of the first execution plan is obtained from the plan hint table, and a second execution plan for the first query statement is determined based on the first query statement and the plan hint information.
[0108] Optionally, the unique identifier information of the first query statement and the plan hint information in the plan hint table are stored correspondingly (associated storage). Illustratively, during database operation, matching the first query statement and the plan hint table means: obtaining the unique identifier information of the first query statement, and traversing the plan hint table based on the unique identifier information. If the plan hint table contains the unique identifier information of the first query statement, then the first query statement is matched with the plan hint information of the first execution plan stored in the plan hint table, and the plan hint information corresponding to the unique identifier information in the plan hint table is obtained. Optionally, the unique identifier information can be implemented as the unique identifier number of the first query statement, a hash value, etc.
[0109] The execution plan hint information can be implemented as the first hint information, and the execution plan hint table can be implemented as an OUTLINE table. The OUTLINE table is a data structure in the database used to store execution plan hint (HINT) information. For illustration, the unique identifier information of the query statement and the first hint information are stored correspondingly in the first OUTLINE of the OUTLINE table.
[0110] Optionally, after obtaining the second query statement, the second query statement is converted into a syntax tree, and the syntax tree is input into the optimizer to output a second execution plan. The second execution plan represents the query process executed by the database based on the first query statement.
[0111] The syntax tree includes abstract syntax trees (ASTs), etc. Taking the implementation of the first hint information as an example, to decompose the second query statement into tokens, an abstract syntax tree (AST) is constructed based on the tokens. The tokens corresponding to the first hint information are identified from the AST. Based on the tokens corresponding to the first hint information, the corresponding first query operation is determined and extracted. The first query operation can be regarded as a constraint condition for generating the second execution plan; that is, at least one second query operation in the generated second execution plan must contain the first query operation.
[0112] Taking the optimizer implementation as a rule-based optimizer as an example, the rule-based optimizer includes a rule engine, which includes predefined fixed rules. The syntax tree is input into the rule-based optimizer, and the first hint information is extracted from the syntax tree. The first hint information is added to the rule engine as a hint rule. The first hint information has a higher priority than the fixed rules in the rule engine. When the rule engine is used to generate an execution plan (i.e., the second execution plan) for the syntax tree, the rule engine matches the syntax tree with all available rules (including hint rules and predefined rules) to obtain all rules (including hint rules) that match the syntax tree (i.e., the second query statement). The second execution plan is obtained by combining all rules that match the syntax tree.
[0113] Taking the optimizer implementation as a cost-based optimizer as an example, the syntax tree and the current statistics of the database are input into the cost-based optimizer. The first hint information is extracted from the syntax tree and used as a constraint. The cost-based optimizer analyzes the syntax tree and statistics to generate multiple candidate execution plans. The candidate execution plans must include the first query operation indicated by the first hint information. The cost of the candidate execution plans is estimated (such as calculating I / O utilization, CPU utilization, memory utilization, etc.), and the candidate execution plan with the lowest cost is selected as the second execution plan.
[0114] In some embodiments, during the operation of the database and while the plan prompt information is in effect, if the execution prompt information meets preset requirements, the first execution plan is updated based on the current operating state of the database through the plan generation model; the updated plan prompt information is determined based on the updated first execution plan; and during the operation of the database, the second execution plan for the first query statement is determined based on the first query statement and the updated plan prompt information.
[0115] The "plan prompt information taking effect" means that the plan prompt information is valid, and a corresponding second execution plan can be generated based on the plan prompt information taking effect and the first query statement.
[0116] Among them, updating the first execution plan based on the current running state of the database through the plan generation model means running the database with the current running state of the database as the model running condition, analyzing the first query statement through the plan generation model, and generating the updated first execution plan.
[0117] In the above scheme, before the first query statement is executed, the first execution plan will be updated based on preset requirements, and the plan prompt information will be updated to ensure the synchronization between the plan prompt information and the current running status of the database, thereby improving the quality of the final generated second execution plan.
[0118] Optionally, the execution prompt message meeting the preset requirements includes at least one of the following:
[0119] (1) If the generation time of the execution prompt message is longer than the preset time, the first execution plan is updated based on the current running status of the database through the plan generation model.
[0120] The generation duration refers to the time from the generation time of the preset prompt information to the current time. Indicatively, during database operation, the first execution plan can be updated once every preset time interval before the first query statement is executed. The updated plan prompt information is determined based on the updated first execution plan. Then, based on the first query statement and the updated plan prompt information, the second execution plan for the first query statement is determined. The specific determination process can be referred to the above process of determining the second execution plan based on the first query statement and plan prompt information, and will not be elaborated here.
[0121] In the above scheme, the first execution plan is updated based on a preset duration requirement, ensuring that the plan prompt information can be generated based on the latest data block running status, and avoiding the generation of an incorrect second execution plan due to the old plan (i.e., the unupdated plan prompt information).
[0122] (2) If the current running status of the plan generation model meets the requirements for status change, update the first execution plan based on the current running status of the database through the plan generation model.
[0123] Optionally, if the resource utilization in the current operating state meets the state change requirements, the first execution plan is updated based on the current operating state of the database through the plan generation model. If the database resource utilization is greater than a preset utilization rate for M consecutive collection cycles, it is determined that the resource utilization meets the state change requirements. Here, M is a pre-defined positive integer. Resource utilization includes at least one of I / O utilization, CPU utilization, and memory utilization.
[0124] In the above scheme, the first execution plan is updated based on the state change requirement, ensuring that the plan prompt information can be generated based on the latest data block running status, thereby adapting to changes in the database running status and updating to generate a better execution plan. For example, when CPU, memory or I / O utilization continues to exceed the standard, updating the plan prompt information can guide the optimizer to choose a more efficient execution path and reduce resource consumption.
[0125] Step 240: Execute at least one second query operation in the database to obtain the query results.
[0126] The query result is the result of the first query statement in the database.
[0127] Indicatively, queries are executed in the database according to at least one second query operation in the second execution plan and the order of query operation execution, and the query results are obtained.
[0128] This is illustrative; please refer to it. Figure 3 This illustrates a data query method. For example... Figure 3As shown, multiple SQL statements are input into the plan generation model 302, which outputs execution plans corresponding to each SQL statement, including the first SQL statement 301. Hint information 303 corresponding to each execution plan is determined and added to the OUTLINE table 304. During database 308 execution, the first SQL statement 301 is matched against the OUTLINE table 304. If the first hint information corresponding to the first SQL statement 301 exists in the OUTLINE table 304, it is inserted into the first SQL statement 301, resulting in the second SQL statement 305. The second SQL statement 305 is input into the optimizer 306, which determines the execution plan 307 under the constraints of the first hint information. Database 308 is then called to execute the execution plan 307, yielding the query result 309.
[0129] In summary, the data query method provided in this application generates a first execution plan for a first query statement using a pre-trained plan generation model, and then obtains the corresponding plan hint information. During database runtime, the second execution plan is quickly generated and executed by combining the first query statement and the existing plan hint information to obtain the query results. Compared with related technologies that use a cost-based optimizer to generate execution plans during database runtime, this application, on the one hand, uses an AI model (i.e., a plan generation model) to generate the first execution plan, and its corresponding plan hint information ensures that the second execution plan generated during database runtime can inherit the optimization strategy of the first execution plan, thereby guaranteeing the quality of the execution plan. On the other hand, this application generates the first execution plan using a plan generation model before database runtime and represents the first execution plan through plan hint information. During database runtime, the system can directly obtain the AI analysis results (i.e., the first execution plan) based on the plan hint information, avoiding the AI inference process during database runtime. This improves the generation efficiency of the execution plan while ensuring its quality, thereby improving data query efficiency.
[0130] In some embodiments, for an execution plan that fails to execute, if a corresponding plan hint message exists for that execution plan, the plan hint message can be made invalid. For illustrative purposes, please refer to [reference needed]. Figure 4 The diagram illustrates a flowchart of a data query method, which includes steps 250 and 260. Optionally, steps 250 and 260 are executed after step 240.
[0131] Step 250: If the second execution plan meets the abnormal execution conditions, the control plan prompt message becomes invalid.
[0132] The second execution plan may meet the abnormal execution conditions in at least one of the following situations: the execution time of the second execution plan is longer than the preset time; the resources consumed during the execution of the second execution plan are greater than the preset resource amount; the query results of the second execution plan are incorrect, etc.
[0133] In some embodiments, the execution duration of the second execution plan in the database is obtained; if the execution duration exceeds a preset duration, the control plan prompt information becomes invalid. Optionally, once the plan prompt information becomes invalid, it cannot be used anymore, that is, the corresponding execution plan cannot be generated based on the plan prompt information and the first query statement.
[0134] In the above scheme, the execution time is used as the criterion for judging abnormal execution conditions. This ensures that the prompts for plans with low actual execution efficiency can be removed in a timely manner, avoiding the problem of low query efficiency caused by the subsequent use of inefficient execution plans, thereby improving the overall efficiency of the query system.
[0135] Step 260: Use the execution record data corresponding to the second execution plan as training sample data to update the model parameters of the plan generation model.
[0136] The execution record data includes at least one of the following: the query statement corresponding to the second execution plan (such as the first query statement and the second query statement), execution prompt information, execution duration, resources consumed during execution, query results obtained after execution, database information (such as database name, database running status during the execution of the second execution plan, etc.), each query step of the second execution plan, and the execution duration of each query step in the second execution plan. No limitation is imposed here.
[0137] In some embodiments, the plan generation model is a comparison model. Optionally, if the second execution plan meets the abnormal execution conditions, the execution record data corresponding to the second execution plan is obtained; the execution record data corresponding to the second execution plan is used as negative sample data to update the model parameters of the plan generation model.
[0138] This example illustrates how to determine the anomaly types corresponding to execution record data. For instance, if the anomaly condition is that the execution duration of the second execution plan exceeds a preset duration, the anomaly type is "Execution Duration Anomaly"; if the anomaly condition is that the resources consumed during the execution of the second execution plan exceed a preset resource amount, the anomaly type is "Resource Consumption Anomaly"; if the anomaly condition is that the query result corresponding to the second execution plan is incorrect, the anomaly type is "Query Result Anomaly," and so on. Based on the anomaly type corresponding to the execution record data, obtain at least two corresponding normal types of execution record data. For example, if the anomaly type is "Execution Duration Anomaly," then the normal type of execution record data is the execution record data of execution plans whose execution duration is less than or equal to the preset duration; if the anomaly type is "Resource Consumption Anomaly," then the normal type of execution record data is the execution record data of execution plans whose execution duration is less than or equal to the preset resource amount; if the anomaly type is "Query Result," then the normal type of execution record data is the execution record data of execution plans whose query result is correct. Encoding the execution record data of the anomaly type yields negative sample feature representations, and encoding the execution record data of at least two normal types yields at least two positive sample feature representations. The contrastive loss function is calculated based on the similarity between at least two positive sample feature representations (positive sample pairs) and the similarity between a negative sample feature representation and any positive sample feature representation (negative sample pair). The optimization objective of the contrastive loss function is to maximize the similarity of positive sample pairs and minimize the similarity of negative sample pairs. The update gradient is calculated using the loss value of the contrastive loss function, and the model parameters of the planned generation model are adjusted based on the update gradient.
[0139] The updated plan generation model can be used in subsequent data query processes.
[0140] In the above scheme, the execution record data corresponding to the second execution plan meeting the abnormal execution conditions is used as negative sample data to update the model parameters of the plan generation model. This realizes the introduction of data under actual abnormal execution conditions as negative feedback. The plan generation model can optimize the model parameters according to the actual negative feedback, thereby generating a more accurate execution plan. This also generates more accurate plan prompt information, further improving the quality of the execution plan generated by the subsequent database runtime.
[0141] In some embodiments, an abnormal execution database is constructed to store execution record data of execution plans that meet abnormal execution conditions, such as the execution record data corresponding to the second execution plan. Optionally, if the second execution plan meets the abnormal execution conditions, the execution record data corresponding to the second execution plan is stored in the abnormal execution database. Target execution record data is obtained from the abnormal execution database, where the similarity between the target execution record data and the execution record data corresponding to the second execution plan is greater than a preset similarity. The update gradient is determined based on the similarity between the target execution record data and the execution record data corresponding to the second execution plan when using the execution record data as training sample data.
[0142] To illustrate, when new abnormal execution record data is generated, the system searches the abnormal execution database for historical abnormal data (i.e., target execution record data) with a similarity greater than a preset threshold. Higher similarity indicates a higher frequency of anomalies in that type of execution plan, meaning the abnormal execution record data has a greater impact on the model parameters, thus increasing the gradient update (i.e., increasing gradient weights). Lower similarity indicates a lower frequency of anomalies in that type of execution plan, thus decreasing the gradient update (i.e., reducing gradient weights). This filters out execution plan anomalies caused by accidental reasons (such as network anomalies, device hardware anomalies, etc.), avoiding over-adjustment of the model.
[0143] In summary, the data query method provided in this application controls the corresponding plan prompt information to become invalid when the second execution plan meets the abnormal execution conditions, thereby avoiding the problem of low query efficiency or query failure caused by the subsequent use of abnormal execution plans and improving the reliability of the database management system.
[0144] In some embodiments, for query statements that meet the short query requirements, an execution plan can be directly generated and executed according to preset short query rules. For illustrative examples, please refer to [reference needed]. Figure 5 The diagram illustrates a flowchart of a data query method, which includes steps 270 and 280.
[0145] Step 270: If the first query statement meets the short query requirement, generate a third execution plan for the first query statement according to the preset short query rules.
[0146] The third execution plan includes at least one third query operation.
[0147] Optionally, if the query type corresponding to the first query statement is a short query, then the first query statement is determined to meet the short query requirement. A short query refers to a query type with short execution time (typically in the millisecond range), simple logic, and low data access volume. Optionally, the query type of a short query includes at least one of the following:
[0148] (1) Simple single-table query: A simple SELECT operation involving only a single table.
[0149] (2) Queries based on primary key or unique index: Equality queries are performed using primary key or unique index fields to directly locate the target record.
[0150] (3) Constant table lookup: The lookup conditions can uniquely identify a single record.
[0151] (4) Simple aggregation query: Perform simple aggregation statistics on small datasets (such as COUNT, SUM).
[0152] (5) Covering index query: All fields required for the query are contained in the index, and there is no need to go back to the table.
[0153] It should be noted that the examples of short queries above are merely illustrative and this application does not limit them.
[0154] Optionally, different short queries for different query types correspond to different preset short query rules; generating a third execution plan for the first query statement based on the preset short query rules includes: determining a preset first short query rule based on the query type corresponding to the first query statement; and generating a third execution plan for the first query statement based on the first short query rule.
[0155] To illustrate, the syntax tree of the first query statement is obtained; the query type corresponding to the first query statement is determined based on the syntax tree; if the query type is a short query, the first short query rule corresponding to the query type of the first query statement is obtained. A third execution plan for the first query statement is generated based on the first short query rule.
[0156] Step 280: Execute at least one third query operation in the database to obtain the query results.
[0157] That is, the third execution plan is executed in the database to obtain the query results.
[0158] This is illustrative of the process of executing a query in the database according to at least one third query operation in the third execution plan and the order of query operations, and obtaining the query results.
[0159] In summary, the data query method provided in this application directly generates and executes a third execution plan based on preset short query rules for a first query statement that meets the short query requirements. This avoids complex and redundant processing of short queries, simplifies the short query processing flow, and improves the overall query efficiency of the query system to a certain extent.
[0160] This is illustrative; please refer to it. Figure 6 The diagram illustrates a flowchart of a data query method, which includes steps 601 to 613.
[0161] Step 601: Input at least one query statement into the plan generation model and output the execution plan of at least one query statement.
[0162] At least one of the query statements can be implemented as an SQL statement.
[0163] Optionally, during the database preprocessing stage, at least one query statement to be executed is obtained; then, the at least one query statement is input into the plan generation model, and the execution plan of the at least one query statement is output.
[0164] Optionally, at least one query statement is a predefined query statement to be executed subsequently.
[0165] Among them, the plan generation model is a pre-trained machine learning model used to generate execution plans. Illustratively, in the database field, the plan generation model can be called an AI optimizer.
[0166] In some embodiments, the plan generation model can be implemented as an end-to-end model. Optionally, at least two candidate execution plans corresponding to the query statement are obtained; plan features corresponding to the at least two candidate execution plans are extracted through the plan generation model; the plan features are analyzed through the plan generation model to obtain the quality scores of the candidate execution plans; and the candidate execution plan with the highest quality score among the at least two candidate execution plans is used as the execution plan for the query statement.
[0167] In other embodiments, the plan generation model primarily uses artificial intelligence technology to optimize the cardinality estimation, cost calculation, and plan enumeration of traditional optimizers, thereby accurately generating the optimal execution plan. Optionally, the plan generation model includes at least one of a cardinality prediction sub-model, a cost calculation sub-model, and a plan enumeration sub-model. Optionally, query features of the query statement are extracted; the query features and database metadata are input into the cardinality prediction sub-model, and a cardinality estimate is output. Optionally, the query features and optimization objectives are input into the plan enumeration sub-model, and a set of candidate execution plans is output, where the optimization objective represents a user-specified or default objective (such as minimizing execution time). Optionally, the cardinality estimate and the set of candidate execution plans are input into the cost calculation sub-model, and a cost estimate for each candidate execution plan in the candidate execution plan set is output, where the cost estimate can be implemented as the expected execution time of the candidate execution plan. Optionally, after obtaining the cost estimate for each candidate execution plan in the candidate execution plan set, the candidate execution plan with the lowest cost estimate is selected as the execution plan for the query statement.
[0168] Step 602: Obtain the plan hint information of the execution plan that meets the preset execution requirements from the execution plan of at least one query statement, and add the plan hint information of the execution plan that meets the preset execution requirements to the plan hint table.
[0169] Optionally, the hint information of execution plans that meet preset execution requirements from the execution plans of at least one query statement is obtained, and the hint information of execution plans that meet the preset execution requirements is added to the OUTLINE table. Illustratively, the execution plans of at least one query statement are simulated, and the simulated execution duration of the execution plans of at least one query statement is obtained. If the simulated execution duration meets the preset duration condition, it is determined that the execution plan meets the preset execution requirements.
[0170] After confirming that the execution plan meets the preset execution requirements, the HINT information of the execution plan is obtained. For example, the execution plan is parsed to obtain at least one operator, and this operator is mapped to HINT information supported by the database.
[0171] After obtaining the hint information for at least one query statement, add the hint information for at least one query statement to the OUTLINE table. For example, generate the hash value of the query statement and store the hash value and the corresponding hint information of the query statement in the OUTLINE table.
[0172] Indicative, such as Figure 7 As shown, each OUTLINE in the OUTLINE table (also known as the planning reminder table 705) Figure 7 Q1 to Q n Each OUTLINE corresponds to a query statement, and each OUTLINE stores the following information: the identifier of the query statement (such as the hash value of the query statement), the hint information of the query statement (...). Figure 7 P1 to P n ), whether the OUTLINE is valid, the OUTLINE update time, the conditions for the OUTLINE to take effect, the HINT version number, etc.
[0173] Step 603: During the operation of the database, obtain the first query statement for the database.
[0174] Alternatively, the database can be implemented as a relational database.
[0175] Optionally, the first query statement is a query statement in at least one query statement.
[0176] In some embodiments, a first query request is received during database operation; the first query request is parsed to obtain a first query statement; and a second execution plan for the first query statement is determined based on the first query statement and plan hint information. Optionally, the client of the first application sends the first query request to the database management system, which parses the first query request to obtain the first query statement and determines a second execution plan for the first query statement based on the first query statement and plan hint information.
[0177] Step 604: If the first query statement meets the short query requirement, generate the third execution plan for the first query statement according to the preset short query rules.
[0178] Optionally, if the query type corresponding to the first query statement is a short query, then the first query statement is determined to meet the short query requirement.
[0179] Optionally, the first query statement is identified, and the identification result is obtained. If the identification result indicates that the query operation of the first query statement is a single-table query and only contains predicate conditions that can be hit by a single index, the query type corresponding to the first query statement is determined to be a short query. For example, a single-table query operation means that the SQL statement only involves operations on a single table (such as SELECT, UPDATE, DELETE) and does not contain multi-table joins (JOIN), subqueries, or set operations (UNION). Only containing predicate conditions that can be hit by a single index means that the conditions in the WHERE or ORDER BY clauses of the query can be completely covered by an existing index. After determining that the first query statement meets the short query requirements, a third execution plan for the first query statement is generated according to preset short query rules.
[0180] Please refer to Figure 7 , Figure 7 A schematic diagram of a data query method is shown. For example... Figure 7 As shown, before SQL statement 701 enters the optimizer, it is identified. If the query operation corresponding to SQL statement 701 is a single-table query and contains only predicate conditions that can be hit by a single index, it will be determined as a short query. When SQL statement 701 is determined to be a short query, it is input into the fast path mechanism 703 to obtain the execution plan a of SQL statement 701. The fast path mechanism 703 predefines short query rules. For example, for the SQL statement "SELECT username, email FROM users WHERE user_id=123", this SQL statement is a single-table query and user_id is the primary key, so it is determined to be a short query. The execution plan for this short query is directly generated as "quickly locate the record where user_id=123 through the primary key index and return username and email".
[0181] Step 605: Execute the third execution plan in the database to obtain the query results.
[0182] That is, at least one third query operation in the third execution plan is executed in the database to obtain the query result.
[0183] If the first query meets the short query requirement, it is unnecessary to input the first query into the optimizer; the third execution plan is executed directly to obtain the query result. (Illustrative example follows.) Figure 7 As shown, when SQL statement 701 is determined to be a short query, the execution plan a generated by the fast path mechanism 703 is input into the executor 702, and the database is called to execute the execution plan a to obtain the query result 704.
[0184] Step 606: If the first query statement does not meet the short query requirement, match the first query statement with the plan hint table.
[0185] Optionally, if the query type corresponding to the first query statement is not a short query, match the first query statement with the plan hint table. Illustratively, matching the first query statement with the plan hint table means determining whether the plan hint table records the plan hint information corresponding to the first query statement, i.e., the hint information. Optionally, obtain the hash value of the first query statement, and traverse the plan hint table based on the hash value of the first query statement, matching the first query statement with the plan hint table, i.e., querying whether the plan hint table contains the hash value of the first query statement.
[0186] Step 607: If the first query statement and the plan hint table do not match, input the first query statement into the optimizer to obtain the fourth execution plan.
[0187] The fourth execution plan includes at least one fourth query operation.
[0188] If the hash value of the first query statement is not included in the query plan hint table, it means that the plan hint table does not store the plan hint information corresponding to the first query statement. In this case, the first query statement is directly input into the optimizer to obtain the fourth execution plan. For example, using a cost-based optimizer, the first query statement is transformed into a first syntax tree (such as an abstract syntax tree, AST). The first syntax tree and the current database statistics are then input into the optimizer to obtain the fourth execution plan.
[0189] Step 608: Execute the fourth execution plan in the database to obtain the query results.
[0190] That is, at least one fourth query operation in the fourth execution plan is executed in the database to obtain the query result.
[0191] Indicative, such as Figure 7 As shown, if the SQL statement 701 and the plan hint table 705 do not match, the SQL statement 701 is input into the executor 702. The executor 702 calls the optimizer to generate execution plan b (that is, the fourth execution plan mentioned above), and then calls the database to execute execution plan b to obtain the query result 704.
[0192] Step 609: If the first query statement matches the plan hint information of the first execution plan in the plan hint table, bind the plan hint information of the first execution plan and the first query statement to obtain the second query statement.
[0193] The first execution plan includes at least one first query operation.
[0194] If the hash value of the first query statement is present in the query plan hint table, it means that the table stores the plan hint information corresponding to the first query statement. This plan hint information corresponds to the first execution plan. Therefore, it is necessary to bind the plan hint information of the first execution plan and the first query statement to obtain the second query statement. For illustration, if the hash value in one of the OUTLINE tables is the same as the hash value of the first query statement, it means that the OUTLINE stores the hint information of the first query statement. Retrieving this hint information and inserting it into the first query statement yields the second query statement.
[0195] Step 610: Input the second query statement into the optimizer to obtain the second execution plan.
[0196] The second execution plan includes at least one second query operation.
[0197] To illustrate, taking a cost-based (CBO) optimizer as an example, the second query statement is transformed into a second syntax tree (such as an abstract syntax tree AST). The second syntax tree and the current statistics of the database are then input into the optimizer to obtain the second execution plan.
[0198] Step 611: Execute the second execution plan in the database to obtain the query results.
[0199] That is, at least one second query operation in the second execution plan is executed in the database to obtain the query result.
[0200] Indicative, such as Figure 7 As shown, when SQL statement 701 matches plan hint table 705, the HINT information of the SQL statement is obtained from plan hint table 705. Figure 7 From P1' to P n ' indicates the matching HINT information), insert the HINT information into the SQL statement, input the SQL statement with the inserted HINT information into the executor 702, the executor 702 calls the optimizer to generate execution plan c (that is, the second execution plan mentioned above), and then calls the database to execute execution plan c to obtain query result 704.
[0201] Step 612: If the second execution plan meets the abnormal execution conditions, the plan prompt information of the first execution plan in the control plan prompt table becomes invalid.
[0202] Considering that business data and load conditions are constantly changing during database operation, execution plans generated by the plan generation model based on data and load conditions at a specific point in time may not be suitable for new business scenarios. To address this issue, a load monitoring system is introduced to monitor database load conditions in real time and accurately.
[0203] Indicative, such as Figure 7 As shown, the load monitoring system 706 monitors the execution time of each query statement, which is the complete time from the query statement being input into the database to obtaining the returned result (including optimizer processing time and execution plan execution time). If the execution time of a query statement is found to be longer than the preset time, the load monitoring system 706 determines whether the execution plan of the query statement was generated by the plan generation model 707, that is, whether the execution plan of the query statement was generated based on the execution prompt information. If so, it is determined that the execution plan of the query statement meets the abnormal execution conditions, and the execution prompt information corresponding to the query statement in the control plan prompt table 705 of the load monitoring system 706 becomes invalid, that is, the OUTLINE corresponding to the query statement in the control plan prompt table 705 becomes invalid.
[0204] It should be noted that, in addition to the load monitoring system 706, DBAs (Database Administrators) can also manually intervene in the OUTLINE table, such as invalidating the OUTLINE corresponding to expired query statements, thereby avoiding the negative impact of expired OUTLINE on performance.
[0205] Step 613: Use the execution record data corresponding to the second execution plan as training sample data to update the model parameters of the plan generation model.
[0206] In other words, if the second execution plan meets the abnormal execution conditions, the execution record data corresponding to the second execution plan is used as training sample data to update the model parameters of the plan generation model. The updated plan generation model is then used in the subsequent data query process.
[0207] Indicative, such as Figure 7As shown, the plan generation model 707 can be implemented as a comparison model. For execution plans that meet the abnormal execution conditions, the load monitoring system 706 will obtain the execution record data corresponding to the execution plan, such as the query statement corresponding to the execution plan, execution plan details, and number of data scan rows. Then, the execution record data is added to the training data of the comparison model. This execution record data will serve as negative sample data in the training data of the comparison model. The model parameters of the comparison model can be updated through this negative sample data. The updated comparison model will be used in subsequent data query processes. For example, a new batch of query statements can be obtained, and execution plans can be generated for the new batch of query statements. Then, plan prompt information for the execution plans of the new batch of query statements can be generated, and the plan prompt information for the new batch of query statements can be updated in the plan prompt table 705.
[0208] In summary, the data query method provided in this application, through the organic integration of an AI optimizer and a load monitoring system, constructs an intelligent optimization system capable of effectively responding to changes in business scenarios. Leveraging the real-time feedback mechanism of load monitoring, the system can promptly eliminate the adverse effects of expired plans; while newly added training data helps the AI optimizer quickly adapt to new business loads and data characteristics, continuously ensuring the high-performance operation of the database management system.
[0209] The data query method provided in this application can be applied to e-commerce, gaming applications, payment platforms, social platforms, logistics, finance and other scenarios. This application does not limit it. The following explanation uses logistics and finance scenarios as examples.
[0210] (I) Logistics scenario.
[0211] Step 1: In the preprocessing stage, obtain at least one query statement for the logistics database.
[0212] The logistics database is used to store logistics data, such as order information tables, inventory record tables, transportation status tables, delivery network tables, vehicle resource tables, and personnel resource tables.
[0213] Optionally, during the preprocessing stage, at least one query statement is pre-constructed for each logistics order in the logistics database, such as a query statement for querying logistics delivery details.
[0214] Step 2: Generate at least one execution plan corresponding to at least one query statement through the plan generation model, and obtain the plan prompt information corresponding to the execution plan that meets the preset execution requirements.
[0215] A plan generation model is a pre-trained machine learning model used to generate execution plans.
[0216] Step 3: During the operation of the logistics database, receive the first query request sent by the logistics platform's client.
[0217] As an illustration, when a user triggers a query operation on the logistics platform's client, the client will send a first query request to the logistics database management system. For example, the first query request is used to request the logistics delivery details of a specified logistics order.
[0218] Step 4: Obtain the first query statement based on the first query request.
[0219] The first query statement is a query statement among at least one query statement involved in the aforementioned preprocessing stage. Illustratively, parsing the first query request yields the first query statement, which belongs to at least one pre-constructed query statement. For example, the first query statement is used to query the logistics delivery details of a specified logistics order.
[0220] Step 5: If the first query statement and the plan hint information of the first execution plan in the plan hint table match, determine the second execution plan based on the first query statement and the plan hint information.
[0221] Optionally, if the first query statement matches the plan hint information of the first execution plan in the plan hint table, the plan hint information of the first execution plan is inserted into the first query statement to obtain the second query statement. The second query statement is then input into the optimizer to obtain the second execution plan.
[0222] The second execution plan includes at least one second query operation.
[0223] Step 6: Execute the second execution plan in the logistics database to obtain the logistics query results.
[0224] That is, at least one second query operation is performed in the logistics database to obtain the logistics query result. For example, if the first query request is used to query the logistics delivery details of a specified logistics order, then the logistics query result refers to the logistics delivery details of the specified logistics order.
[0225] Step 7: Send the logistics query results back to the logistics platform's client.
[0226] As an illustration, the database management system of the logistics database receives the logistics query results and sends them to the client of the logistics platform.
[0227] (ii) Financial scenarios.
[0228] Step 1: In the preprocessing stage, obtain at least one query statement for the financial database.
[0229] Among them, financial databases are used to store financial transaction information, such as user account tables, transaction record tables, risk assessment tables, etc.
[0230] Optionally, during the preprocessing stage, at least one query statement is pre-constructed for each account, such as a query statement for querying the account balance.
[0231] Step 2: Generate at least one execution plan corresponding to at least one query statement through the plan generation model, and obtain the plan prompt information corresponding to at least one execution plan that meets the preset execution requirements.
[0232] A plan generation model is a pre-trained machine learning model used to generate execution plans.
[0233] Step 3: During the operation of the financial database, receive the first query request sent by the client of the financial trading platform.
[0234] As an illustration, when a query operation is triggered on the client side of a financial trading platform, a first query request is sent to the database management system of the financial database. For example, the first query request is used to request the account balance of a specified account.
[0235] Step 4: Obtain the first query statement based on the first query request.
[0236] The first query statement is a query statement among at least one query statement involved in the aforementioned preprocessing stage. Illustratively, parsing the first query request yields the first query statement, which belongs to at least one pre-constructed query statement. For example, the first query statement is used to query the account balance of a specified account.
[0237] Step 5: If the first query statement and the plan hint information of the first execution plan in the plan hint table match, determine the second execution plan of the first query statement based on the first query statement and the plan hint information.
[0238] Optionally, if the first query statement matches the plan hint information of the first execution plan in the plan hint table, the plan hint information of the first execution plan is inserted into the first query statement to obtain the second query statement. The second query statement is then input into the optimizer to obtain the second execution plan.
[0239] The second execution plan includes at least one second query operation.
[0240] Step 6: Execute the second execution plan in the financial database to obtain the financial query results.
[0241] That is, at least one second query operation is performed in the logistics database to obtain the logistics query result. For example, if the first query request is used to request the account balance of a specified account, then the financial query result refers to the account balance of the specified account.
[0242] Step 7: Feedback the financial query results to the client of the financial trading platform.
[0243] To illustrate, after the financial database management system receives the logistics query results, it sends the financial query results to the client of the financial trading platform.
[0244] Figure 8 This is a structural block diagram of a data query apparatus provided in an exemplary embodiment of this application, such as... Figure 8 As shown, the device includes:
[0245] The first processing module 810 is used to generate a first execution plan for a first query statement through a plan generation model. The first execution plan includes a first query operation performed by the database according to the first query statement. The plan generation model is a pre-trained machine learning model for generating execution plans.
[0246] The first processing module 810 is used to obtain plan prompt information corresponding to the first query operation when the first execution plan meets the preset execution requirements. The plan prompt information is used to prompt the operation method of the first query operation.
[0247] The second processing module 820 is used to determine a second execution plan for the first query statement based on the first query statement and the plan prompt information during the operation of the database. The second execution plan includes the database performing at least one second query operation according to the first query statement.
[0248] The second processing module 820 is used to perform the at least one second query operation in the database to obtain query results.
[0249] In some embodiments, the first processing module 810 is configured to obtain the plan prompt information corresponding to the first execution plan when the first simulation duration of the first execution plan is less than a preset first execution duration, wherein the first simulation duration represents the execution duration required to simulate the execution of the first execution plan in the database.
[0250] In some embodiments, the first processing module 810 is configured to obtain at least two simulated running conditions; simulate running the database according to the at least two simulated running conditions, and obtain first candidate durations corresponding to the at least two simulated running conditions respectively; the first candidate duration represents the execution time required to execute the first execution plan in the database based on the simulated running conditions; and determine the first simulation duration based on the at least two first candidate durations.
[0251] In some embodiments, the first processing module 810 is configured to obtain the plan prompt information corresponding to the first execution plan when the second simulation duration of the first query operation is less than the preset second execution duration, wherein the second simulation duration represents the execution duration required for the first query operation when the first execution plan is simulated in the database.
[0252] In some embodiments, the first processing module 810 is configured to, when the first execution plan meets the preset execution requirements, parse the first execution plan to obtain first operation data corresponding to the first query operation; obtain a prompt information template corresponding to the operation mode of the first query operation; and generate the plan prompt information based on the first operation data and the prompt information template.
[0253] In some embodiments, the first processing module 810 is configured to insert the plan suggestion information into the first query statement to obtain a second query statement; and to analyze the second query statement through an optimizer to obtain a second execution plan, wherein the optimizer includes at least one of a rule-based optimizer and a cost-based optimizer.
[0254] In some embodiments, the first processing module 810 is configured to determine the insertion position of the plan prompt information in the first query statement; insert the plan prompt information at the insertion position of the first query statement to obtain the second query statement.
[0255] In some embodiments, the first processing module 810 is configured to control the plan prompt information to become invalid if the second execution plan meets the abnormal execution conditions.
[0256] In some embodiments, the first processing module 810 is configured to obtain the execution duration of the second execution plan in the database; and if the execution duration exceeds a preset duration, to control the plan prompt information to become invalid.
[0257] In some embodiments, the plan generation model is a comparison model; the first processing module 810 is used to obtain the execution record data corresponding to the second execution plan when the second execution plan meets the abnormal execution conditions; and update the model parameters of the plan generation model with the execution record data corresponding to the second execution plan as negative sample data.
[0258] In some embodiments, the first processing module 810 is configured to generate a third execution plan for the first query statement according to a preset short query rule when the first query statement meets the short query requirement; and execute the query process represented by the third execution plan in the database to obtain the query result.
[0259] In some embodiments, the first processing module 810 is configured to, during the process of the plan prompt information taking effect, update the first execution plan based on the current running status of the database through the plan generation model when the execution prompt information meets preset requirements; determine updated plan prompt information based on the updated first execution plan; and, during the operation of the database, determine the second execution plan of the first query statement based on the first query statement and the updated plan prompt information.
[0260] In some embodiments, if the generation time of the execution prompt information is longer than a preset time, the first execution plan is updated based on the current running status of the database through the plan generation model; or, if the current running status of the plan generation model meets the status change requirements, the first execution plan is updated based on the current running status of the database through the plan generation model.
[0261] In some embodiments, the at least one second query operation includes the first query operation; wherein the first execution plan and the second execution plan are the same, or the first execution plan and the second execution plan are different.
[0262] In summary, the data query apparatus and method provided in this application generate a first execution plan for a first query statement using a pre-trained plan generation model, and then obtain the corresponding plan hint information. During database runtime, the second execution plan is quickly generated and executed by combining the first query statement and the existing plan hint information to obtain the query results. Compared with related technologies that use a cost-based optimizer to generate execution plans during database runtime, in this application, the first execution plan is generated by an AI model (i.e., a plan generation model), and its corresponding plan hint information ensures that the second execution plan generated during database runtime can inherit the optimization strategy of the first execution plan, thereby guaranteeing the quality of the execution plan. Furthermore, this application generates the first execution plan using a plan generation model before database runtime and represents the first execution plan through plan hint information. During database runtime, the system can directly obtain the AI analysis results (i.e., the first execution plan) based on the plan hint information, avoiding the AI inference process during database runtime. This improves the generation efficiency of the execution plan while ensuring its quality, thereby improving data query efficiency.
[0263] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the content structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0264] Please refer to Figure 9 This illustration shows a structural block diagram of a computer device provided in one embodiment of this application. The computer device 900 may be... Figure 1 The terminal or server in the computer system shown is used to implement the data query method provided in the above embodiments. Specifically:
[0265] Typically, computer device 900 includes a processor 901 and a memory 902.
[0266] Processor 901 may include one or more processing cores, such as a quad-core processor or an octa-core processor. Processor 901 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), and PLA (Programmable Logic Array). Processor 901 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 901 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 901 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0267] The memory 902 may include one or more computer-readable storage media, which may be non-transitory. The memory 902 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 902 are used to store a computer program configured to be executed by one or more processors to implement the data query method described above.
[0268] In some embodiments, the computer device 900 may also optionally include other components 903, such as a peripheral device interface and at least one peripheral device. The processor 901, memory 902, and peripheral device interface can be connected via a bus or signal lines. Each peripheral device can be connected to the peripheral device interface via a bus, signal lines, or a circuit board. Specifically, the peripheral device includes at least one of the following: radio frequency circuitry, a display screen, audio circuitry, and a power supply.
[0269] Those skilled in the art will understand that Figure 9 The structure shown does not constitute a limitation on the computer device 900, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0270] In an exemplary embodiment, a computer-readable storage medium is also provided, wherein a computer program is stored in the storage medium, and the computer program, when executed by a processor, implements the above-described data query method. Optionally, the computer-readable storage medium may include: ROM (Read-Only Memory), RAM (Random Access Memory), SSD (Solid State Drives), or optical disc, etc. The random access memory may include ReRAM (Resistance Random Access Memory) and DRAM (Dynamic Random Access Memory).
[0271] In an exemplary embodiment, a computer program product is also provided, the computer program product including a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, causing the computer device to perform the data query method described above.
[0272] It should be noted that the collection and processing of relevant data (such as the first content requirement) in this application should strictly comply with the requirements of relevant national laws and regulations, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of laws and regulations and the authorization of the personal information subject.
[0273] It should be understood that "multiple" as used herein refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. Furthermore, the step numbers described herein are merely illustrative of one possible execution order. In some other embodiments, the steps may not be executed in numerical order, such as two steps with different numbers being executed simultaneously, or two steps with different numbers being executed in the reverse order of the illustration. This application does not limit this.
[0274] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A data query method, characterized in that, The method includes: A first execution plan for a first query statement is generated using a plan generation model. The first execution plan includes a first query operation performed by the database based on the first query statement. The plan generation model is a pre-trained machine learning model used to generate execution plans. If the first execution plan meets the preset execution requirements, obtain the plan prompt information corresponding to the first execution plan. The plan prompt information is used to prompt the operation method of the first query operation. During the operation of the database, based on the first query statement and the plan prompt information, a second execution plan for the first query statement is determined. The second execution plan includes at least one second query operation performed by the database according to the first query statement. Execute the at least one second query operation in the database to obtain query results.
2. The method according to claim 1, characterized in that, The step of obtaining the plan prompt information corresponding to the first execution plan when the first execution plan meets the preset execution requirements includes: If the first simulation duration of the first execution plan is less than the preset first execution duration, the plan prompt information corresponding to the first execution plan is obtained, where the first simulation duration represents the execution duration required to simulate the execution of the first execution plan in the database.
3. The method according to claim 2, characterized in that, The method further includes: Obtain at least two simulation run conditions; The database is simulated based on the at least two simulated operating conditions to obtain the first candidate duration corresponding to each of the at least two simulated operating conditions; the first candidate duration represents the execution time required to execute the first execution plan in the database based on the simulated operating conditions. The first simulation duration is determined based on at least two first candidate durations.
4. The method according to claim 1, characterized in that, The step of obtaining the plan prompt information corresponding to the first execution plan when the first execution plan meets the preset execution requirements includes: If the second simulation duration of the first query operation is less than the preset second execution duration, the plan prompt information corresponding to the first execution plan is obtained, whereby the second simulation duration represents the execution duration required for the first query operation when the first execution plan is simulated in the database.
5. The method according to any one of claims 1 to 4, characterized in that, The step of obtaining the plan prompt information corresponding to the first execution plan when the first execution plan meets the preset execution requirements includes: If the first execution plan meets the preset execution requirements, the first execution plan is parsed to obtain the first operation data corresponding to the first query operation; Obtain the prompt information template corresponding to the operation method of the first query operation; The plan prompt information is generated based on the first operation data and the prompt information template.
6. The method according to any one of claims 1 to 4, characterized in that, The step of determining the second execution plan for the first query statement based on the first query statement and the plan suggestion information includes: Insert the plan prompt information into the first query statement to obtain the second query statement; The second query statement is analyzed by an optimizer to obtain the second execution plan. The optimizer includes at least one of a rule-based optimizer and a cost-based optimizer.
7. The method according to claim 6, characterized in that, The step of inserting the plan prompt information into the first query statement to obtain the second query statement includes: Determine the insertion position of the plan prompt information in the first query statement; The plan hint information is inserted at the insertion position of the first query statement to obtain the second query statement.
8. The method according to any one of claims 1 to 4, characterized in that, The method further includes: If the second execution plan meets the abnormal execution conditions, the control plan prompt information becomes invalid.
9. The method according to claim 8, characterized in that, The step of controlling the plan prompt information to become invalid when the second execution plan meets the abnormal execution conditions includes: Obtain the execution duration of the second execution plan in the database; If the execution time exceeds the preset time, the plan prompt information will be disabled.
10. The method according to claim 8, characterized in that, The plan generation model is a comparative model; the method further includes: If the second execution plan meets the abnormal execution conditions, obtain the execution record data corresponding to the second execution plan; The execution record data corresponding to the second execution plan is used as negative sample data to update the model parameters of the plan generation model.
11. The method according to any one of claims 1 to 4, characterized in that, The method further includes: If the first query statement meets the short query requirement, a third execution plan for the first query statement is generated according to the preset short query rules; The query process represented by the third execution plan is executed in the database to obtain the query results.
12. The method according to any one of claims 1 to 4, characterized in that, The method further includes: During the process of the plan prompt information taking effect, if the execution prompt information meets the preset requirements, the first execution plan is updated based on the current running status of the database through the plan generation model; The updated plan prompt information is determined based on the updated first execution plan; During the operation of the database, the second execution plan for the first query statement is determined based on the first query statement and the updated plan hint information.
13. The method according to claim 12, characterized in that, When the execution prompt information meets preset requirements, the plan generation model updates the first execution plan based on the current running status of the database, including: If the generation time of the execution prompt information exceeds a preset time, the first execution plan is updated based on the current running status of the database using the plan generation model; or, If the current running state of the plan generation model meets the state change requirements, the first execution plan is updated based on the current running state of the database through the plan generation model.
14. The method according to any one of claims 1 to 4, characterized in that, The at least one second query operation includes the first query operation; wherein the first execution plan and the second execution plan are the same, or the first execution plan and the second execution plan are different.
15. A data query device, characterized in that, The device includes: The first processing module is configured to generate a first execution plan for a first query statement using a plan generation model. The first execution plan includes a first query operation performed by the database based on the first query statement. The plan generation model is a pre-trained machine learning model used to generate execution plans. The first processing module is used to obtain plan prompt information corresponding to the first query operation when the first execution plan meets the preset execution requirements. The plan prompt information is used to prompt the operation method of the first query operation. The second processing module is used to determine a second execution plan for the first query statement based on the first query statement and the plan prompt information during the operation of the database. The second execution plan includes the database performing at least one second query operation according to the first query statement. The second processing module is used to execute the at least one second query operation in the database to obtain query results.
16. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing a computer program that is loaded and executed by the processor to implement the data query method as described in any one of claims 1 to 14.
17. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which is loaded and executed by a processor to implement the data query method as described in any one of claims 1 to 14.
18. A computer program product, characterized in that, The computer program product includes a computer program stored in a computer-readable storage medium, and a processor reads from and executes the computer program to implement the data query method as described in any one of claims 1 to 14.
