Resource consumption prediction method and device of query request and nonvolatile storage medium

By using a compressed two-layer long short-term memory network model to accurately predict the resource consumption of database query requests, the problem of inaccurate resource consumption prediction in traditional database query optimization is solved, and efficient query optimization and adaptive resource scheduling are achieved.

CN121833762APending Publication Date: 2026-04-10AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-26
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Traditional database query optimizers fail to accurately predict resource consumption when handling complex queries, peak concurrency, and multi-tenant scenarios, leading to performance issues such as excessive CPU usage and memory overflow. Furthermore, they lack the ability to learn about dynamic changes in system resources and long-term characteristics of query behavior.

Method used

A compressed two-layer long short-term memory network model is adopted. By acquiring the resource consumption characteristics of real-time query requests, such as syntax tree structure, operator sequence and historical resource consumption statistics, accurate prediction is made. Combined with scheduling and load statistics within a preset time window, the prediction of CPU occupancy ratio, memory usage threshold and input/output bandwidth is realized.

Benefits of technology

It enables accurate prediction of real-time database query resource requirements, improves system adaptability, realizes dynamic scheduling of database resources and efficient query optimization, and solves the problems of inaccurate resource consumption prediction and untimely response.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121833762A_ABST
    Figure CN121833762A_ABST
Patent Text Reader

Abstract

The invention discloses a resource consumption prediction method and device for a query request and a nonvolatile storage medium. The method comprises the steps that resource consumption characteristics of a real-time query request used for querying a target database are obtained, and the language of the real-time query request is a structured query language; the resource consumption characteristics comprise a syntax tree structure, an operator sequence, historical resource consumption statistical information of query requests of the same category as the real-time query request, and scheduling and load statistical information in a preset time window; the resource consumption characteristics are input into a target resource prediction model, a target resource consumption prediction result of the real-time query request is obtained, and the target resource prediction model is a compressed double-layer long-short-term memory network model. The technical problems that in the traditional database query optimization process, structured statement resource consumption prediction is not accurate, response is not timely, and a cost model is prone to distortion are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database query optimization technology, and more specifically, to a method, apparatus, and non-volatile storage medium for predicting the resource consumption of query requests. Background Technology

[0002] In today's data-intensive application environments, database management systems face increasing challenges in data processing and query optimization. Especially in complex queries, high concurrency, and multi-tenant scenarios, accurately estimating the resource consumption of a single SQL statement has become crucial for improving system throughput, reducing resource conflicts, and optimizing execution plans.

[0003] Traditional database query optimizers primarily rely on statistics and heuristics to estimate operator costs, which simplifies the optimization decision-making process to some extent. However, the accuracy of such methods is limited by the freshness and coverage of the statistics, and resource estimation often fails when handling complex nested queries, atypical data distributions, or high-concurrency requests, leading to performance issues such as excessive CPU usage and memory overflow. Furthermore, due to a lack of ability to learn from dynamic changes in system resources and long-term characteristics of query behavior, traditional cost models struggle to adapt to evolving query patterns, fluctuations in system resources, or rapid expansion of data scale, resulting in difficulties in resource-aware query optimization.

[0004] There is currently no effective solution to the above problems. Summary of the Invention

[0005] This invention provides a method, apparatus, and non-volatile storage medium for predicting resource consumption of query requests, in order to at least solve the technical problems of inaccurate prediction of resource consumption of structured statements, untimely response, and distorted cost models in traditional database query optimization processes.

[0006] According to one aspect of the present invention, a method for predicting the resource consumption of a query request is provided, comprising: acquiring resource consumption characteristics of a real-time query request for querying a target database, wherein the language of the real-time query request is a structured query language, and the resource consumption characteristics include a syntax tree structure, an operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window; inputting the resource consumption characteristics into a target resource prediction model to obtain a target resource consumption prediction result for the real-time query request, wherein the target resource prediction model is a compressed two-layer long short-term memory network model, and the target resource consumption prediction result includes a predicted CPU occupancy ratio, a predicted memory usage threshold, and a ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

[0007] Optionally, the steps for determining the target resource prediction model are as follows: constructing an initial resource prediction model, wherein the initial resource prediction model is a two-layer long short-term memory network structure; obtaining historical query logs of the target database; constructing a time-series training dataset based on the historical query logs, wherein the time-series training dataset includes resource consumption features corresponding to multiple historical query requests; training the initial resource prediction model based on the time-series training dataset until the model converges to obtain the full resource prediction model; compressing the full resource prediction model to obtain the target resource prediction model.

[0008] Optionally, the full resource prediction model is compressed to obtain a target resource prediction model, including: determining the target hidden unit in the full resource prediction model, wherein the target hidden unit is a hidden unit whose contribution to the prediction output is less than a preset threshold; removing the target hidden unit from the full resource prediction model to obtain a first resource prediction model; quantizing and compressing the weights of multiple levels in the first resource prediction model to obtain a second resource prediction model; and fixing the calculation path of the second resource prediction model to static to obtain the target resource prediction model.

[0009] Optionally, the resource consumption characteristics of real-time query requests in the target database are obtained, including: parsing the real-time query requests and constructing an abstract syntax tree corresponding to the real-time query requests; using depth-first traversal encoding, traversing from the root node of the abstract syntax tree to obtain the nesting level and dependency relationship of the real-time query requests, as the syntax tree structure; obtaining a preset operator database, wherein the operator database includes multiple operators and their respective identifiers; constructing an operator embedding matrix based on the operator database, wherein each row of the operator embedding matrix corresponds to the embedding vector of an operator; mapping the operators of the real-time query requests to a vector sequence based on the operator embedding matrix, as the operator sequence; obtaining historical resource consumption information of multiple query requests of the same category as the real-time query requests, wherein the resource consumption information includes CPU execution time, memory usage, and input / output read / write rate; calculating the mean and variance of the historical resource consumption information of multiple query requests of the same category as the real-time query requests, as historical resource consumption statistics; and obtaining the query statement scheduling frequency and system average load within a preset time window, as scheduling and load statistics within the preset time window.

[0010] Optionally, it also includes: if the prediction time of the target resource prediction model exceeds a preset time threshold, obtaining the average historical resource consumption information of historical query requests that match the real-time query request in the target database; calculating the prediction deviation of the target resource prediction model based on the average historical resource consumption information, resource consumption prediction results, and prediction time; and determining that the target resource prediction model has experienced performance degradation if the prediction deviation exceeds a preset safety threshold.

[0011] Optionally, the method further includes: recording the actual resource consumption results of multiple query requests and the predicted resource consumption results of multiple query requests within a preset time period; calculating the loss function value of the target resource prediction model based on the actual resource consumption results and the predicted resource consumption results; adjusting the parameters of the target resource prediction model based on the loss function value to obtain an updated target resource prediction model; and applying the updated target resource prediction model to the target database when the prediction accuracy of the updated target resource prediction model reaches a preset accuracy threshold and the prediction time of the updated target resource prediction model is less than a preset time threshold.

[0012] According to another aspect of the present invention, a resource consumption prediction device for query requests is also provided, comprising: an acquisition module, configured to acquire resource consumption characteristics of a real-time query request for querying a target database, wherein the language of the real-time query request is a structured query language, and the resource consumption characteristics include a syntax tree structure, an operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window; and a prediction module, configured to input the resource consumption characteristics into a target resource prediction model to obtain a target resource consumption prediction result for the real-time query request, wherein the target resource prediction model is a compressed two-layer long short-term memory network model, and the target resource consumption prediction result includes a central processing unit (CPU) predicted occupancy ratio, a memory usage prediction threshold, and a ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

[0013] According to another aspect of the present invention, a non-volatile storage medium is also provided, the non-volatile storage medium including a stored program, wherein, when the program is running, the device where the non-volatile storage medium is located executes the resource consumption prediction method for any of the above query requests.

[0014] According to another aspect of the present invention, a computer device is also provided, the computer device including a processor, the processor being configured to run a program, wherein the program, when running, executes the resource consumption prediction method for any of the above-described query requests.

[0015] According to another aspect of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements the resource consumption prediction method for any of the above-described query requests.

[0016] In this embodiment of the invention, a method for predicting the resource consumption of query requests is employed. This method obtains the resource consumption characteristics of real-time query requests used to query the target database. The language of the real-time query request is a structured query language (SCL). The resource consumption characteristics include the syntax tree structure, operator sequences, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window. These resource consumption characteristics are then input into a target resource prediction model to obtain the target resource consumption prediction result for the real-time query request. The target resource prediction model is a compressed two-layer long short-term memory (LSTM) network model. The target resource consumption prediction result includes the predicted CPU occupancy ratio, memory usage prediction threshold, and the ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold. This achieves the goal of accurately predicting the real-time query resource requirements of the database, improving the system's adaptive capability, and thus realizing the technical effects of dynamic database resource scheduling and efficient query optimization. Furthermore, it solves the technical problems of inaccurate prediction of resource consumption for structured statements, untimely response, and distorted cost models in traditional database query optimization processes. Attached Figure Description

[0017] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:

[0018] Figure 1 A hardware block diagram of a computer terminal for implementing a resource consumption prediction method for query requests is shown.

[0019] Figure 2 This is a flowchart illustrating the resource consumption prediction method for query requests provided in an embodiment of the present invention.

[0020] Figure 3 This is a flowchart of the training process of a two-layer long short-term memory network model provided by an optional embodiment of the present invention;

[0021] Figure 4 This is a compressed flowchart of the full resource prediction model provided according to an optional embodiment of the present invention;

[0022] Figure 5 This is a flowchart of the system dynamic feedback closed-loop mechanism provided by an optional embodiment of the present invention;

[0023] Figure 6 This is an architecture diagram of a resource consumption prediction system for query requests provided according to an optional embodiment of the present invention.

[0024] Figure 7 This is a structural block diagram of a resource consumption prediction device for query requests provided according to an embodiment of the present invention. Detailed Implementation

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

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

[0027] First, some nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows:

[0028] LSTM (Long Short-Term Memory) is a recurrent neural network structure with memory capabilities that can effectively capture long-term dependencies in time series data and is suitable for time series prediction tasks.

[0029] Model distillation is a method that improves model compression and inference efficiency by training a lightweight model (student model) to mimic the behavior of a large, complex model (teacher model).

[0030] Shared memory is a memory management mechanism provided by the operating system that allows multiple processes to access the same physical memory area for efficient inter-process data exchange.

[0031] CGroup (Control Groups) is a resource management module in the Linux kernel used to limit, record, and isolate the CPU, memory, and I / O resource usage of process groups, ensuring the rational allocation of system resources.

[0032] According to an embodiment of the present invention, a method embodiment for predicting resource consumption of query requests is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0033] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1 A hardware block diagram of a computer terminal for implementing a resource consumption prediction method for query requests is shown. Figure 1 As shown, the computer terminal 10 may include one or more processors (shown as 102a, 102b, ..., 102n in the figure) (the processor may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.

[0034] It should be noted that the aforementioned one or more processors and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10. As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).

[0035] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the resource consumption prediction method for query requests in this embodiment of the invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the resource consumption prediction method for query requests of the aforementioned application. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0036] The display can be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10.

[0037] Figure 2 This is a flowchart illustrating a resource consumption prediction method for query requests provided in an embodiment of the present invention, as shown below. Figure 2 As shown, the method includes the following steps:

[0038] Step S201: Obtain the resource consumption characteristics of the real-time query request used to query the target database. The language of the real-time query request is Structured Query Language. The resource consumption characteristics include the syntax tree structure, operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window.

[0039] In this step, Structured Query Language (SQL) is a standardized database query and management language widely used in relational database systems for data retrieval, updating, management, and definition. Resource consumption characteristics include the syntax tree structure, operator sequences, historical resource consumption statistics for query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window. First, an Abstract Syntax Tree (AST) can be generated by parsing the SQL statement to obtain the syntax tree structure of the real-time query request. The AST clearly represents the syntactic structure of the SQL statement and the logical relationships between operators, thus capturing the complexity and nesting level of the query. Second, the operator sequence of the execution plan is extracted. The operator sequence reflects the computational path designed by the database query optimizer to execute the SQL statement, including but not limited to selection, projection, join, and aggregation operations. Furthermore, the historical resource consumption statistics for query requests of the same category as real-time query requests, namely the historical average resource consumption, are derived from the database system's past operation records. By collecting and analyzing key resource consumption data such as CPU execution time, memory usage, and input / output read / write rates of past Structured Query Language (SCL) queries, a statistical distribution is formed, which is used to train the model to identify resource consumption patterns of similar queries. The scheduling and load statistics within a preset time window, namely time window statistics, include the query scheduling frequency and average system load within a specific time period, providing the model with real-time feedback on resource stress under high-concurrency scenarios.

[0040] Step S202: Input the resource consumption characteristics into the target resource prediction model to obtain the target resource consumption prediction result of the real-time query request. The target resource prediction model is a compressed two-layer long short-term memory network model. The target resource consumption prediction result includes the predicted CPU occupancy ratio, the predicted memory usage threshold, and the ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

[0041] In this step, the target resource prediction model is a compressed two-layer long short-term memory (LSTM) network model. The two-layer LSTM network model is a deep learning architecture that can be used to process and predict sequential data, such as time series or text sequences. In this optional embodiment, the model enhances the temporal memory and semantic understanding capabilities of SQL query resource consumption characteristics through two layers of LSTM unit stacking. This enables it to capture long-short-term dependencies and achieve accurate prediction of real-time query request resource consumption.

[0042] Specifically, resource consumption characteristics are input into the aforementioned target resource prediction model. During the model training phase, these characteristics are transformed into time-series tensors. The entire two-layer LSTM model parameters are trained using an external asynchronous training module and accelerated by a distributed graphics processing unit (GPU) cluster. Subsequently, model distillation is used to compress the model, removing redundant LSTM units while retaining key time-gating structures. The 32-bit floating-point weights are quantized into 8-bit integers, solidifying the dynamic computation graph into a static one, forming a lightweight inference engine. During the integration phase, the compressed inference engine is encapsulated as a C-language extension module, loaded into a database environment supporting runtime extensions via shared memory, and registered as a built-in function. When a real-time query request enters the database system, the target resource prediction model performs predictions in a resource-isolated background process by calling the execution function. Based on the input resource consumption characteristics, the execution function, through the inference process of the compressed model, outputs the target resource consumption prediction result. These correspond to the predicted CPU core utilization ratio, memory usage prediction threshold, and the ratio of predicted input / output bandwidth to the input / output bandwidth threshold, respectively. In other words, they represent the CPU core utilization ratio, memory usage limit, and input / output (IO) bandwidth pressure coefficient. This process is completed asynchronously in a dedicated thread pool, ensuring non-intrusiveness to the database main thread. Simultaneously, resource usage is limited through the CGroup mechanism, avoiding resource contention for other system services.

[0043] Through the above steps, the goal of accurately predicting the real-time query resource demand of the database is achieved, thereby improving the system's adaptive capability. This realizes the technical effects of dynamic scheduling of database resources and efficient query optimization, and solves the technical problems of inaccurate prediction of structured statement resource consumption, untimely response, and distorted cost model in the traditional database query optimization process.

[0044] As an optional embodiment, the steps for determining the target resource prediction model are as follows: Constructing an initial resource prediction model, wherein the initial resource prediction model is a two-layer long short-term memory network structure; obtaining historical query logs of the target database; constructing a time-series training dataset based on the historical query logs, wherein the time-series training dataset includes resource consumption features corresponding to multiple historical query requests; training the initial resource prediction model based on the time-series training dataset until the model converges to obtain a full resource prediction model; compressing the full resource prediction model to obtain the target resource prediction model.

[0045] Optionally, Figure 3 This is a flowchart illustrating the training process of a two-layer long short-term memory network model provided by an optional embodiment of the present invention. Figure 3As shown, firstly, to improve sequence modeling capabilities, a two-layer LSTM structure is adopted as the initial resource prediction model, and a gating control mechanism is introduced. The recursive relationship of the model is as follows:

[0046]

[0047] in, This represents the input vector at time step t. This is the hidden state from the previous step. for sigmoid The activation function, ReLU, is a linear rectified function used to enhance the numerical stability of the output. For learnable weight matrix, This serves as a bias term. The structure possesses temporal memory and nonlinear modeling capabilities, enabling it to capture the correlation between query behavior and resource consumption over long time spans. Secondly, the model training data originates from historical query logs in a database environment that supports runtime expansion. Each SQL query statement is encoded as a temporal sample, forming the temporal training dataset. This temporal training dataset includes resource consumption features corresponding to multiple historical query requests; these multidimensional features collectively construct the temporal input tensor. Subsequently, the initial resource prediction model was trained using the aforementioned time-series training dataset. The entire training process was accelerated using a distributed GPU cluster, and batches were divided using a data parallel approach. The model convergence efficiency was optimized by cross-node gradient aggregation, and finally, the full LSTM parameter file, i.e., the full resource prediction model, was output.

[0048] Finally, after the training phase, the resulting full resource prediction model typically has a large parameter scale and complex computational graph, making it difficult to directly integrate into the database system. Therefore, it must be compressed into a lightweight inference module through model distillation and structural reconstruction to obtain the target resource prediction model, thereby ensuring its deployability and real-time performance in the database kernel space. The aforementioned target resource prediction model can be embedded into the database kernel as a C language extension module. The specific process includes three key steps: dynamic linking encapsulation, shared memory mapping, and built-in function registration. To achieve a reentrant call mechanism, the input vector construction during the inference process does not depend on the global state but is dynamically generated through the execution plan information passed in from the query optimizer. The function definition is as follows:

[0049]

[0050] in, This represents the syntax tree structure corresponding to the SQL statement. This represents the sequence of operators in its execution plan. This represents a vector representing the historical resource consumption statistics for this type of query. The function represents the scheduling frequency and system load metrics within the current time window. This is a set of feature mapping rules, consistent with the input construction process during the training phase, ensuring the model's robustness to semantic changes. After being invoked by the inference engine, it outputs a 3D resource prediction vector as the output of the target resource prediction model.

[0051] As an optional embodiment, the full resource prediction model is compressed to obtain a target resource prediction model, including: determining the target hidden unit in the full resource prediction model, wherein the target hidden unit is a hidden unit whose contribution to the prediction output is less than a preset threshold; removing the target hidden unit from the full resource prediction model to obtain a first resource prediction model; quantizing and compressing the weights of multiple levels in the first resource prediction model to obtain a second resource prediction model; and fixing the calculation path of the second resource prediction model to static to obtain the target resource prediction model.

[0052] Optionally, Figure 4 This is a compressed flowchart of the full resource prediction model provided according to an optional embodiment of the present invention. Figure 4 As shown, firstly, to quantify the contribution of each hidden unit to the prediction result, a structure sensitivity index function is introduced:

[0053]

[0054] in, This represents the average gradient influence of the j-th hidden unit on the predicted output. Let be the activation value of the j-th unit at time step t. This represents the predicted resource consumption, where T is the sample length. Specifically, all data below a set threshold... The units that contribute little to resource prediction are considered low-contribution hidden units, i.e., target hidden units. By analyzing the hidden units in the time series data that contribute little to resource prediction, redundant units are identified using the information entropy decrease rate index. Target hidden units that do not affect prediction accuracy are removed, and only the time-gated structure with high influence is retained to obtain the first resource prediction model.

[0055] Secondly, the weight parameters are further quantized and compressed, and the 32-bit floating-point weights are mapped to 8-bit integer representations through symmetric quantization:

[0056]

[0057] in, For the original floating-point weights, This represents the average weight of the current layer. The scaling factor is automatically derived based on the maximum absolute value. The second resource prediction model is obtained by quantizing and compressing the weights of the first resource prediction model to obtain the integer weights for final storage. This process significantly reduces storage space while maintaining numerical representation accuracy and speeds up CPU inference. Finally, after compression, the second resource prediction model is converted from a dynamic graph representation to a static computation graph. Tensor shape freezing and control flow unrolling eliminate runtime branch overhead, allowing the inference path to be directly executed within the database process without interpreter dependency, resulting in the target resource prediction model. The final generated target resource prediction model is a lightweight model, encapsulated as a C language shared object, meeting real-time invocation requirements and featuring high throughput, low latency, and controllable resource overhead.

[0058] As an optional embodiment, obtaining the resource consumption characteristics of real-time query requests in the target database includes: parsing the real-time query requests and constructing an abstract syntax tree corresponding to the real-time query requests; using depth-first traversal encoding, traversing from the root node of the abstract syntax tree to obtain the nesting level and dependency relationship of the real-time query requests, as the syntax tree structure; obtaining a preset operator database, wherein the operator database includes multiple operators and their respective identifier codes; based on the operator database, constructing an operator embedding matrix, wherein each row of the operator embedding matrix corresponds to the embedding vector of an operator; based on the operator embedding matrix, mapping the operators of the real-time query requests to a vector sequence, as the operator sequence; obtaining historical resource consumption information of multiple query requests of the same category as the real-time query requests, wherein the resource consumption information includes CPU execution time, memory usage, and input / output read / write rate; calculating the mean and variance of the historical resource consumption information of multiple query requests of the same category as the real-time query requests, as historical resource consumption statistics; and obtaining the query statement scheduling frequency and system average load within a preset time window, as scheduling and load statistics within the preset time window.

[0059] Optionally, firstly, the real-time query request is parsed, and an Abstract Syntax Tree (AST) corresponding to the real-time query request is constructed. In this stage, the SQL statement is converted into a tree structure, where each node represents a component of the statement, such as fields, table names, join conditions, etc., and edges express the logical relationships between the components. By constructing the AST, the structure of the SQL statement and its potential resource consumption points can be intuitively displayed. Using depth-first traversal encoding, the traversal starts from the root node of the AST to obtain the nesting level and dependencies of the real-time query request, which serves as the syntax tree structure.

[0060] Secondly, a pre-defined operator database is obtained, which includes multiple operators and their corresponding identifiers. Based on this database, an operator embedding matrix is ​​constructed, with each row corresponding to the embedding vector of an operator. This matrix is ​​a predefined mapping table that converts operators in the SQL execution plan into their mathematical representations, i.e., dense vectors. The operators of the real-time query request are mapped to a vector sequence, serving as the operator sequence. By searching the operator embedding matrix, each operator in the execution plan is transformed into a fixed-length vector. These vectors are arranged in the order of operation execution to form a sequence, serving as the operator sequence and providing a semantic description of the execution path for the model.

[0061] Next, historical resource consumption information for multiple query requests of the same category as the real-time query request is obtained from the historical query logs of the target database. This includes CPU execution time, memory usage, and I / O read / write rates. The mean and variance of this historical resource consumption information are then used as historical resource consumption statistics. The statistical mean and variance reflect the basic level of resource consumption and reveal the range of fluctuations in resource consumption.

[0062] Finally, the query statement scheduling frequency and system average load within the preset time window are obtained as scheduling and load statistics for that time window. This statistical information reflects the current operating status of the database and query activity, helping the model to assess the degree of resource contention faced when executing SQL statements at a specific point in time.

[0063] As an optional embodiment, the method further includes: when the prediction time of the target resource prediction model exceeds a preset time threshold, obtaining the average historical resource consumption information of historical query requests that match the real-time query request in the target database; calculating the prediction deviation degree of the target resource prediction model based on the average historical resource consumption information, the resource consumption prediction result, and the prediction time; and determining that the target resource prediction model has experienced performance degradation when the prediction deviation degree exceeds a preset safety threshold.

[0064] Optionally, to achieve non-intrusive and low-risk resource calls to the database main thread during model inference, this optional embodiment introduces a resource isolation execution mechanism. Each database query request is intercepted via a hook function, triggering a resource prediction function before entering the optimization path selection logic, and scheduling it to a dedicated background process for execution. This background process is managed by a built-in scheduler, registered to a lightweight thread pool during initialization, and loads the inference engine asynchronously to avoid blocking the main scheduling path.

[0065] Specifically, to ensure that the process does not cause resource contention for other system services, a Linux CGroup mechanism can be used to impose a hard resource isolation policy on the child process. The CPU core usage is limited to no more than 10%, and the maximum memory allocation threshold is set to 1GB. All resource control parameters are dynamically injected through preset variables in the database startup configuration file. Simultaneously, to control call latency, the prediction function call cycle is limited to a maximum of 50 milliseconds, and precise monitoring is achieved through clock cycle counting. Once an inference response timeout occurs, a fault tolerance strategy is immediately triggered, using the average historical resource consumption information from the target database as a prediction compensation item, and writing it to the exception log for backtracking analysis. In this optional embodiment, a cost-performance ratio control function is introduced to calculate the prediction deviation of the target resource prediction model, defined as follows:

[0066]

[0067] in The error cost function representing the difference between predicted and historical values ​​is expressed using the weighted L2 norm. This is information on average historical resource consumption. The time consumed by the target resource prediction model. This indicates the degree of prediction deviation per unit time. If it exceeds the safety threshold, it is determined that the target resource prediction model has experienced performance degradation.

[0068] As an optional embodiment, the method further includes: recording the actual resource consumption results of multiple query requests and the predicted resource consumption results of multiple query requests within a preset time period; calculating the loss function value of the target resource prediction model based on the actual resource consumption results and the predicted resource consumption results; adjusting the parameters of the target resource prediction model based on the loss function value to obtain an updated target resource prediction model; and applying the updated target resource prediction model to the target database when the prediction accuracy of the updated target resource prediction model reaches a preset accuracy threshold and the prediction time of the updated target resource prediction model is less than a preset time threshold.

[0069] Optionally, this optional embodiment also includes a dynamic feedback closed-loop mechanism to maintain the predictive accuracy and adaptability of the model during long-term operation. Figure 5 This is a flowchart of a system dynamic feedback closed-loop mechanism provided by an optional embodiment of the present invention. For example... Figure 5As shown, firstly, at the end of each natural day (preset time period), the database environment instance supporting runtime extensions automatically schedules the resource monitoring module to write the SQL queries generated that day and their actual execution resource consumption records into an intermediate buffer, including syntax tree encoding, execution plan operation sequence, prediction results, and actual CPU / memory / IO usage. After the intermediate buffer data is collected, the data is compressed and uploaded to the external training server in incremental mode, where the resource consumption prediction results can be obtained. Secondly, after receiving the data, the external server calculates the loss function value of the target resource prediction model. The loss function measures the difference between the prediction result and the actual result. In this optional embodiment, the weighted mean squared error (MSE) norm is used for calculation. To control model complexity, a regularized stability loss function is introduced, defined as follows:

[0070]

[0071] in, The main loss term representing the difference between the predicted results and the actual consumption values ​​is expressed using the weighted MSE norm. and These represent the weights of the old and new models, respectively. The regularization factor is used to balance the trade-off between accuracy improvement and model stability, ensuring that the updated model does not experience structural oscillations. Utilizing backpropagation and gradient descent, the model parameters are adjusted inversely based on the calculated loss function value to minimize prediction error, resulting in the updated target resource prediction model. Finally, after obtaining the updated target resource prediction model, the version controller generates a unique version number based on the model identifier and signature value, comparing it with the currently running version in the database. If the updated model meets a preset accuracy threshold and its prediction time is less than a preset time threshold, the hot-replacement subsystem loads the new model into the database shared memory using a lock-free mechanism, replacing the original inference engine function pointer. This replacement process is hot-replacement and can be completed in a non-blocking context, ensuring uninterrupted query service. During this process, a dual-version isolation method is used to retain one query cycle of the old model to handle rollback strategies. After the updated target resource prediction model is applied, its version identifier is broadcast to all computing nodes through the metadata system, ensuring consistency of inference logic in the cluster environment.

[0072] As an optional embodiment, Figure 6 This is an architecture diagram of a resource consumption prediction system for query requests provided according to an optional embodiment of the present invention. Figure 6As shown, the system is a loop system consisting of five core components, designed to predict the resource consumption of query requests. First, the external asynchronous training module operates independently outside the database system. It is responsible for forming a time-series training dataset from historical SQL query logs, and using a two-layer LSTM structure model to model the syntax tree structure features of SQL queries, the sequence of execution plan operators, the historical average resource consumption, and time window statistics. The training process is accelerated by a distributed GPU cluster, producing a full resource prediction model.

[0073] Secondly, the fully trained resource prediction model is compressed using model distillation to obtain the target resource prediction model, i.e., the lightweight model. The target resource prediction model is then encapsulated as a C language extension module, loaded into the database process space via shared memory, and registered as a built-in function.

[0074] Furthermore, the target resource prediction model operates using a resource isolation execution mechanism to ensure its intrusion into the main database process. Specifically, when a new SQL query is received, a dedicated background process is scheduled to invoke the prediction function. This process is limited by CGroup resources, with CPU core utilization controlled below 10% and memory limit set to 1GB to prevent negative impacts on database performance. If the prediction takes more than 50 milliseconds, the system will automatically use the cached historical average resource consumption as the prediction result and record the timeout event for subsequent analysis and optimization.

[0075] Finally, the system employs a dynamic feedback closed-loop mechanism to ensure the long-term adaptability and accuracy of the prediction model. At fixed time intervals, the system automatically synchronizes the actual resource consumption data of newly added queries to the external training server, triggering an incremental model update process. Through a version management mechanism, the old and new models are hot-swapped to ensure the continuity of database services. Simultaneously, the system autonomously optimizes itself through the dynamic feedback closed-loop mechanism to adapt to evolving query patterns and load changes, maintaining a high level of performance in resource consumption prediction.

[0076] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.

[0077] Through the above description of the embodiments, those skilled in the art can clearly understand that the resource consumption prediction method for query requests according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0078] According to embodiments of the present invention, an apparatus for implementing the resource consumption prediction method for the above-described query request is also provided. Figure 7 This is a structural block diagram of a resource consumption prediction device for query requests provided according to an embodiment of the present invention, such as... Figure 7 As shown, the device includes an acquisition module 71 and a prediction module 72. The device will be described below.

[0079] The acquisition module 71 is used to acquire the resource consumption characteristics of real-time query requests used to query the target database. The language of the real-time query request is Structured Query Language, and the resource consumption characteristics include syntax tree structure, operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window.

[0080] The prediction module 72, connected to the acquisition module 71, is used to input resource consumption characteristics into the target resource prediction model to obtain the target resource consumption prediction result of the real-time query request. The target resource prediction model is a compressed two-layer long short-term memory network model. The target resource consumption prediction result includes the predicted CPU occupancy ratio, the predicted memory usage threshold, and the ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

[0081] It should be noted that the acquisition module 71 and prediction module 72 mentioned above correspond to steps S201 to S202 in the embodiments. Multiple modules implement the same instances and application scenarios as their corresponding steps, but are not limited to the content disclosed in the above embodiments. It should also be noted that the above modules, as part of the device, can run on the computer terminal 10 provided in the embodiments.

[0082] Embodiments of the present invention may provide a computer device. Optionally, in this embodiment, the computer device may be located in at least one of a plurality of network devices in a computer network. The computer device includes a memory and a processor.

[0083] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the query request resource consumption prediction method and apparatus in this embodiment of the invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby realizing the aforementioned query request resource consumption prediction method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to a computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0084] The processor can invoke information and applications stored in memory via a transmission device to perform the following steps: acquiring resource consumption characteristics of a real-time query request for querying a target database, wherein the language of the real-time query request is a structured query language, and the resource consumption characteristics include a syntax tree structure, operator sequences, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window; inputting the resource consumption characteristics into a target resource prediction model to obtain the target resource consumption prediction result for the real-time query request, wherein the target resource prediction model is a compressed two-layer long short-term memory network model, and the target resource consumption prediction result includes the predicted CPU occupancy ratio, the predicted memory usage threshold, and the ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

[0085] Optionally, the processor may also execute program code with the following steps: The steps for determining the target resource prediction model are as follows: Constructing an initial resource prediction model, wherein the initial resource prediction model is a two-layer long short-term memory network structure; obtaining historical query logs of the target database; constructing a time-series training dataset based on the historical query logs, wherein the time-series training dataset includes resource consumption features corresponding to multiple historical query requests; training the initial resource prediction model based on the time-series training dataset until the model converges to obtain a full resource prediction model; compressing the full resource prediction model to obtain the target resource prediction model.

[0086] Optionally, the processor may also execute program code for the following steps: compressing the full resource prediction model to obtain a target resource prediction model, including: determining the target hidden unit in the full resource prediction model, wherein the target hidden unit is a hidden unit whose contribution to the prediction output is less than a preset threshold; removing the target hidden unit from the full resource prediction model to obtain a first resource prediction model; quantizing and compressing the weights of multiple levels in the first resource prediction model to obtain a second resource prediction model; and fixing the calculation path of the second resource prediction model to static to obtain the target resource prediction model.

[0087] Optionally, the processor may also execute program code with the following steps: obtaining resource consumption characteristics of real-time query requests in the target database, including: parsing the real-time query requests and constructing an abstract syntax tree corresponding to the real-time query requests; using depth-first traversal encoding, traversing from the root node of the abstract syntax tree to obtain the nesting level and dependency relationship of the real-time query requests as the syntax tree structure; obtaining a preset operator database, wherein the operator database includes multiple operators and their respective identifiers; constructing an operator embedding matrix based on the operator database, wherein each row of the operator embedding matrix corresponds to the embedding vector of an operator; mapping the operators of the real-time query requests to a vector sequence based on the operator embedding matrix as the operator sequence; obtaining historical resource consumption information of multiple query requests of the same category as the real-time query requests, wherein the resource consumption information includes CPU execution time, memory usage, and input / output read / write rate; calculating the mean and variance of the historical resource consumption information of multiple query requests of the same category as the real-time query requests as historical resource consumption statistics; and obtaining the query statement scheduling frequency and system average load within a preset time window as scheduling and load statistics within the preset time window.

[0088] Optionally, the processor may also execute program code that performs the following steps: when the prediction time of the target resource prediction model exceeds a preset time threshold, obtain the average historical resource consumption information of historical query requests that match the real-time query request in the target database; calculate the prediction deviation of the target resource prediction model based on the average historical resource consumption information, the resource consumption prediction result, and the prediction time; and determine that the target resource prediction model has experienced performance degradation when the prediction deviation exceeds a preset safety threshold.

[0089] Optionally, the processor may also execute program code that performs the following steps: within a preset time period, records the actual resource consumption results of multiple query requests and the predicted resource consumption results of multiple query requests; calculates the loss function value of the target resource prediction model based on the actual resource consumption results and the predicted resource consumption results; adjusts the parameters of the target resource prediction model based on the loss function value to obtain an updated target resource prediction model; and applies the updated target resource prediction model to the target database when the prediction accuracy of the updated target resource prediction model reaches a preset accuracy threshold and the prediction time of the updated target resource prediction model is less than a preset time threshold.

[0090] This invention provides a scheme for predicting the resource consumption of query requests. By acquiring the resource consumption characteristics of real-time query requests used to query a target database, where the language of the real-time query request is a structured query language, the resource consumption characteristics include the syntax tree structure, operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window; the resource consumption characteristics are input into a target resource prediction model to obtain the target resource consumption prediction result for the real-time query request, where the target resource prediction model is a compressed two-layer long short-term memory network model, and the target resource consumption prediction result includes the predicted CPU occupancy ratio, the predicted memory usage threshold, and the ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold. This achieves the goal of accurately predicting the real-time query resource requirements of the database, improving the system's adaptability, and thus solving the technical problems of inaccurate prediction of resource consumption for structured statements, untimely response, and distorted cost models in traditional database query optimization processes.

[0091] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a non-volatile storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0092] Embodiments of the present invention also provide a non-volatile storage medium. Optionally, in this embodiment, the aforementioned non-volatile storage medium can be used to store the program code executed by the resource consumption prediction method for query requests provided in the above embodiments.

[0093] Optionally, in this embodiment, the non-volatile storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.

[0094] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: obtaining resource consumption characteristics of a real-time query request for querying a target database, wherein the language of the real-time query request is a structured query language, and the resource consumption characteristics include a syntax tree structure, an operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window; inputting the resource consumption characteristics into a target resource prediction model to obtain the target resource consumption prediction result of the real-time query request, wherein the target resource prediction model is a compressed two-layer long short-term memory network model, and the target resource consumption prediction result includes the predicted CPU occupancy ratio, the predicted memory usage threshold, and the ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

[0095] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: The steps for determining the target resource prediction model are as follows: Constructing an initial resource prediction model, wherein the initial resource prediction model is a two-layer long short-term memory network structure; obtaining historical query logs of the target database; constructing a time-series training dataset based on the historical query logs, wherein the time-series training dataset includes resource consumption features corresponding to multiple historical query requests; training the initial resource prediction model based on the time-series training dataset until the model converges to obtain a full resource prediction model; compressing the full resource prediction model to obtain the target resource prediction model.

[0096] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: compressing the full resource prediction model to obtain a target resource prediction model, including: determining the target hidden unit in the full resource prediction model, wherein the target hidden unit is a hidden unit whose contribution to the prediction output is less than a preset threshold; removing the target hidden unit from the full resource prediction model to obtain a first resource prediction model; quantizing and compressing the weights of multiple levels in the first resource prediction model to obtain a second resource prediction model; and fixing the calculation path of the second resource prediction model to static to obtain the target resource prediction model.

[0097] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: obtaining resource consumption characteristics of real-time query requests in the target database, including: parsing the real-time query requests and constructing an abstract syntax tree corresponding to the real-time query requests; using depth-first traversal encoding, traversing from the root node of the abstract syntax tree to obtain the nesting level and dependency relationship of the real-time query requests as the syntax tree structure; obtaining a preset operator database, wherein the operator database includes multiple operators and their respective identifiers; constructing an operator embedding matrix based on the operator database, wherein each row of the operator embedding matrix corresponds to the embedding vector of an operator; mapping the operators of the real-time query requests to a vector sequence based on the operator embedding matrix as the operator sequence; obtaining historical resource consumption information of multiple query requests of the same category as the real-time query requests, wherein the resource consumption information includes CPU execution time, memory usage, and input / output read / write rate; calculating the mean and variance of the historical resource consumption information of multiple query requests of the same category as the real-time query requests as historical resource consumption statistics; and obtaining the query statement scheduling frequency and system average load within a preset time window as scheduling and load statistics within the preset time window.

[0098] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: when the prediction time of the target resource prediction model exceeds a preset time threshold, obtaining the average historical resource consumption information of historical query requests that match the real-time query request in the target database; calculating the prediction deviation degree of the target resource prediction model based on the average historical resource consumption information, the resource consumption prediction result, and the prediction time; and determining that the target resource prediction model has experienced performance degradation when the prediction deviation degree exceeds a preset safety threshold.

[0099] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: within a preset time period, recording the actual resource consumption results of multiple query requests and the predicted resource consumption results of multiple query requests; calculating the loss function value of the target resource prediction model based on the actual resource consumption results and the predicted resource consumption results; adjusting the parameters of the target resource prediction model based on the loss function value to obtain an updated target resource prediction model; and applying the updated target resource prediction model to the target database when the prediction accuracy of the updated target resource prediction model reaches a preset accuracy threshold and the prediction time of the updated target resource prediction model is less than a preset time threshold.

[0100] Embodiments of the present invention also provide a computer program product, including a computer program. Optionally, in this embodiment, when the computer program is executed by a processor, it can: acquire resource consumption characteristics of a real-time query request for querying a target database, wherein the language of the real-time query request is a structured query language, and the resource consumption characteristics include a syntax tree structure, an operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window; input the resource consumption characteristics into a target resource prediction model to obtain a target resource consumption prediction result for the real-time query request, wherein the target resource prediction model is a compressed two-layer long short-term memory network model, and the target resource consumption prediction result includes a central processing unit (CPU) predicted occupancy ratio, a memory usage prediction threshold, and a ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

[0101] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0102] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0103] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.

[0104] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0105] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0106] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a non-volatile storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0107] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for predicting resource consumption of query requests, characterized in that, include: Obtain the resource consumption characteristics of real-time query requests used to query the target database, wherein the language of the real-time query request is a structured query language, and the resource consumption characteristics include syntax tree structure, operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window; The resource consumption characteristics are input into the target resource prediction model to obtain the target resource consumption prediction result of the real-time query request. The target resource prediction model is a compressed two-layer long short-term memory network model. The target resource consumption prediction result includes the predicted CPU occupancy ratio, the predicted memory usage threshold, and the ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

2. The method according to claim 1, characterized in that, The steps for determining the target resource prediction model are as follows: Construct an initial resource prediction model, wherein the initial resource prediction model is a two-layer long short-term memory network structure; Obtain the historical query logs of the target database; Based on the historical query logs, a time-series training dataset is constructed, wherein the time-series training dataset includes resource consumption characteristics corresponding to multiple historical query requests; Based on the time-series training dataset, the initial resource prediction model is trained until the model converges to obtain the full resource prediction model. The full resource prediction model is compressed to obtain the target resource prediction model.

3. The method according to claim 2, characterized in that, The step of compressing the full resource prediction model to obtain the target resource prediction model includes: Identify the target hidden unit in the full resource prediction model, wherein the target hidden unit is a hidden unit whose contribution to the prediction output is less than a preset threshold; Remove the target hidden unit from the full resource prediction model to obtain the first resource prediction model; The weights of multiple levels in the first resource prediction model are quantized and compressed to obtain the second resource prediction model. The calculation path of the second resource prediction model is fixed as static to obtain the target resource prediction model.

4. The method according to claim 1, characterized in that, The process of obtaining the resource consumption characteristics of real-time query requests in the target database includes: Parse the real-time query request and construct the abstract syntax tree corresponding to the real-time query request; Using depth-first traversal encoding, starting from the root node of the abstract syntax tree, the nesting level and dependency relationship of the real-time query request are obtained, which serve as the syntax tree structure. Obtain a preset operator database, wherein the operator database includes multiple operators and the identifier codes corresponding to each of the multiple operators; Based on the operator database, an operator embedding matrix is ​​constructed, wherein each row of the operator embedding matrix corresponds to the embedding vector of an operator; Based on the operator embedding matrix, the operators of the real-time query request are mapped to a vector sequence, which serves as the operator sequence; Obtain historical resource consumption information for multiple query requests of the same category as the real-time query request, wherein the resource consumption information includes central processing unit execution time, memory usage, and input / output read / write rate; Calculate the mean and variance of the historical resource consumption information of the multiple query requests that are of the same category as the real-time query request, and use it as the historical resource consumption statistics. The query frequency and average system load within the preset time window are obtained as scheduling and load statistics within the preset time window.

5. The method according to claim 1, characterized in that, Also includes: If the prediction time of the target resource prediction model exceeds a preset time threshold, obtain the average historical resource consumption information of historical query requests that match the real-time query request in the target database; Based on the average historical resource consumption information, the resource consumption prediction results, and the prediction time, the prediction deviation of the target resource prediction model is calculated. If the prediction deviation exceeds a preset safety threshold, it is determined that the target resource prediction model has experienced performance degradation.

6. The method according to any one of claims 1 to 5, characterized in that, Also includes: Within a preset time period, record the actual resource consumption results of each of the multiple query requests and the predicted resource consumption results of each of the multiple query requests. Based on the actual resource consumption results and the predicted resource consumption results, calculate the loss function value of the target resource prediction model; Based on the loss function value, the parameters of the target resource prediction model are adjusted to obtain an updated target resource prediction model. If the prediction accuracy of the updated target resource prediction model reaches a preset accuracy threshold and the prediction time of the updated target resource prediction model is less than a preset time threshold, the updated target resource prediction model is applied to the target database.

7. A resource consumption prediction device for query requests, characterized in that, include: The acquisition module is used to acquire the resource consumption characteristics of real-time query requests for querying the target database. The language of the real-time query request is a structured query language, and the resource consumption characteristics include a syntax tree structure, an operator sequence, historical resource consumption statistics of query requests of the same category as the real-time query request, and scheduling and load statistics within a preset time window. The prediction module is used to input the resource consumption characteristics into the target resource prediction model to obtain the target resource consumption prediction result of the real-time query request. The target resource prediction model is a compressed two-layer long short-term memory network model. The target resource consumption prediction result includes the predicted CPU occupancy ratio, the predicted memory usage threshold, and the ratio of the predicted input / output bandwidth value to the input / output bandwidth threshold.

8. A non-volatile storage medium, characterized in that, The non-volatile storage medium includes a stored program, wherein, when the program is executed, it controls the device where the non-volatile storage medium is located to execute the resource consumption prediction method for the query request as described in any one of claims 1 to 6.

9. A computer device, characterized in that, include: Memory and processor The memory stores computer programs; The processor is configured to execute a computer program stored in the memory, wherein when the computer program is executed, the processor performs the resource consumption prediction method for the query request according to any one of claims 1 to 6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the resource consumption prediction method for the query request as described in any one of claims 1 to 6.