Cardinality estimation method and device and storage medium
By combining the deep learning model and the forest structure, a hybrid cardinality estimation model is constructed, and an update mechanism is introduced into the model, which solves the accuracy and dynamic problems of cardinality estimation in the existing technology, and achieves accurate estimation and timeliness of different cardinality queries. sex.
Patent Information
- Application Number
- CN202410811527.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-06-21
AI Technical Summary
Existing cardinality estimation models have deficiencies in evaluation indicators, handling low-cardinality queries, and database dynamics, resulting in the inability to accurately estimate cardinality.
Combining the deep learning model and forest structure, by encoding the query statement and using single attribute cardinality to estimate the upper bound loss function and custom loss function, build a hybrid model to improve the estimation accuracy, and introduce an update mechanism in the deep learning network and forest structure to Adapt to dynamic changes in the database.
It achieves accurate estimation of different cardinality queries, improves the accuracy of low-cardinality queries and the prediction ability of high-cardinality queries, and ensures the timeliness and accuracy of the cardinality estimation results.
Smart Images

Figure CN118656394A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cardinality estimation, and in particular to a cardinality estimation method, device and storage medium. Background Art
[0002] Cardinality estimation is an important part of database query optimization. It helps the database query optimizer select the best query execution plan by estimating the number of query results (cardinality value) in advance, and plays an important role in improving database query performance. Traditional cardinality estimation can be divided into two categories: histogram-based methods, which obtain the result by multiplying the attribute proportion values; sampling-based methods, which infer the overall cardinality from a small sample. With the development of deep learning technology, emerging cardinality estimation methods are divided into two categories: data-based and query-based. The former decomposes and predicts the cardinality probability value through an autoregressive model, while the latter regards the task as a regression problem and uses encoding and neural networks to learn and predict query statements. Histogram-based cardinality estimation ignores the correlation between attributes, resulting in large errors when processing highly correlated attributes. Sampling-based methods are affected by the quality of the sampling algorithm and are difficult to adapt to the frequent changes in database data. Although the learning-based model has better performance, it still has some shortcomings.
[0003] Existing cardinality estimation models have deficiencies in evaluation indicators, processing low-cardinality queries and database dynamics: the Q error evaluation indicator causes the model to be biased towards training low-cardinality queries; the learning model is easily misled by a single high-cardinality condition, affecting the accuracy of low-cardinality queries; the static training model is difficult to adapt to the dynamic updates of the database and requires an effective update mechanism to maintain performance; these deficiencies make it impossible to accurately estimate the cardinality. Summary of the invention
[0004] The present application provides a cardinality method, device and storage medium to solve the problem that the cardinality cannot be accurately estimated in the prior art.
[0005] In a first aspect, the present application provides a cardinality estimation method, comprising:
[0006] Get the query statement to be predicted;
[0007] Encoding the query statement to be predicted and inputting it into a deep learning model to obtain a cardinality estimation result, wherein the deep learning model is obtained by training the encoded historical query statements with an initial deep learning model;
[0008] If the cardinality estimation result is greater than a preset threshold, the cardinality estimation result is used as the final cardinality estimation result; otherwise, the accurate cardinality output by the forest structure is used as the final cardinality estimation result; wherein the forest structure is obtained by constructing a multi-branch tree based on database record data.
[0009] The present application combines a learning model with an accurate solution structure to form a hybrid model for cardinality estimation. Relying on the hybrid model, a deep learning model is used to estimate high-cardinality query statements, and a forest structure is used to accurately solve low-cardinality query statements. Compared with the problem of being unable to accurately estimate cardinality in the prior art, the hybrid model of the present application can accurately estimate queries of different cardinality.
[0010] As a preferred embodiment of the first aspect, the deep learning model is obtained by training the encoded historical query statements by the initial deep learning model, specifically:
[0011] Obtain the encoded historical query sentence to obtain the historical query vector;
[0012] Build an initial deep learning model using two consecutive fully connected layers and a sigmoid function;
[0013] The historical query vector is obtained and trained through an initial deep learning model, and the initial deep learning model is optimized using a single attribute cardinality estimation upper bound loss function during the training process to obtain a deep learning model.
[0014] As a preferred embodiment of the first aspect, the optimization using the single attribute cardinality estimation upper bound loss function during the training process is specifically as follows:
[0015] The expression of the upper bound loss function for single attribute cardinality estimation is:
[0016]
[0017] Where P represents the predicted value, L represents the label, and Bnd represents the upper bound of the single attribute cardinality;
[0018] During the training process, the predicted value of the cardinality estimation is continuously monitored to see whether it is close to or exceeds the preset upper limit of the single attribute cardinality;
[0019] When it is detected that the predicted value of the cardinality estimation exceeds or is expected to exceed the upper bound of the single attribute cardinality, the corresponding penalty is automatically applied through the single attribute cardinality estimation upper bound loss function.
[0020] In this preferred embodiment, the present application utilizes two consecutive fully connected layers and a sigmoid function to construct an initial deep learning model, thereby enhancing the model's ability to learn complex query statements; the single attribute cardinality estimation upper bound loss function is used to optimize the initial deep learning model training process. The single attribute cardinality upper bound can be used to limit the prediction space of the learning model, thereby improving the accuracy of the deep learning model.
[0021] As a preferred embodiment of the first aspect, the forest structure is obtained by constructing a multi-branch tree according to the database record data, specifically:
[0022] Get database record data;
[0023] Analyze the attributes of the database record data and identify the quantity of each attribute;
[0024] Construct multiple multi-branch trees according to the number of each attribute value, and each tree represents the value range of an attribute;
[0025] Combining all constructed multi-branch trees results in a forest structure.
[0026] In this preferred embodiment, the present application constructs a multi-tree-based forest structure, which can effectively process different attribute constraints in database record data and provide accurate cardinality estimation for the query statement to be predicted.
[0027] As a preferred embodiment of the first aspect, the preset threshold is adaptively calculated by using a custom loss function to balance the effect and overhead of a set of historical query statements on the two components of the deep learning model and the forest structure;
[0028] The formula for the custom loss function is:
[0029]
[0030] The loss function Cost(η) consists of two parts: t(η) and mqe(η); t(η) represents the time overhead of the forest structure; mqe(η) represents the average Q error value of the deep learning model and the forest structure in the historical data;
[0031] In this preferred embodiment, the present application balances the rapid response of the deep learning model and the accuracy of the forest structure by adaptively determining the threshold through the loss function, so that the hybrid model can intelligently select the most appropriate estimation strategy based on historical data.
[0032] As a preferred embodiment of the first aspect, the use of the forest structure to output an accurate cardinality as the final cardinality estimation result is specifically as follows:
[0033] Obtain the encoded query sentence to be predicted to obtain a query vector to be predicted;
[0034] Identifying the attributes specified in the query vector to be predicted and the corresponding constraints;
[0035] Use binary search method to find the range of child nodes that meet the specified attributes and corresponding constraints in the multi-tree forest structure node;
[0036] Recursively search in the multi-tree forest structure nodes until all leaf nodes or terminal nodes that meet the query conditions are found;
[0037] The statistical variables in the leaf nodes or terminal nodes that meet the conditions are accumulated as the final accurate cardinality, and the accurate cardinality is the final cardinality estimation result.
[0038] In this preferred embodiment, the present application utilizes binary search and recursive search techniques to improve the efficiency of searching for nodes that meet the conditions in the forest structure, thereby ensuring the rapid output of accurate cardinality.
[0039] As a preferred embodiment of the first aspect, it also includes: when the data recorded in the database is updated, adding an update structure to the initial deep learning model and the forest structure;
[0040] The initial deep learning network model updates the single attribute cardinality upper bound, sample vectors, and labels before training;
[0041] The newly added database record data is inserted into the forest structure one by one, and the statistical variables of each node of the multi-branch tree in the forest structure are updated in turn before training.
[0042] In this preferred embodiment, the present application introduces an update mechanism in the deep learning network and the forest structure. This update mechanism can adapt to the dynamic changes of the database and maintain the timeliness and accuracy of the cardinality estimation results.
[0043] As a preferred embodiment of the first aspect, the query statement to be predicted is encoded and input into the deep learning model to obtain the cardinality estimation result, specifically:
[0044] Encode the query to be predicted to form an input vector, which consists of three parts: attribute vector, predicate vector and sample vector;
[0045] The attribute vector uses one-hot encoding to indicate the attribute position;
[0046] The predicate vector is used to encode the predicate type and restrict the space;
[0047] The sample vector is a bitmap used to indicate whether the sample data meets the query statement;
[0048] The deep learning model obtains the encoded input vector;
[0049] The cardinality estimation value is predicted through the deep learning model to obtain the cardinality estimation result.
[0050] In this preferred embodiment, the present application encodes the query statement into a vector containing attributes, predicates and sample information. The vectors of different information attributes improve the model's ability to capture the features of the query statement, provide richer input information for the deep learning model, and thus improve the accuracy of cardinality prediction.
[0051] In a second aspect, the present application provides a cardinality estimation device. The cardinality estimation device includes an acquisition module, a prediction module, and a comparison module;
[0052] The module is used to obtain the query statement to be predicted;
[0053] The prediction module is used to encode the query statement to be predicted and input it into the deep learning model to obtain a cardinality estimation result, wherein the deep learning model is obtained by training the encoded historical query statement by the initial deep learning model;
[0054] The comparison module is used to compare the cardinality estimation result with a preset threshold. If the cardinality estimation result is greater than the preset threshold, the cardinality estimation result is used as the final cardinality estimation result; otherwise, the accurate cardinality output by the forest structure is used as the final cardinality estimation result; wherein the forest structure is obtained by constructing a multi-branch tree based on database record data.
[0055] This device uses three modules to divide the work and coordinate work to better discover and deal with problems that arise in the cardinality estimation device. The device can comprehensively utilize historical and real-time data, quickly generate prediction results through the collaborative work of deep learning networks and forest structures, and make intelligent decisions based on dynamically determined thresholds to ensure the optimality of the output results.
[0056] As a preferred embodiment of the second aspect, the deep learning model is obtained by training the encoded historical query statements by the initial deep learning model, specifically:
[0057] Obtain the encoded historical query sentence to obtain the historical query vector;
[0058] Build an initial deep learning model using two consecutive fully connected layers and a sigmoid function;
[0059] The historical query vector is obtained and trained through an initial deep learning model, and the initial deep learning model is optimized using a single attribute cardinality estimation upper bound loss function during the training process to obtain a deep learning model.
[0060] As a preferred embodiment of the second aspect, the optimization using the single attribute cardinality estimation upper bound loss function during the training process is specifically as follows:
[0061] The expression of the upper bound loss function for single attribute cardinality estimation is:
[0062]
[0063] Where P represents the predicted value, L represents the label, and Bnd represents the upper bound of the single attribute cardinality;
[0064] During the training process, the predicted value of the cardinality estimation is continuously monitored to see whether it is close to or exceeds the preset upper limit of the single attribute cardinality;
[0065] When it is detected that the predicted value of the cardinality estimation exceeds or is expected to exceed the upper bound of the single attribute cardinality, the corresponding penalty is automatically applied through the single attribute cardinality estimation upper bound loss function.
[0066] In this preferred embodiment, the present application utilizes two consecutive fully connected layers and a sigmoid function to construct an initial deep learning model, thereby enhancing the model's ability to learn complex query statements; the single attribute cardinality estimation upper bound loss function is used to optimize the initial deep learning model training process. The single attribute cardinality upper bound can be used to limit the prediction space of the learning model, thereby improving the accuracy of the deep learning model.
[0067] As a preferred embodiment of the second aspect, the forest structure is obtained by constructing a multi-branch tree based on the database record data, specifically:
[0068] Get database record data;
[0069] Analyze the attributes of the database record data and identify the quantity of each attribute;
[0070] Construct multiple multi-branch trees according to the number of each attribute value, and each tree represents the value range of an attribute;
[0071] Combining all constructed multi-branch trees results in a forest structure.
[0072] In this preferred embodiment, the present application constructs a multi-tree-based forest structure, which can effectively process different attribute constraints in database record data and provide accurate cardinality estimation for the query statement to be predicted.
[0073] As a preferred embodiment of the second aspect, the preset threshold is adaptively calculated by using a custom loss function to balance the effect and overhead of a set of historical query statements on the two components of the deep learning model and the forest structure;
[0074] The formula for the custom loss function is:
[0075]
[0076] The loss function Cost(η) consists of two parts: t(η) and mqe(η); t(η) represents the time overhead of the forest structure; mqe(η) represents the average Q error value of the deep learning model and the forest structure in the historical data;
[0077] In this preferred embodiment, the present application balances the rapid response of the deep learning model and the accuracy of the forest structure by adaptively determining the threshold through the loss function, so that the hybrid model can intelligently select the most appropriate estimation strategy based on historical data.
[0078] As a preferred embodiment of the second aspect, the use of the forest structure to output an accurate cardinality as the final cardinality estimation result is specifically as follows:
[0079] Obtain the encoded query sentence to be predicted to obtain a query vector to be predicted;
[0080] Identifying the attributes specified in the query vector to be predicted and the corresponding constraints;
[0081] Use binary search method to find the range of child nodes that meet the specified attributes and corresponding constraints in the multi-tree forest structure node;
[0082] Recursively search in the multi-tree forest structure nodes until all leaf nodes or terminal nodes that meet the query conditions are found;
[0083] The statistical variables in the leaf nodes or terminal nodes that meet the conditions are accumulated as the final accurate cardinality, and the accurate cardinality is the final cardinality estimation result.
[0084] In this preferred embodiment, the present application utilizes binary search and recursive search techniques to improve the efficiency of searching for nodes that meet the conditions in the forest structure, thereby ensuring the rapid output of accurate cardinality.
[0085] As a preferred embodiment of the second aspect, it also includes: when the data recorded in the database is updated, adding an update structure to the initial deep learning model and the forest structure;
[0086] The initial deep learning network model updates the single attribute cardinality upper bound, sample vectors, and labels before training;
[0087] The newly added database record data is inserted into the forest structure one by one, and the statistical variables of each node of the multi-branch tree in the forest structure are updated in turn before training.
[0088] In this preferred embodiment, the present application introduces an update mechanism in the deep learning network and the forest structure. This update mechanism can adapt to the dynamic changes of the database and maintain the timeliness and accuracy of the cardinality estimation results.
[0089] As a preferred embodiment of the second aspect, the query statement to be predicted is encoded and input into the deep learning model to obtain the cardinality estimation result, specifically:
[0090] Encode the query to be predicted to form an input vector, which consists of three parts: attribute vector, predicate vector and sample vector;
[0091] The attribute vector uses one-hot encoding to indicate the attribute position;
[0092] The predicate vector is used to encode the predicate type and restrict the space;
[0093] The sample vector is a bitmap used to indicate whether the sample data meets the query statement;
[0094] The deep learning model obtains the encoded input vector;
[0095] The cardinality estimation value is predicted through the deep learning model to obtain the cardinality estimation result.
[0096] In this preferred embodiment, the present application encodes the query statement into a vector containing attributes, predicates and sample information. The vectors of different information attributes improve the model's ability to capture the features of the query statement, provide richer input information for the deep learning model, and thus improve the accuracy of cardinality prediction.
[0097] In a third aspect, the present application provides a computer-readable storage medium, the computer-readable storage medium including a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to perform a cardinality estimation method as described above. Its beneficial effects are the same as those of the cardinality estimation method provided in the first aspect of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0098] Figure 1 : A flowchart of an embodiment of a cardinality estimation method provided in the present application;
[0099] Figure 2 : Schematic diagram of the initial deep learning model structure provided for this application;
[0100] Figure 3 : A schematic diagram of the structure of the forest structure building process for solving the accurate cardinality provided in this application;
[0101] Figure 4 : Schematic diagram of the input query sentence encoding vectorization structure provided in this application;
[0102] Figure 5 : A structural diagram of an embodiment of a cardinality estimation device provided by the present application; DETAILED DESCRIPTION
[0103] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0104] Embodiment 1
[0105] Please refer to Figure 1 , which is a cardinality estimation method provided in an embodiment of the present application.
[0106] In this embodiment, the process of the cardinality estimation method in this application is described in detail through steps S01-S03.
[0107] S01: Obtain the query statement to be predicted;
[0108] S02: Encode the query statement to be predicted and input it into the deep learning model to obtain a cardinality estimation result, wherein the deep learning model is obtained by training the encoded historical query statements with the initial deep learning model;
[0109] As a preferred embodiment of the first embodiment, the deep learning model is obtained by training the encoded historical query statements by the initial deep learning model, specifically:
[0110] Obtain the encoded historical query sentence to obtain the historical query vector;
[0111] Build an initial deep learning model using two consecutive fully connected layers and a sigmoid function;
[0112] The historical query vector is obtained and trained through an initial deep learning model, and the initial deep learning model is optimized using a single attribute cardinality estimation upper bound loss function during the training process to obtain a deep learning model.
[0113] The initial deep learning model is extended from MSCN. Generally speaking, the initial deep learning model of this application includes a fully connected layer and a sigmoid activation function, such as Figure 2 shown.
[0114] In the initial deep learning model training phase, this application sets the initial learning rate to 0.001, and reduces it by 20% every 5 epochs, for a total of 100 rounds. The Adam optimizer is used for the initial deep learning model training.
[0115] As a preferred embodiment of the first embodiment, the optimization is performed using a single attribute cardinality estimation upper bound loss function during the initial deep learning model training process, specifically:
[0116] The expression of the upper bound loss function for single attribute cardinality estimation is:
[0117]
[0118] Where P represents the predicted value, L represents the label, and Bnd represents the upper bound of the single attribute cardinality;
[0119] During the training process, the predicted value of the cardinality estimation is continuously monitored to see whether it is close to or exceeds the preset upper limit of the single attribute cardinality;
[0120] When it is detected that the predicted value of the cardinality estimation exceeds or is expected to exceed the upper bound of the single attribute cardinality, the corresponding penalty is automatically applied through the single attribute cardinality estimation upper bound loss function.
[0121] The definition of attribute cardinality upper-bound (ACUB) is: given a table T, which contains u records (tuples) and x attributes (attributes) θ1, θ2, ..., θx; given a query statement Q, the corresponding constraints on the x attributes are γ1, γ2, ..., γx, then the cardinality upper bound on attribute θi can be expressed as the proportion of the number of records in table T that satisfy the constraint γi:
[0122] BoundQ(θi)=cardyi(T) / u
[0123] Obviously, the cardinality of a query statement is the number of records in T that meet all the restrictions, that is:
[0124] cardQ(T)=cardy1y2...yx(T)
[0125] Thus, even in the best case, the cardinality of a query statement must be less than the minimum value in the single cardinality upper bound, that is:
[0126] BoundQ(T)=cardy1y2...yx(T) / u≤min(cardγi(T) / u)
[0127] In this way, the single attribute cardinality upper bound can be used to limit the prediction space of the learning model, thereby improving the accuracy of the model.
[0128] Calculation method: The upper bound of the cardinality of a single attribute can be quickly obtained through a histogram;
[0129] (1) Point predicate (=): In this case, since the histogram is the number of times each value appears on a certain attribute, it can be obtained by using the histogram for indexing;
[0130] (2) Range predicates (≥, ≤, []): For these situations, the concepts of more-than-or-equal-to histogram (MH) and less-than-or-equal-to histogram (LH) are introduced. MH / LH stores the number of records that are greater than / less than each value of an attribute. For example, given an attribute, MHT[vi] represents the number of records in table T whose attribute position is greater than or equal to value vi. In this way, the upper bound of the single attribute cardinality of the range predicate [vi,vj] can be quickly calculated according to the following formula:
[0131] Bound[vi,vj](T)=(MHA[vi]+LHA[vj]) / u-1
[0132] S03: If the cardinality estimation result is greater than a preset threshold, the cardinality estimation result is used as the final cardinality estimation result; otherwise, the accurate cardinality output by the forest structure is used as the final cardinality estimation result; wherein the forest structure is obtained by constructing a multi-branch tree based on the database record data.
[0133] As a preferred embodiment of the first embodiment, the preset threshold is adaptively calculated by using a custom loss function to balance the effect and cost of a set of historical query statements on the two components of the deep learning model and the forest structure;
[0134] The formula for the custom loss function is:
[0135]
[0136] The loss function Cost(η) consists of two parts: t(η) and mqe(η); t(η) represents the time overhead of the forest structure; mqe(η) represents the average Q error value of the deep learning model and the forest structure in the historical data;
[0137] The nonlinear least squares method and the sequential least squares algorithm are used to find the minimum point of the custom loss function, and the abscissa of the minimum point is used as the threshold.
[0138] As a preferred embodiment of the first embodiment, the forest structure is obtained by constructing a multi-branch tree according to the database record data, specifically:
[0139] Get database record data;
[0140] Analyze the attributes of the database record data and identify the quantity of each attribute;
[0141] Construct multiple multi-branch trees according to the number of each attribute value, and each tree represents the value range of an attribute;
[0142] Combining all constructed multi-branch trees results in a forest structure.
[0143] More specifically, the steps for constructing the forest structure are:
[0144] Input: n tuples with x attributes, attribute order in ascending order of the number of values appearing in each attribute;
[0145]
[0146]
[0147] That is, given a record (tuple) with x attributes, the values of each attribute are v1, v2, ..., vx. Sort these attributes in ascending order of the number of different values of each attribute to get the order of the attributes. The tree building process starts from the root node Nroot of the tree (line 21).
[0148] Determine whether the value v1 has been stored in a child node of Nroot (line 6). If so, add 1 to the statistical variable of the child node Nv1 (line 7); otherwise, add a new node Nv1 as a child node of Nroot and initialize its statistical variable to 1 (lines 8-10);
[0149] Next, enter the child node Nv1 (line 12), and then determine whether the second value v2 has been stored in a child node of Nv1 (line 6). If so, add 1 to the statistical variable of the child node Nv2 (line 7); otherwise, add a new node Nv2 as a child node of Nv1 and initialize its statistical variable to 1 (lines 8-10). Repeat this step until all the values of the record are stored in the tree structure (line 2). At this point, the first tree structure in the forest structure is completed;
[0150] Next, starting from order[2:], build the second tree according to the above steps for the x-1 attributes; starting from order[3:], build the third tree according to the above steps for the x-2 attributes. In this way, the final forest structure contains x tree structures.
[0151] Figure 3An example of building a forest structure is given in . First, the attributes are sorted in ascending order according to the number of different values in them. Because there is only one value in θ1z, two values in θ0, and three values in θ2, the attributes are sorted as [θ1,θ0,θ2]. Then according to the above tree building process, the first tree contains the attribute range [θ1,θ0,θ2], the second tree contains the range [θ0,θ2], and the third tree is [θ2]. For a specified query statement, you can determine which tree to use for the exact solution based on the appearance of its predicate. For example, if the query statement has the restriction condition 'whereθ0=a andθ2=b', then you should use Figure 3 The second tree is used to find the exact solution.
[0152] As a preferred embodiment of the first embodiment, the use of the forest structure to output the accurate cardinality as the final cardinality estimation result is specifically as follows:
[0153] Obtain the encoded query sentence to be predicted to obtain a query vector to be predicted;
[0154] Identifying the attributes specified in the query vector to be predicted and the corresponding constraints;
[0155] Use binary search method to find the range of child nodes that meet the specified attributes and corresponding constraints in the multi-tree forest structure node;
[0156] Recursively search in the multi-tree forest structure nodes until all leaf nodes or terminal nodes that meet the query conditions are found;
[0157] The statistical variables in the leaf nodes or terminal nodes that meet the conditions are accumulated as the final accurate cardinality, and the accurate cardinality is the final cardinality estimation result.
[0158] More specifically, the steps for the forest structure to find the exact solution to the query statement are:
[0159] Input: a query Q with x attributes, where Q[j][-1] represents the upper bound of the constraint on the j-th attribute, and Q[j][-2] represents the lower bound of the constraint on the j-th attribute; exact solution to the forest structure Forest; attribute order in ascending order of the number of values that appear on each attribute;
[0160]
[0161]
[0162] First, the tree in the forest structure is selected according to the attributes that appear in the query statement (lines 16-19). Starting from the root node of the tree, a binary search is used to find the start node and the last node in the child nodes that meet the restriction on the first attribute (lines 7 and 8). Then, for each of the child nodes, a binary search is continued for their child nodes according to the restriction on the second attribute to find the start node and the last node in the second layer of child nodes that meet the restriction on the second attribute (lines 9 and 10). This search process is iterated until the restriction is exhausted (line 3). Finally, the values of the statistical variables stored in all nodes that meet the conditions are accumulated as the final accurate solution (line 4).
[0163] As a preferred embodiment of the first embodiment, when the data recorded in the database is updated, an update structure is added to the initial deep learning model and the forest structure;
[0164] The initial deep learning network model updates the single-attribute cardinality upper bound, sample vector and label before training; note that only the single-attribute cardinality upper bound and sample vector information in the input vector will change as the data is updated. In this way, the update of the single-attribute cardinality upper bound can be achieved by first updating the single-dimension histogram, and then updating the single-attribute cardinality upper bound through the single-attribute histogram. Furthermore, the reservoir sampling algorithm is used for dynamic update of the sample vector, which can ensure that in the dynamic data stream, the probability of each data being selected as a sample is equal. For the labels of the training data, since the forest structure can obtain the accurate cardinality value of the query statement, it can be updated by creating a new forest structure for the updated data. This application only considers the addition of new data operations, so it is assumed that the forest structure constructed by the newly added data is Fnew. Given a query statement Q, its accurate cardinality value is Fnew(Q), and it is obvious that labelnew=labelold+Fnew(Q). In this way, the labels can be updated quickly. After updating the training data and training labels, this application uses the adam optimizer to update the deep learning model. The initial learning rate is set to 0.001, and it decreases by 20% every 2 rounds, for a total of 40 rounds of training.
[0165] The forest structure is updated by inserting the newly added database record data into the forest structure one by one, updating the statistical variables of each node of the multi-branch tree in the forest structure in turn, and then training.
[0166] As a preferred embodiment of the first embodiment, the query statement to be predicted is encoded and input into the deep learning model to obtain the cardinality estimation result, specifically:
[0167] Encode the query to be predicted to form an input vector, which consists of three parts: attribute vector, predicate vector and sample vector;
[0168] The attribute vector uses one-hot encoding to indicate the attribute position;
[0169] The predicate vector is used to encode the predicate type and restrict the space;
[0170] The sample vector is a bitmap used to indicate whether the sample data meets the query statement;
[0171] The deep learning model obtains the encoded input vector;
[0172] The cardinality estimation value is predicted through the deep learning model to obtain the cardinality estimation result.
[0173] Figure 4 The input query statement encoding vectorization is shown, where the attribute vector is a one-hot vector that indicates the location of the attribute used; the predicate vector indicates the predicate type (>, <, =, [], etc.) at that location and the range of the predicate restriction space; the sample vector is a bitmap, each bit indicates whether the sample data complies with the query statement, 1 if it complies, and 0 if it does not. For multiple tables, there is an additional table vector and a connection vector, both of which are one-hot vectors. The table vector is used to indicate which table is used; the connection vector is used to indicate the connection method. An example of encoding is as follows: Figure 3 For example, attribute θ0 is the first attribute, and its attribute vector is encoded as [1,0,0]; the predicate 'θ0≤1.834' does not contain the lower bound information of the restriction condition, so the first line is encoded as [0,0,0], the value part is also 0, and 'UB' is the upper bound of the single attribute cardinality.
[0174] The first embodiment of the present application combines a learning model and an accurate solution structure into a cardinality estimation hybrid model. Relying on the hybrid model, a deep learning model is used to estimate high-cardinality query statements, and a forest structure is used to accurately solve low-cardinality query statements. Compared with the problem of being unable to accurately estimate cardinality in the prior art, the hybrid model of the present application can accurately estimate queries of different cardinality.
[0175] Embodiment 2
[0176] Please refer to Figure 5 , which is a cardinality estimation device provided in an embodiment of the present application.
[0177] In this embodiment, the cardinality estimation device includes an acquisition module 10 , a prediction module 20 and a comparison module 30 .
[0178] The acquisition module 10 is used for the query statement to be predicted;
[0179] The prediction module 20 is used to encode the query statement to be predicted and input it into the deep learning model to obtain a cardinality estimation result, wherein the deep learning model is obtained by training the encoded historical query statement by the initial deep learning model;
[0180] As a preferred embodiment of the second embodiment, the deep learning model is obtained by training the encoded historical query statements by the initial deep learning model, specifically:
[0181] Obtain the encoded historical query sentence to obtain the historical query vector;
[0182] Build an initial deep learning model using two consecutive fully connected layers and a sigmoid function;
[0183] The historical query vector is obtained and trained through an initial deep learning model, and the initial deep learning model is optimized using a single attribute cardinality estimation upper bound loss function during the training process to obtain a deep learning model.
[0184] The initial deep learning model is extended from MSCN. Generally speaking, the initial deep learning model of this application includes a fully connected layer and a sigmoid activation function, such as Figure 2 shown.
[0185] In the initial deep learning model training phase, this application sets the initial learning rate to 0.001, and reduces it by 20% every 5 epochs, for a total of 100 rounds. The Adam optimizer is used for the initial deep learning model training.
[0186] As a preferred embodiment of the second embodiment, the optimization is performed using a single attribute cardinality estimation upper bound loss function during the initial deep learning model training process, specifically:
[0187] The expression of the upper bound loss function for single attribute cardinality estimation is:
[0188]
[0189] Where P represents the predicted value, L represents the label, and Bnd represents the upper bound of the single attribute cardinality;
[0190] During the training process, the predicted value of the cardinality estimation is continuously monitored to see whether it is close to or exceeds the preset upper limit of the single attribute cardinality;
[0191] When it is detected that the predicted value of the cardinality estimation exceeds or is expected to exceed the upper bound of the single attribute cardinality, the corresponding penalty is automatically applied through the single attribute cardinality estimation upper bound loss function.
[0192] The definition of attribute cardinality upper-bound (ACUB) is: given a table T, which contains u records (tuples) and x attributes (attributes) θ1, θ2, ..., θx; given a query statement Q, the corresponding constraints on the x attributes are γ1, γ2, ..., γx, then the cardinality upper bound on attribute θi can be expressed as the proportion of the number of records in table T that satisfy the constraint γi:
[0193] BoundQ(θi)=cardyi(T) / u
[0194] Obviously, the cardinality of a query statement is the number of records in T that meet all the restrictions, that is:
[0195] cardQ(T)=cardy1y2...yx(T)
[0196] Thus, even in the best case, the cardinality of a query statement must be less than the minimum value in the single cardinality upper bound, that is:
[0197] BoundQ(T)=cardy1y2...yx(T) / u≤min(cardγi(T) / u)
[0198] In this way, the single attribute cardinality upper bound can be used to limit the prediction space of the learning model, thereby improving the accuracy of the model.
[0199] Calculation method: The upper bound of the cardinality of a single attribute can be quickly obtained through a histogram;
[0200] (1) Point predicate (=): In this case, since the histogram is the number of times each value appears on a certain attribute, it can be obtained by using the histogram for indexing;
[0201] (2) Range predicates (≥, ≤, []): For these situations, the concepts of more-than-or-equal-to histogram (MH) and less-than-or-equal-to histogram (LH) are introduced. MH / LH stores the number of records that are greater than / less than each value of an attribute. For example, given an attribute, MHT[vi] represents the number of records in table T whose attribute position is greater than or equal to value vi. In this way, the upper bound of the single attribute cardinality of the range predicate [vi,vj] can be quickly calculated according to the following formula:
[0202] Bound[vi,vj](T)=(MHA[vi]+LHA[vj]) / u-1
[0203] The comparison module 30 is used to compare the cardinality estimation result with a preset threshold. If the cardinality estimation result is greater than the preset threshold, the cardinality estimation result is used as the final cardinality estimation result; otherwise, the accurate cardinality output by the forest structure is used as the final cardinality estimation result; wherein the forest structure is obtained by constructing a multi-branch tree based on database record data.
[0204] As a preferred embodiment of the second embodiment, the preset threshold is adaptively calculated by using a custom loss function to balance the effect and cost of a set of historical query statements on the two components of the deep learning model and the forest structure;
[0205] The formula for the custom loss function is:
[0206]
[0207] The loss function Cost(η) consists of two parts: t(η) and mqe(η); t(η) represents the time overhead of the forest structure; mqe(η) represents the average Q error value of the deep learning model and the forest structure in the historical data;
[0208] The nonlinear least squares method and the sequential least squares algorithm are used to find the minimum point of the custom loss function, and the abscissa of the minimum point is used as the threshold.
[0209] As a preferred embodiment of the second embodiment, the forest structure is obtained by constructing a multi-branch tree based on the database record data, specifically:
[0210] Get database record data;
[0211] Analyze the attributes of the database record data and identify the quantity of each attribute;
[0212] Construct multiple multi-branch trees according to the number of each attribute value, and each tree represents the value range of an attribute;
[0213] Combining all constructed multi-branch trees results in a forest structure.
[0214] More specifically, the steps for constructing the forest structure are:
[0215] Input: n tuples with x attributes, attribute order in ascending order of the number of values appearing in each attribute;
[0216]
[0217]
[0218] That is, given a record (tuple) with x attributes, the values of each attribute are v1, v2, ..., vx. Sort these attributes in ascending order of the number of different values of each attribute to get the order of the attributes. The tree building process starts from the root node Nroot of the tree (line 21).
[0219] Determine whether the value v1 has been stored in a child node of Nroot (line 6). If so, add 1 to the statistical variable of the child node Nv1 (line 7); otherwise, add a new node Nv1 as a child node of Nroot and initialize its statistical variable to 1 (lines 8-10).
[0220] Next, enter the child node Nv1 (line 12), and then determine whether the second value v2 has been stored in a child node of Nv1 (line 6). If so, add 1 to the statistical variable of the child node Nv2 (line 7); otherwise, add a new node Nv2 as a child node of Nv1 and initialize its statistical variable to 1 (lines 8-10). Repeat this step until all the values of the record are stored in the tree structure (line 2). At this point, the first tree structure in the forest structure is built.
[0221] Next, starting from order[2:], build the second tree according to the above steps for the x-1 attributes; starting from order[3:], build the third tree according to the above steps for the x-2 attributes. In this way, the final forest structure contains x tree structures.
[0222] Figure 3 An example of building a forest structure is given in . First, the attributes are sorted in ascending order according to the number of different values in them. Because there is only one value in θ1z, two values in θ0, and three values in θ2, the attributes are sorted as [θ1,θ0,θ2]. Then according to the above tree building process, the first tree contains the attribute range [θ1,θ0,θ2], the second tree contains the range [θ0,θ2], and the third tree is [θ2]. For a specified query statement, you can determine which tree to use for the exact solution based on the appearance of its predicate. For example, if the query statement has the restriction condition 'whereθ0=a andθ2=b', then you should use Figure 3 The second tree is used to find the exact solution.
[0223] As a preferred embodiment of the second embodiment, the use of the forest structure to output the accurate cardinality as the final cardinality estimation result is specifically as follows:
[0224] Obtain the encoded query sentence to be predicted to obtain a query vector to be predicted;
[0225] Identifying the attributes specified in the query vector to be predicted and the corresponding constraints;
[0226] Use binary search method to find the range of child nodes that meet the specified attributes and corresponding constraints in the multi-tree forest structure node;
[0227] Recursively search in the multi-tree forest structure nodes until all leaf nodes or terminal nodes that meet the query conditions are found;
[0228] The statistical variables in the leaf nodes or terminal nodes that meet the conditions are accumulated as the final accurate cardinality, and the accurate cardinality is the final cardinality estimation result.
[0229] More specifically, the steps for the forest structure to find the exact solution to the query statement are:
[0230] Input: a query Q with x attributes, where Q[j][-1] represents the upper bound of the constraint on the j-th attribute, and Q[j][-2] represents the lower bound of the constraint on the j-th attribute; exact solution to the forest structure Forest; attribute order in ascending order of the number of values that appear on each attribute;
[0231]
[0232]
[0233] First, the tree in the forest structure is selected according to the attributes that appear in the query statement (lines 16-19). Starting from the root node of the tree, a binary search is used to find the start node and the last node in the child nodes that meet the restriction on the first attribute (lines 7 and 8). Then, for each of the child nodes, a binary search is continued for their child nodes according to the restriction on the second attribute to find the start node and the last node in the second layer of child nodes that meet the restriction on the second attribute (lines 9 and 10). This search process is iterated until the restriction is exhausted (line 3). Finally, the values of the statistical variables stored in all nodes that meet the conditions are added up as the final accurate solution (line 4).
[0234] As a preferred embodiment of the second embodiment, when the data recorded in the database is updated, an update structure is added to the initial deep learning model and the forest structure;
[0235] The initial deep learning network model updates the single-attribute cardinality upper bound, sample vector and label before training; note that only the single-attribute cardinality upper bound and sample vector information in the input vector will change as the data is updated. In this way, the update of the single-attribute cardinality upper bound can be achieved by first updating the single-dimension histogram, and then updating the single-attribute cardinality upper bound through the single-attribute histogram. Furthermore, the reservoir sampling algorithm is used for dynamic update of the sample vector, which can ensure that in the dynamic data stream, the probability of each data being selected as a sample is equal. For the labels of the training data, since the forest structure can obtain the accurate cardinality value of the query statement, it can be updated by creating a new forest structure for the updated data. This application only considers the addition of new data operations, so it is assumed that the forest structure constructed by the newly added data is Fnew. Given a query statement Q, its accurate cardinality value is Fnew(Q), and it is obvious that labelnew=labelold+Fnew(Q). In this way, the labels can be updated quickly. After updating the training data and training labels, this application uses the adam optimizer to update the deep learning model. The initial learning rate is set to 0.001, and it decreases by 20% every 2 rounds, for a total of 40 rounds of training.
[0236] The forest structure is updated by inserting the newly added database record data into the forest structure one by one, updating the statistical variables of each node of the multi-branch tree in the forest structure in turn, and then training.
[0237] As a preferred embodiment of the second embodiment, the query statement to be predicted is encoded and input into the deep learning model to obtain the cardinality estimation result, which is specifically:
[0238] Encode the query to be predicted to form an input vector, which consists of three parts: attribute vector, predicate vector and sample vector;
[0239] The attribute vector uses one-hot encoding to indicate the attribute position;
[0240] The predicate vector is used to encode the predicate type and restrict the space;
[0241] The sample vector is a bitmap used to indicate whether the sample data meets the query statement;
[0242] The deep learning model obtains the encoded input vector;
[0243] The cardinality estimation value is predicted through the deep learning model to obtain the cardinality estimation result.
[0244] Figure 4The input query statement encoding vectorization is shown, where the attribute vector is a one-hot vector that indicates the location of the attribute used; the predicate vector indicates the predicate type (>, <, =, [], etc.) at that location and the range of the predicate restriction space; the sample vector is a bitmap, each bit indicates whether the sample data complies with the query statement, 1 if it complies, and 0 if it does not. For multiple tables, there is an additional table vector and a connection vector, both of which are one-hot vectors. The table vector is used to indicate which table is used; the connection vector is used to indicate the connection method. An example of encoding is as follows: Figure 3 For example, attribute θ0 is the first attribute, and its attribute vector is encoded as [1,0,0]; the predicate 'θ0≤1.834' does not contain the lower bound information of the restriction condition, so the first line is encoded as [0,0,0], the value part is also 0, and 'UB' is the upper bound of the single attribute cardinality.
[0245] The cardinality estimation device of the second embodiment of the present application uses three modules to divide the work and coordinate the work to better discover and deal with problems that arise in the cardinality estimation device. The device can comprehensively utilize historical and real-time data, quickly generate prediction results through the collaborative work of deep learning networks and forest structures, and make intelligent decisions based on dynamically determined thresholds to ensure the optimality of the output results.
[0246] Embodiment three:
[0247] An embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the cardinality estimation method;
[0248] Wherein, the cardinality estimation method, if implemented in the form of a software functional unit and used as an independent product, can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium, etc.
[0249] The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.
Claims
1. A cardinality estimation method, characterized in that: include: Get the query statement to be predicted; Encoding the query statement to be predicted and inputting it into a deep learning model to obtain a cardinality estimation result, wherein the deep learning model is obtained by training the encoded historical query statements with an initial deep learning model; If the cardinality estimation result is greater than a preset threshold, the cardinality estimation result is used as the final cardinality estimation result; otherwise, the accurate cardinality output by the forest structure is used as the final cardinality estimation result; wherein the forest structure is obtained by constructing a multi-branch tree based on database record data.
2. A cardinality estimation method according to claim 1, characterized in that: The deep learning model is obtained by training the encoded historical query sentences by the initial deep learning model, specifically: Obtain the encoded historical query sentence to obtain the historical query vector; Build an initial deep learning model using two consecutive fully connected layers and a sigmoid function; The historical query vector is obtained and trained through an initial deep learning model, and the initial deep learning model is optimized using a single attribute cardinality estimation upper bound loss function during the training process to obtain a deep learning model.
3. A cardinality estimation method according to claim 2, characterized in that: The single attribute cardinality is used to estimate the upper bound loss function for optimization during the training process, specifically: The expression of the upper bound loss function for single attribute cardinality estimation is: Where P represents the predicted value, L represents the label, and Bnd represents the upper bound of the single attribute cardinality; During the training process, the predicted value of the cardinality estimation is continuously monitored to see whether it is close to or exceeds the preset upper limit of the single attribute cardinality; When it is detected that the predicted value of the cardinality estimation exceeds or is expected to exceed the upper bound of the single attribute cardinality, the corresponding penalty is automatically applied through the single attribute cardinality estimation upper bound loss function.
4. A cardinality estimation method according to claim 1, characterized in that: The forest structure is obtained by constructing a multi-branch tree based on the database record data, specifically: Get database record data; Analyze the attributes of the database record data and identify the quantity of each attribute; Construct multiple multi-branch trees according to the number of each attribute value, and each tree represents the value range of an attribute; Combining all constructed multi-branch trees results in a forest structure.
5. A cardinality estimation method according to claim 1, characterized in that: The preset threshold is adaptively calculated by using a custom loss function to balance the effect and cost of a set of historical query statements on the two components of the deep learning model and the forest structure; The formula for the custom loss function is: The loss function Cost(η) consists of two parts: t(η) and mqe(η); t(η) represents the time overhead of the forest structure; mqe(η) represents the average Q error value of the deep learning model and the forest structure in the historical data; The nonlinear least squares method and the sequential least squares algorithm are used to find the minimum point of the custom loss function, and the abscissa of the minimum point is used as the threshold.
6. A cardinality estimation method according to claim 1, characterized in that: The use of the forest structure to output the accurate cardinality as the final cardinality estimation result is specifically as follows: Obtain the encoded query sentence to be predicted to obtain a query vector to be predicted; Identifying the attributes specified in the query vector to be predicted and the corresponding constraints; Use binary search method to find the range of child nodes that meet the specified attributes and corresponding constraints in the multi-tree forest structure node; Recursively search in the multi-tree forest structure nodes until all leaf nodes or terminal nodes that meet the query conditions are found; The statistical variables in the leaf nodes or terminal nodes that meet the conditions are accumulated as the final accurate cardinality, and the accurate cardinality is the final cardinality estimation result.
7. A cardinality estimation method according to claim 1, characterized in that: Also includes: When the data recorded in the database is updated, an updated structure is added to the initial deep learning model and the forest structure; The initial deep learning network model updates the single attribute cardinality upper bound, sample vectors, and labels before training; The newly added database record data is inserted into the forest structure one by one, and the statistical variables of each node of the multi-branch tree in the forest structure are updated in turn before training.
8. A cardinality estimation method according to claim 1, characterized in that: The query statement to be predicted is encoded and input into the deep learning model to obtain the cardinality estimation result, which is specifically: Encode the query to be predicted to form an input vector, which consists of three parts: attribute vector, predicate vector and sample vector; The attribute vector uses one-hot encoding to indicate the attribute position; The predicate vector is used to encode the predicate type and restrict the space; The sample vector is a bitmap used to indicate whether the sample data meets the query statement; The deep learning model obtains the encoded input vector; The cardinality estimation value is predicted through the deep learning model to obtain the cardinality estimation result.
9. A cardinality estimation device, characterized in that: It includes an acquisition module, a prediction module and a comparison module; The module is used to obtain the query statement to be predicted; The prediction module is used to encode the query statement to be predicted and input it into the deep learning model to obtain a cardinality estimation result, wherein the deep learning model is obtained by training the encoded historical query statement by the initial deep learning model; The comparison module is used to compare the cardinality estimation result with a preset threshold. If the cardinality estimation result is greater than the preset threshold, the cardinality estimation result is used as the final cardinality estimation result; otherwise, the accurate cardinality output by the forest structure is used as the final cardinality estimation result; wherein the forest structure is obtained by constructing a multi-branch tree based on database record data.
10. A cardinality estimation device according to claim 9, characterized in that: The deep learning model is obtained by training the encoded historical query sentences by the initial deep learning model, specifically: Obtain the encoded historical query sentence to obtain the historical query vector; Build an initial deep learning model using two consecutive fully connected layers and a sigmoid function; The historical query vector is obtained and trained through an initial deep learning model, and the initial deep learning model is optimized using a single attribute cardinality estimation upper bound loss function during the training process to obtain a deep learning model.
11. A cardinality estimation device according to claim 10, characterized in that: The single attribute cardinality is used to estimate the upper bound loss function for optimization during the training process, specifically: The expression of the upper bound loss function for single attribute cardinality estimation is: Where P represents the predicted value, L represents the label, and Bnd represents the upper bound of the single attribute cardinality; During the training process, the predicted value of the cardinality estimation is continuously monitored to see whether it is close to or exceeds the preset upper limit of the single attribute cardinality; When it is detected that the predicted value of the cardinality estimation exceeds or is expected to exceed the upper bound of the single attribute cardinality, the corresponding penalty is automatically applied through the single attribute cardinality estimation upper bound loss function.
12. A cardinality estimation device according to claim 9, characterized in that: The forest structure is obtained by constructing a multi-branch tree based on the database record data, specifically: Get database record data; Analyze the attributes of the database record data and identify the quantity of each attribute; Construct multiple multi-branch trees according to the number of each attribute value, and each tree represents the value range of an attribute; Combining all constructed multi-branch trees results in a forest structure.
13. A cardinality estimation device according to claim 9, characterized in that The preset threshold is adaptively calculated by using a custom loss function to balance the effect and cost of a set of historical query statements on the two components of the deep learning model and the forest structure; The formula for the custom loss function is: The loss function Cost(η) consists of two parts: t(η) and mqe(η); t(η) represents the time overhead of the forest structure; mqe(η) represents the average Q error value of the deep learning model and the forest structure in the historical data; The nonlinear least squares method and the sequential least squares algorithm are used to find the minimum point of the custom loss function, and the abscissa of the minimum point is used as the threshold.
14. A cardinality estimation device according to claim 9, characterized in that: The use of the forest structure to output the accurate cardinality as the final cardinality estimation result is specifically as follows: Obtain the encoded query sentence to be predicted to obtain a query vector to be predicted; Identifying the attributes specified in the query vector to be predicted and the corresponding constraints; Use binary search method to find the range of child nodes that meet the specified attributes and corresponding constraints in the multi-tree forest structure node; Recursively search in the multi-tree forest structure nodes until all leaf nodes or terminal nodes that meet the query conditions are found; The statistical variables in the leaf nodes or terminal nodes that meet the conditions are accumulated as the final accurate cardinality, and the accurate cardinality is used as the final cardinality estimation result.
15. The cardinality estimation device according to claim 9, characterized in that: Also includes: When the data recorded in the database is updated, an updated structure is added to the initial deep learning model and the forest structure; The initial deep learning network model updates the single attribute cardinality upper bound, sample vectors, and labels before training; The newly added database record data is inserted into the forest structure one by one, and the statistical variables of each node of the multi-branch tree in the forest structure are updated in turn before training.
16. A cardinality estimation device according to claim 9, characterized in that: The query statement to be predicted is encoded and input into the deep learning model to obtain the cardinality estimation result, which is specifically: Encode the query to be predicted to form an input vector, which consists of three parts: attribute vector, predicate vector and sample vector; The attribute vector uses one-hot encoding to indicate the attribute position; The predicate vector is used to encode the predicate type and restrict the space; The sample vector is a bitmap used to indicate whether the sample data meets the query statement; The deep learning model obtains the encoded input vector; The cardinality estimation value is predicted through the deep learning model to obtain the cardinality estimation result.
17. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the cardinality estimation method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Deep learning-based relational database cardinality estimation method
CN115269639A
Cardinality estimation method and device for database query optimization
CN115587111A
Method and device for improving adaptability of cardinality estimation model of active learning
CN116523029A
Deep learning-based method and apparatus for skyline query cardinality estimation
WO2024021624A1
