A method and system for adaptive multi-table join cardinality estimation

By employing an adaptive multi-table join cardinality estimation method, and utilizing a multi-set convolutional network model to learn the relevance of multi-table queries, the problem of inaccurate multi-table join cardinality estimation in traditional methods is solved, thereby improving query execution efficiency.

CN116150189BActive Publication Date: 2025-11-18SHANDONG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310102690.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-06
Publication Date
2025-11-18
Estimated Expiration
2043-02-06

AI Technical Summary

Technical Problem

Traditional cardinality estimation methods for multi-table joins are inaccurate and tend to underestimate the cardinality, especially when joining more than three tables. This leads to low query execution efficiency and fails to effectively utilize the correlation between data.

Method used

An adaptive multi-table join cardinality estimation method is adopted. By establishing relevance sample features, using accurate execution statistics and samples with relevance features as training data, and using a multi-set convolutional network model to learn the relevance of multi-table join queries, the accuracy of cardinality estimation is improved.

Benefits of technology

It improves the accuracy of cardinality estimation in multi-table join queries, selects a better execution plan, and improves the efficiency of query execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116150189B_ABST
    Figure CN116150189B_ABST
Patent Text Reader

Abstract

The application belongs to the field of connection cardinality estimation, and provides a method and system for adaptive multi-table connection cardinality estimation. The method for adaptive multi-table connection cardinality estimation comprises receiving an input query statement and analyzing the contained relationship and the connection relationship of multi-table connection of the query statement; the analysis result of the query statement is subjected to feature vectorization, and then the cardinality of the query statement is predicted based on a cardinality estimation model; the query statement is converted into a database query prompt, a query optimizer is operated through the prompt, the query statement is executed, and a real cardinality value is obtained; the feature vector corresponding to the analysis result of the query statement and the real cardinality value constitute a training sample, and the cardinality estimation model is retrained to learn the correlation of multi-table joint query, which is used for estimation of the next connection cardinality.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the field of join cardinality estimation, and particularly relates to a method and system for adaptive multi-table join cardinality estimation. BACKGROUND

[0002] The statements in this section merely provide background information related to the present application and do not necessarily constitute prior art.

[0003] Query optimization is one of the cores of a database management system, and involves the construction of a database query execution plan tree, the selection of a specific implementation at a plan tree node, the selection of parameters, the selection of a compiled execution, and the like. A query optimizer is mainly composed of three components, i.e., cardinality estimation, a cost model, and plan enumeration. After a SQL statement is input in the query optimization stage, a syntax tree is obtained after analysis and inspection. A cardinality estimation module predicts the remaining number of rows of a table under a single-table filtering condition or the remaining number of rows of a connected table under a multi-table join filtering condition. Cardinality estimation is an important component of query optimization, and the output of this module will be used in the cost model to estimate the number of rows of a table in each query scheme and the execution time of the scheme, so as to select a query plan in the plan enumeration space that can efficiently execute the query, thereby improving the efficiency of subsequent query execution.

[0004] The challenge of traditional cardinality estimation research lies in a query involving related predicates of columns in different tables, which are connected through join and are referred to as "multi-table joint query correlation". Prior knowledge of multi-table join cardinality estimation has problems such as difficulty in statistics and low generality, and especially when three or more tables are connected, an independent distribution assumption is often used for prediction, which is prone to inaccurate prediction results. In multi-table join cardinality estimation, as the number of tables participating in the connection increases, the error of the cardinality estimation result gradually becomes larger, and there is a serious tendency to underestimate the multi-table join cardinality. The inventors have found that the traditional cardinality estimation method applies assumptions such as independent data application attribute values, and query feedback information is not effectively utilized, which leads to not considering the correlation between data (columns) and often results in inaccurate cardinality estimation results, thus selecting a suboptimal execution plan and ultimately leading to inefficient and slow query execution. SUMMARY

[0005] In order to solve the technical problems in the background art, the present application provides a method and system for adaptive multi-table join cardinality estimation, which establishes correlation sample features in the data preprocessing part, uses accurate execution statistical information and samples with correlation features as training data to input a model, and uses an adaptive idea to train the model, so as to better learn the correlation under multi-table joint query and thus improve the accuracy of multi-table join query cardinality estimation.

[0006] In order to achieve the above purpose, the present application adopts the following technical solutions:

[0007] The first aspect of the present application provides a method for adaptive multi-table join cardinality estimation.

[0008] A method for adaptive multi-table join cardinality estimation comprises:

[0009] receiving an input query statement and analyzing its containment relationship and join relationship of multi-table join;

[0010] vectorizing the analysis result of the query statement, and predicting the cardinality of the query statement based on a cardinality estimation model;

[0011] converting the query statement into a database query hint, operating a query optimizer through the hint, executing the query statement, and obtaining a real cardinality value;

[0012] constructing a training sample of the feature vector corresponding to the analysis result of the query statement and the real cardinality value, and re-training the cardinality estimation model to learn the correlation of multi-table joint query for the estimation of the next join cardinality.

[0013] As an implementation, the cardinality estimation model is a multi-set convolutional network model.

[0014] As an implementation, in the multi-set convolutional network model, tables, joins, and predicates are represented as separate modules, each set element is composed of a two-layer neural network with shared parameters; the module output is sequentially subjected to averaging and series connection operations and then fed to a final output network.

[0015] As an implementation, the process of vectorizing the analysis result of the query statement is as follows:

[0016] encoding and representing the analysis result of the query statement into a unique one-hot vector;

[0017] standardizing the one-hot vector.

[0018] The second aspect of the present application provides a system for adaptive multi-table join cardinality estimation.

[0019] A system for adaptive multi-table join cardinality estimation comprises:

[0020] a query statement analysis module for receiving an input query statement and analyzing its containment relationship and join relationship of multi-table join;

[0021] a join cardinality prediction module for vectorizing the analysis result of the query statement, and predicting the cardinality of the query statement based on a cardinality estimation model;

[0022] a real base determining module, configured to convert the query statement into a database query prompt, execute the query statement through a query optimizer operated by the prompt, and obtain a real base value;

[0023] a correlation learning module, configured to form a training sample by using a feature vector corresponding to the analysis result of the query statement and the real base value, and re-train the base estimation model to learn the correlation of the multi-table joint query, for estimation of the next join base.

[0024] As an implementation form, the base estimation model is a multi-set convolutional network model.

[0025] As an implementation form, in the multi-set convolutional network model, the table, the join and the predicate are represented as separate modules, each set element is composed of a two-layer neural network with shared parameters, and the module output is fed to a final output network after being sequentially subjected to an average and a series connection operation.

[0026] As an implementation form, in the join base prediction module, the process of feature vectorization of the analysis result of the query statement is as follows:

[0027] the analysis result of the query statement is encoded and represented as a unique one-hot vector;

[0028] the one-hot vector is normalized.

[0029] A third aspect of the present application provides a computer readable storage medium.

[0030] A computer readable storage medium having a computer program stored thereon, the program being executed by a processor to implement the steps of the adaptive multi-table join base estimation method described above.

[0031] A fourth aspect of the present application provides an electronic device.

[0032] An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the adaptive multi-table join base estimation method described above when executing the program.

[0033] Compared with the prior art, the present application has the following advantages:

[0034] The present application establishes correlation sample features in the data preprocessing part, uses accurate execution statistics and samples with correlation features as training data input model, and uses adaptive idea to train the model, which can better learn the correlation under multi-table joint query, thereby improving the accuracy of multi-table join query base estimation.

[0035] Advantages of additional aspects of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0036] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.

[0037] Figure 1 This is a flowchart of the adaptive multi-table join cardinality estimation method according to an embodiment of the present invention;

[0038] Figure 2 It is the Word2vec skip-gram algorithm;

[0039] Figure 3 It is a row vector embedding method;

[0040] Figure 4 This is a schematic diagram of a multilayer sensor structure;

[0041] Figure 5 This is the MSCN architecture of an embodiment of the present invention;

[0042] Figure 6 This is a schematic diagram of the adaptive multi-table join cardinality estimation method according to an embodiment of the present invention. Detailed Implementation

[0043] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0044] It should be noted that the following detailed description is illustrative and intended to provide further explanation of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.

[0045] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of exemplary embodiments according to the invention. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.

[0046] Example 1

[0047] In this embodiment, considering that the accurate results obtained after query execution are not effectively utilized, if query execution statistics are collected and incorporated into the learning input, the relevance of multi-table joint queries can be learned. Continuously querying and obtaining and utilizing feedback is an adaptive process.

[0048] exist Figure 1 The adaptive multi-table join cardinality estimation method in this embodiment can estimate the cardinality of query statements involving multi-table joins. The generated cardinality estimation result is injected into the PostgreSQL optimizer to generate an execution plan. After the PostgreSQL executor executes the plan, it can obtain query feedback information.

[0049] Reference Figure 1 and Figure 6 This embodiment provides an adaptive multi-table join cardinality estimation method, which includes:

[0050] Step S101: Receive the input query statement and analyze its inclusion relationship and multi-table join relationship.

[0051] Step S102: Convert the analysis results of the query statement into feature vectors, and then predict the cardinality of the query statement based on the cardinality estimation model;

[0052] Specifically, the process of vectorizing the analysis results of the query statement into feature vectors is as follows:

[0053] The analysis results of the query statement are encoded and represented as a unique one-hot vector;

[0054] Then, the one-hot vector is standardized.

[0055] The raw data comes from the real-world dataset IMDB—the Internet Movie Information Database—which includes film information, actor information, production company information, and more.

[0056] Data processing primarily involves the representation of query statements and the design of vectorized encoding methods. The encoding method for query statements needs to include information required for query optimization, such as relationships within the query and join relationships between multiple tables. This method represents a query q∈Q as a set of tables. A set of connections and a set of predicates A set (Tq, Jq, Pq) participates in a specific query q. Each table t∈T is represented by a unique one-hot vector vt (a binary vector of length |T| with one non-zero entry, uniquely identifying a specific table). Similarly, joins j∈J are characterized using one-hot encoding. For predicates of the form (col, op, val), we represent col and op as unique one-hot vectors based on different encoding methods, and normalize the value val∈[0,1] using the minimum and maximum values ​​of the corresponding columns.

[0057] Cardinality estimation is crucial for query optimizers. For multi-table join queries, database systems often make simplifying assumptions about relevance, such as uniformity, independence, or inclusion principles, which frequently lead to inaccurate estimates. Our method avoids making simplistic assumptions about data distribution and does not attempt to directly estimate predicate cardinality. Instead, it constructs semantically rich, vectorized representations of query predicates that can serve as input to a cardinality estimation model, enabling neural networks to learn data relevance. Following recent work in semantic querying, entity matching, data discovery, and error detection, we construct vectorized representations of each query predicate based on data from the database itself.

[0058] In this method, we treat each row of each table in the database as a sentence and each column value of that row as a word. Therefore, values ​​that frequently appear together in the same row are mapped to similar vectors. We call these vectors row vectors. The cardinality estimation model can take these row vectors as input and use them to identify correlations between data and predicates whose values ​​are syntactically different but semantically similar. Figure 3 The row vector method shown is based on the word2vec algorithm, which is a method for converting natural language words into vectors. For example... Figure 2 As shown in the word2vec example, each entry in the column predicate vector is replaced with a vector containing semantic information related to the predicate.

[0059] Our goal is to construct a semantically rich representation of the query predicate, which a cardinality estimation model can use as input. First, we construct a three-layer neural network, called the embedding network, with equal-sized input and output layers. The neural network is trained to map each one-hot encoded value in the database to an output vector representing the context of that value. After training the embedding network, the output layer is removed, resulting in a two-layer network. Using this truncated network, we construct a vectorized representation of the database values ​​by passing the database values ​​to the input layer and recording the values ​​in the embedding layer. To encode the query predicate, we combine information from the predicate operators (e.g., LIKE or !=) with the embedding vector. In the simplest case, the query predicate is of the form tbl.attr OP VALUE, for example, m.type="Romance". For these simple cases, the query predicate is encoded by concatenating the one-hot encoding of the predicate operator (e.g., =) with the embedding vector of the predicate value (e.g., "Romance"). This concatenated vector replaces the simple 0s or 1s used in one-hot encoding. By partially denormalizing the database, the word2vec model can capture inter-table correlations, thus improving embedding.

[0060] The cardinality estimation model is a multi-set convolutional network model.

[0061] In a multi-set convolutional network model, tables, connections, and predicates are represented as separate modules. Each set element consists of a two-layer neural network with shared parameters. The module outputs are fed into the final output network after being successively averaged and concatenated.

[0062] After obtaining the characteristic query, the model can be used for prediction.

[0063] This method introduces the multi-set convolutional network (MSCN) model, a neural network module for operating on sets, originally derived from the Deep Sets model. The Deep Sets model is based on the observation that any function f(S) on a set S is permutation-invariant with respect to the elements of S and can be decomposed into functions ρ and ρ with appropriate choices. ρ[∑x∈S Φ(x)].

[0064] In the specific implementation process, simple fully connected multilayer neural networks (MLPs) are chosen to parameterize the functions ρ and ρ. They rely on their function approximation properties to learn the mapping f(S) of any set S. Among them, the Multi-Laver Perceptron (MLP) is a classic neural network architecture, whose excellent function approximation capabilities have been successfully applied in modeling and control fields.

[0065] like Figure 4 As shown, a multilayer perceptron (MLP) is a network with interconnected layers, meaning it has a multi-layered structure where neurons in each layer do not interact directly; information transfer occurs only between layers. The number of hidden layers in an MLP often varies depending on the number of neurons in the input and output layers, as well as the nature of the dataset itself. Research indicates that in most scenarios, one hidden layer is sufficient for application requirements, while two hidden layers are typically used to approximate discontinuous functions, such as sawtooth waves. In most approximations of continuous functions, the performance improvement of two hidden layers compared to one hidden layer is limited, and it may even lead to getting trapped in local optima. Currently, there is no theoretical analysis showing that using more than two hidden layers in an MLP will improve performance. In summary, since the size of the result set and the feature vectors of a multi-table connection cardinality are difficult to describe with a continuous function, we believe that using two hidden layers is likely to better estimate the size of the result set. Therefore, this paper first conducts experiments with two hidden layers and two hidden layers to compare the performance differences and ultimately determine the number of hidden layers.

[0066] exist Figure 5 In this architecture, tables, connections, and predicates are represented as separate modules, and each set element consists of a two-layer neural network with shared parameters. The module outputs are averaged, concatenated, and fed into the final output network.

[0067] The query representation in this method consists of multiple sets, and we make the following choices for the model architecture: For each set S, we learn a set-specific, element-by-element neural network MLP. S (v s That is, applying to each feature vector V for each element t∈T. S It is independent. Then, the final representation w of the set. S It is given by the average value of each transformation of its elements, that is: We choose an average (instead of a simple summation) to simplify generalization to different numbers of elements in set S; otherwise, the overall size of the network output would vary depending on the number of elements in S.

[0068] Table module:

[0069] Join module:

[0070] Predicate module:

[0071] In practice, we implemented a vectorized version of the model that operates on mini-batch data. Since the number of set elements in each data sample may differ during mini-batch processing, we padded all samples with zero-valued feature vectors so that all samples in the mini-batch have the same number of set elements. We masked the dummy set elements in the averaging operation, so only the original set elements are involved in the averaging.

[0072] Finally, we concatenate the various set representations and then pass them to the final output MLP:

[0073] Merge & Predict: w out =MLP out ([w t w J w P ]) (4)[,] indicates vector concatenation

[0074] All MLP modules are two fully connected neural networks with activation functions:

[0075] LeakyReLU(x)=I(x<0)(α(x)+I(x≥0) (x) (5) α is a parameter with a preset size.

[0076] Instead of using the output MLP, apply the activation function to the last layer:

[0077]

[0078] Only one scalar is output, therefore w out ∈[0, 1]. We use the LeakyReLU activation function for the hidden layer, which is a variation of the ReLU activation function. It addresses the vulnerability of ReLU during training by not converting x < 0 to 0, but instead transforming it into a very small negative slope, such as 0.01. All other representation vectors w in the MLP... T w J w P The vector chosen as dimension d, where d is a hyperparameter, is optimized on a separate validation set via grid search.

[0079] We normalize the target cardinality Ctarget as follows: We first take the logarithm to distribute the target values ​​more evenly, and then normalize it to the interval [0, 1] using the log-normalized minimum and maximum values ​​obtained from the training set. Normalization is invertible, so we can obtain the predicted values ​​w from our model's output. out Recover the non-normalized cardinality in [0, 1].

[0080] This method obtains an initial training corpus by generating random queries based on pattern information and extracting text from actual values ​​in a database. Training samples consist of table identifiers, join predicates, base table predicates, and the proper cardinality of the query results. To avoid combinatorial explosion, we generate queries with at most two joins and allow the model to generalize to more joins.

[0081] The query generator first uniformly plots the number of joins |Jq|(0)≤|Jq|≤2), then uniformly selects a table referenced by at least one table. For |Jq|>0, it uniformly selects a new table that can be joined with the current table set (initially only one table), adds the corresponding join edge to the query, and repeats this process (overall) |Jq| times. For each base table t in the query, the number of predicates is uniformly plotted. For each predicate, we uniformly plot the predicate type (=< or >) and select a text (actual value) from the corresponding column. We configure the query generator to generate only unique queries. We then execute these queries to obtain their true result cardinality, while skipping queries with empty results. Through this process, we obtain the initial training set for the model. VI. Query Execution Feedback Statistics Collection

[0082] Step S103: Convert the query statement into a database query hint, and execute the query statement through the query optimizer operated by the hint to obtain the true cardinality value;

[0083] Step S104: Use the feature vectors and true cardinality values ​​corresponding to the analysis results of the query statement to form training samples, and retrain the cardinality estimation model to learn the relevance of multi-table joint queries, which will be used for the estimation of the next join cardinality.

[0084] The main principle of adaptive cardinality estimation in this embodiment is to use the execution statistics of executed queries as input data for machine learning. To verify the quality of cardinality estimation and obtain query execution feedback, we integrated the deep learning cardinality estimation model algorithm MSCN into the PostgreSQL query optimizer.

[0085] For each SQL query Q, each subplan query is a query that involves only a subset of the tables in Q. The collection of all subqueries is called the subplan query space. PostgreSQL's built-in planner generates the subplan query space for query Q, and then PostgreSQL's cost model estimates their execution costs to determine the optimal execution plan. To select the best execution plan, we need to inject a more accurate cardinality estimate from the neural network model into the PostgreSQL optimizer. To do this, in our implementation, we override the `calc_joinrel_size_estimate` function in the PostgreSQL planner to derive the subplan query space for each query in the workload. Specifically, whenever the planner needs a cardinality estimate for a subplan query, the modified function `calc_joinrel_size_estimate` immediately captures it. Then, the MSCN cardinality estimation method is called to estimate the cardinality of the subplan query, and the estimate is injected into PostgreSQL. Afterward, we run the PostgreSQL compiler on query Q to generate a plan, which directly reads the injected cardinality generated by the MSCN method. Finally, we execute the query with the generated plan. In this way, we enable PostgreSQL to support deep learning cardinality estimation methods without requiring significant modifications to the PostgreSQL source code. It's worth noting that we can report the total time (excluding subplan space generation time) as the end-to-end time cost of running a SQL query using any cardinality estimation method, and collect and provide feedback on query execution statistics executed by PostgreSQL.

[0086] For collecting query execution statistics, the `pg_stat_statements` module in PostgreSQL provides a way to track the execution statistics of all SQL statements executed by a server. This module must be loaded by adding `pg_stat_statements` to `shared_preload_libraries` in `postgresql.conf`. When loaded, `pg_stat_statements` tracks statistics for all databases on the server. To access and manipulate these statistics, the module provides a view `pg_stat_statements` and utility functions `pg_stat_statements_reset` and `pg_stat_statements`. These views and functions are not globally available; they can be enabled for specific databases using `CREATEEXTENSION pg_stat_statements`. This method allows for the periodic collection and packaging of query execution statistics, which can then be used as input data for machine learning to further train models, learn correlations between data, and perform more accurate cardinality estimation.

[0087] Example 2

[0088] This embodiment provides a system for adaptive multi-table join cardinality estimation, which includes:

[0089] The query statement analysis module is used to receive input query statements and analyze their inclusion relationships and multi-table join relationships;

[0090] Connect the cardinality prediction module, which is used to vectorize the analysis results of the query statement into feature vectors, and then predict the cardinality of the query statement based on the cardinality estimation model;

[0091] The true cardinality determination module is used to transform the query statement into a database query hint. The query optimizer, which operates on the hint, executes the query statement and obtains the true cardinality value.

[0092] The relevance learning module is used to construct training samples from the feature vectors corresponding to the analysis results of the query statement and the true cardinality values, and to retrain the cardinality estimation model to learn the relevance of multi-table joint queries for the estimation of the next join cardinality.

[0093] The cardinality estimation model is a multi-set convolutional network model.

[0094] In a multi-set convolutional network model, tables, connections, and predicates are represented as separate modules. Each set element consists of a two-layer neural network with shared parameters. The module outputs are fed into the final output network after being successively averaged and concatenated.

[0095] Specifically, in the connection cardinality prediction module, the process of vectorizing the analysis results of the query statement into feature vectors is as follows:

[0096] The analysis results of the query statement are encoded and represented as a unique one-hot vector;

[0097] Then, the one-hot vector is standardized.

[0098] It should be noted that each module in this embodiment corresponds one-to-one with each step in Embodiment 1, and their specific implementation processes are the same, so they will not be repeated here.

[0099] Example 3

[0100] This embodiment provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the adaptive multi-table join cardinality estimation method described above.

[0101] Example 4

[0102] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps in the adaptive multi-table join cardinality estimation method described above.

[0103] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0104] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for adaptive multi-table join cardinality estimation, characterized in that, include: Receive the input query statement and analyze its inclusion relationship and multi-table join relationship; The analysis results of the query statement are vectorized into feature vectors, and then the cardinality of the query statement is predicted based on the cardinality estimation model. The query statement is transformed into a database query hint, and the query optimizer, which operates on the hint, executes the query statement to obtain the true cardinality value; The feature vectors corresponding to the analysis results of the query statement and the true cardinality values ​​are used as training samples, and the cardinality estimation model is retrained to learn the relevance of multi-table joint queries for the estimation of the cardinality of the next connection. The cardinality estimation model is a multi-set convolutional network model. In the multi-set convolutional network model, the table, connection and predicate are represented as separate modules, and each set element is composed of a two-layer neural network with shared parameters. The module outputs are fed into the final output network after being averaged and concatenated in sequence. Treat each row of each table in the database as a sentence, and each column value of the table row as a word. Values ​​that often appear together in the same row are mapped to similar vectors, which are called row vectors. Cardinality estimation models take these row vectors as input and use them to identify correlations in data and predicates that are syntactically different but semantically similar. The query predicate is encoded by combining information about the predicate operators with an embedded vector. The form of the query predicate is: By encoding the predicate operator "=" with the predicate value The embedded vectors are concatenated to encode the query predicate; This concatenation vector replaced The simple 0s or 1s used in the encoding, through partial denormalization of the database, allow... The model captures inter-table correlations and improves embedding.

2. The adaptive multi-table join cardinality estimation method as described in claim 1, characterized in that, The process of vectorizing the analysis results of the query statement into feature vectors is as follows: The analysis results of the query statement are encoded and represented as a unique one-hot vector; Then, the one-hot vector is standardized.

3. A system for adaptive multi-table join cardinality estimation, characterized in that, include: The query statement analysis module is used to receive input query statements and analyze their inclusion relationships and multi-table join relationships; Connect the cardinality prediction module, which is used to vectorize the analysis results of the query statement into feature vectors, and then predict the cardinality of the query statement based on the cardinality estimation model; The true cardinality determination module is used to transform the query statement into a database query hint. The query optimizer, which operates on the hint, executes the query statement and obtains the true cardinality value. The relevance learning module is used to construct training samples from the feature vectors corresponding to the analysis results of the query statement and the true cardinality values, and to retrain the cardinality estimation model to learn the relevance of multi-table joint queries for the estimation of the next join cardinality. The cardinality estimation model is a multi-set convolutional network model. In the multi-set convolutional network model, the table, join, and predicate are represented as separate modules, and each set element consists of a two-layer neural network with shared parameters. The module output is fed into the final output network after being averaged and concatenated in sequence. Treat each row of each table in the database as a sentence, and each column value of the table row as a word. Values ​​that often appear together in the same row are mapped to similar vectors, which are called row vectors. Cardinality estimation models take these row vectors as input and use them to identify correlations in data and predicates that are syntactically different but semantically similar. The query predicate is encoded by combining information about the predicate operators with an embedded vector. The form of the query predicate is: By encoding the predicate operator "=" with the predicate value The embedded vectors are concatenated to encode the query predicate; This concatenation vector replaced The simple 0s or 1s used in the encoding, through partial denormalization of the database, allow... The model captures inter-table correlations and improves embedding.

4. The system for adaptive multi-table join cardinality estimation as described in claim 3, characterized in that, The cardinality estimation model is a multi-set convolutional network model.

5. The system for adaptive multi-table join cardinality estimation as described in claim 4, characterized in that, In a multi-set convolutional network model, tables, connections, and predicates are represented as separate modules. Each set element consists of a two-layer neural network with shared parameters. The module outputs are fed into the final output network after being successively averaged and concatenated.

6. The system for adaptive multi-table join cardinality estimation as described in claim 3, characterized in that, In the connection cardinality prediction module, the process of vectorizing the analysis results of the query statement into feature vectors is as follows: The analysis results of the query statement are encoded and represented as a unique one-hot vector; Then, the one-hot vector is standardized.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps in the method for adaptive multi-table join cardinality estimation as described in any one of claims 1-2.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps in the method for adaptive multi-table join cardinality estimation as described in any one of claims 1-2.

Citation Information

Patent Citations

  • Multi-dimensional range query cardinal number estimation method on database

    CN112883066A

  • Deep learning-based relational database cardinality estimation method

    CN115269639A