Database connection sequence adjusting method based on encoder-decoder architecture

The encoder-decoder architecture method addresses the challenge of mapping SQL execution plans to optimal plans by integrating real cardinality data, resulting in accurate and efficient connection order adjustments within the database query optimization process.

CN119691042AActive Publication Date: 2025-03-25NINGXIA UNIVERSITY
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411778125.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2025-03-25
Estimated Expiration
2044-12-05

AI Technical Summary

Technical Problem

Current database query optimization methods, including those using BERT for connection order adjustment, face challenges in accurately mapping SQL execution plans to optimal plans, leading to suboptimal results due to lack of integration with SQL execution plan layers, resulting in inefficient connection order adjustments.

Method used

A method employing a encoder-decoder architecture that constructs and optimizes connection order data by integrating table sequences, column collections, and predicate collections, training a transformer model with real cardinality data to refine SQL execution plans and produce accurate connection order adjustments.

Benefits of technology

This approach effectively maps SQL execution plans to optimal plans, avoiding suboptimal results by integrating real cardinality data into the optimization process, enhancing the accuracy and efficiency of connection order adjustments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119691042A_ABST
    Figure CN119691042A_ABST
Patent Text Reader

Abstract

The invention discloses a database connection sequence adjusting method based on an encoder-decoder architecture, and relates to the technical field. The method comprises the following steps: extracting table sequences with different lengths and column sets thereof from a database, constructing a predicate set of each column, and integrating information to obtain original connection sequence data; based on each table sequence of the original connection sequence data, constructing an SQL statement corresponding to the table sequence, executing the SQL statement through a database management system to obtain a real cardinal number of a predicate, and updating the original connection sequence data; the real cardinal number of the predicate is injected into a syntax tree of the SQL statement, query is optimized, table data information of a physical operator tree of the SQL statement is extracted, and optimal connection sequence data is obtained; the original connection sequence data and the optimal connection sequence data are used for training a transform model, and training is carried out; and pre-processing a newly queried SQL statement and inputting the pre-processed SQL statement into the model to obtain an accurate connection sequence adjustment result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and in particular to a method for adjusting a database connection sequence based on an encoder-decoder architecture. Background Art

[0002] Currently, join order selection is a key issue in database query optimization, which directly affects the efficiency of query execution. In practical applications, query optimizers need to face complex query spaces and huge data sizes, and efficiently selecting the optimal join order has always been a challenge. Traditional static join order enumeration algorithms search for the optimal solution by thoroughly traversing the query space, but this method is often time-consuming and labor-intensive, and even becomes infeasible when faced with large-scale data sets and complex queries. To solve this problem, modern query optimizers usually use a combination of heuristic algorithms and static methods. Therefore, join order selection is a key issue in database query optimization, which directly affects the performance and efficiency of queries, and optimizers continue to adopt new algorithms and methods to address this challenge in order to provide faster data processing capabilities.

[0003] In the existing technology, with the development of technology, modern database systems have adopted more advanced optimization techniques, such as machine learning, to predict the best connection order. These technologies can adapt to different query patterns and data distributions, and provide more dynamic and accurate optimization decisions. Heuristic algorithms can find a near-optimal solution in a shorter time. The latest research uses pure decoder-BERT to adjust the connection order, sets the connection order as the downstream task of BERT, and optimizes the adjustment of the connection order.

[0004] However, the traditional database query connection order adjustment mainly relies on heuristic rules. The disadvantage is that it will cause serious performance degradation in the face of complex query environments. In order to solve the above problems, a connection order adjustment based on reinforcement learning is proposed, but it consumes too many resources and relies heavily on reward functions. The latest research uses a pure decoder-BERT to adjust the connection order, setting the connection order as the downstream task of BERT. In terms of data sets, the mapping between the information at the SQL execution plan level and the optimal execution plan level is not integrated, which leads to the generation of suboptimal plans and cannot give accurate connection order adjustment results.

[0005] Therefore, how to integrate the information at the SQL execution plan level and the mapping between the optimal execution plan to avoid the generation of suboptimal plans and thus efficiently provide accurate connection order adjustment results is a problem to be solved. Summary of the invention

[0006] Based on this, it is necessary to provide a database connection order adjustment method based on an encoder-decoder architecture to address the above technical problems.

[0007] The present invention adopts the following technical solutions:

[0008] The present invention provides a method for adjusting a database connection sequence based on an encoder-decoder architecture, comprising:

[0009] Obtain table sequences of different lengths from the database, and obtain the column set of each table in each table sequence; construct a predicate set corresponding to each column in the column set; fill the table sequence with data including the table, each column corresponding to the table, and the predicate set corresponding to each column to obtain the original connection sequence data;

[0010] Through each table sequence in the original connection data, an SQL statement corresponding to each table sequence is constructed; through the database management system, the SQL statement corresponding to each table sequence is executed to obtain the real cardinality of the predicate in each table sequence, and in the process of executing the SQL statement, the real cardinality of the predicate is added to the original connection sequence data; the real cardinality of the predicate in the original connection sequence data is injected into the syntax tree corresponding to the SQL statement, the physical operator tree of the query optimization result is obtained, and the table data information of each leaf node of the physical operator tree is extracted to obtain the optimal connection sequence data;

[0011] The original connection sequence data and the optimal connection sequence data of the table are used as training sets to train the transformer model to obtain the final transformer model;

[0012] The data queried by the newly input SQL statement is adjusted to the data format that conforms to the original connection sequence through simple data processing and input into the final transformer model to obtain the connection sequence adjustment result of the table.

[0013] Preferably, obtaining the original connection sequence data comprises the following steps:

[0014] According to the database, the table sequence is constructed as T = {t}, and the column set of each table is constructed as t = {c}; where i, j = 1, 2, 3, ..., {t} represents the table sequence, t is a table in the table sequence, {c} is a column set of a table, and c represents a column in the column set; in addition, the value range of each column c is represents the minimum value of a column c in table t, Indicates the maximum value of a column c in table t;

[0015] For the table sequence {t}, construct all permutations of tables from 1 to |{t}|, each permutation corresponds to a table connection order, and a total of k connection orders are constructed; where k = 1+2! +…+|{t}|!;

[0016] For each table in the join order, obtain its corresponding column set {c}, and for each column, construct the corresponding predicate set P;

[0017] Construct a table set by each table t in each connection sequence, each column c corresponding to table t, and the predicate set P corresponding to each column. Among them, the symbol represents the Cartesian product;

[0018] Select the number of tables from 1 to k in the connection order, for the number of tables i, including There are several permutation results. For each permutation result, table t x Change to in, represents the full permutation, Indicates attachment to table t x Columns, Denotes attachment to a column The predicate of;

[0019] The set consisting of all the changed table arrangements is used as the original connection sequence data.

[0020] Preferably, constructing a corresponding predicate set P for each column includes the following steps:

[0021] Sort the values ​​in the column in ascending order to obtain sequence A;

[0022] Randomly select K values ​​from A as the center of the data cluster; the selection of K value is determined by the amount of data in sequence A. The larger the amount of data in sequence A, the larger the K value;

[0023] Subtract K values ​​from sequence A, calculate the distance between the remaining values ​​and the cluster center, and assign the data point to the cluster corresponding to the closest cluster center;

[0024] Calculate the mean of all member data points in the cluster and update the position of the cluster center;

[0025] Repeat the above steps until the position of the cluster center no longer changes, obtain all clusters of each column, and form a predicate p; where each cluster corresponds to an interval, each interval is [rl,ru], rl and ru represent the minimum and maximum values ​​corresponding to the interval, and rl≤p≤ru, p∈P, where P is the predicate set corresponding to each column.

[0026] Preferably, obtaining the optimal connection sequence data comprises the following steps:

[0027] For each table sequence in the original connection sequence data, a corresponding SQL statement is constructed, and the constructed SQL statement is saved in a separate file to obtain an original SQL file;

[0028] Execute the above SQL statement using a database management system to obtain the real cardinality of the columns in the table sequence under the predicate;

[0029] When the database management system executes to the syntax tree generation stage, the data information table-column-predicate (tcp) pre-saved in each leaf node of the syntax tree is changed to table-column-predicate-true cardinality (tcpe);

[0030] When the database management system executes to the query optimization stage, the input parameter of the cost model in the database management system is changed from the preset cardinality to the actual cardinality;

[0031] When the database management system completes execution, it obtains the query optimization result of the SQL statement, that is, the number of physical operators;

[0032] Extract the data information of the leaf nodes of the physical operator tree from left to right and from top to bottom to obtain an optimal table sequence;

[0033] All table sequences in the original connection sequence data are operated through the above steps to obtain all optimal table sequences, and the set composed of all optimal table sequences is the optimal continuous sequence data;

[0034] The original continuous sequential data in the database is replaced by the optimal continuous sequential data, and is saved in another independent file to obtain the optimal SQL file.

[0035] Preferably, obtaining the final transformer model comprises the following steps:

[0036] Get the dataset for the transformer model;

[0037] Divide the data set into training set and validation set according to the specified ratio;

[0038] Input the training set into the existing transformer model for training; wherein the parameters of the transformer model adopt default parameters or are adjusted as required;

[0039] The validation set is used to verify and tune the trained transformer model.

[0040] Preferably, the acquisition of the data set of the transformer model includes:

[0041] Save the original continuous sequence data and the optimal continuous sequence data to a text file;

[0042] Assume that the original continuous sequence data is JS={js}, and the optimal continuous sequence data is OJS={ojs}; wherein js} represents the set of data elements in the original continuous sequence data, and js is one of the elements; {ojs} represents the set of data elements in the original continuous sequence data, and ojs is one of the elements;

[0043] Through the data elements in the original continuous sequence data and the optimal continuous sequence data, the data format of each line in the text file is constructed as follows: "JS": "js", "OJS": "ojs". The data in the text file is the data set of the transformer model.

[0044] Preferably, the use of a validation set to validate and tune the trained transformer model includes:

[0045] Input the validation set into the trained transformer model, output the validation results of the model, judge the model effect and optimize it based on the validation results, and save the SQL statements corresponding to the poor validation results into a separate file, which is the tuning SQL file;

[0046] Wherein, judging the model effect and optimizing it according to the verification results includes:

[0047] If the output result is inconsistent with the number of tables or the content of the tables, it indicates that the model has serious generalization problems. You need to merge the tuning SQL file with the original SQL file and retrain the model for tuning.

[0048] If the result format of the model output is correct, but the execution effect of the SQL statement corresponding to the validation set data is not as good as the execution effect of the optimal SQL statement corresponding to the original SQL statement, it is necessary to further increase the high-quality data set to tune the model.

[0049] At least one of the above technical solutions adopted by the present invention can achieve the following beneficial effects:

[0050] The database connection sequence adjustment method based on the encoder-decoder architecture provided by the present invention obtains table sequences and column sets of different lengths, constructs a predicate set for each column, and fills the table sequence with data including the table, each column corresponding to the table, and the predicate set corresponding to each column to obtain original connection sequence data; based on each table sequence of the original connection sequence data, constructs a corresponding SQL statement, executes the SQL statement to obtain the real cardinality of the predicate, and updates the original connection sequence data, injects the real cardinality of the predicate into the syntax tree of the SQL statement for optimized query, and extracts data from the nodes of the optimized physical operator tree to obtain optimal connection sequence data, thereby reflecting the mapping relationship between the SQL execution plan level and the optimal execution plan.

[0051] In summary, the present invention constructs original connection sequence data and obtains optimal connection sequence data based on the original connection sequence data to reflect the mapping relationship between the database execution plan level and the optimal execution plan, thereby avoiding the generation of suboptimal plans. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0053] Figure 1 A schematic flow chart of a method for adjusting a database connection sequence based on an encoder-decoder architecture provided by the present invention. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the specific embodiments of the present invention and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0055] The technical solutions provided by various embodiments of the present invention are described in detail below in conjunction with the accompanying drawings.

[0056] This embodiment provides a method for adjusting the database connection order based on an encoder-decoder architecture, and its flow chart is as follows: Figure 1 As shown, the following steps are included:

[0057] S101: Obtain a large number of table sequences of different lengths through the tables corresponding to the database; construct a column set of each table in each table sequence, and construct a predicate set corresponding to each column in the column set to obtain a predicate set of all columns; fill the table sequence with data including the table, the columns corresponding to the table, and the predicate set corresponding to each column to obtain the original connection sequence data, specifically including:

[0058] According to the database, the table sequence is T = {t i}, and the column set of each table is constructed by combining the table sequence as t = {a j}; where i,j = 1, 2, 3, ...; each column c j The value range is Representation table t i A column c in j The minimum value of Representation table t i A column c in j The maximum value of

[0059] For the table sequence {t i}, respectively construct numbers ranging from 1 to |{t i}|, each permutation corresponds to a table connection order, and a total of k connection orders are constructed; where k = 1+2! +…+|{t i}|!;

[0060] For each table in the connection order, get the corresponding column set {c j}, and for each column, construct the corresponding predicate set P, including:

[0061] Sort the values ​​in the column in ascending order to obtain sequence A;

[0062] Randomly select K values ​​from A as the center of the data cluster; the selection of K value is determined by the amount of data in sequence A. The larger the amount of data in sequence A, the larger the K value;

[0063] Subtract K values ​​from sequence A, calculate the distance between the remaining values ​​and the cluster center, and assign the data point to the cluster corresponding to the closest cluster center;

[0064] Calculate the mean of all member data points in the cluster and update the position of the cluster center;

[0065] Repeat the above steps until the position of the cluster center no longer changes, obtain all the clusters of the column, and form the predicate p; where each cluster corresponds to an interval, each interval is [rl,ru], rl and ru represent the minimum and maximum values ​​corresponding to the interval, and rl≤p≤ru, p∈P;

[0066] Through each table t in each join sequencei , table t i Each corresponding column a t And the predicate set P corresponding to each column, construct the table set Among them, the symbol represents the Cartesian product;

[0067] Select the number of tables from 1 to k in the connection order, for the number of tables i, including There are several permutation results. For each permutation result, table t x Change to in, represents the full permutation, Indicates attachment to table t x Columns, Denotes attachment to a column The predicate of;

[0068] The set of all changed table arrangements is the original connection order data.

[0069] S102: constructing an SQL statement corresponding to the table sequence through each table sequence in the original connection data; executing the SQL statement corresponding to the table sequence through the database management system to obtain the real cardinality of the predicates in the table sequence, and adding the real cardinality of the predicates to the original connection sequence data during the execution of the SQL statement; injecting the real cardinality of the predicates in the original connection sequence data into the syntax tree corresponding to the constructed SQL statement, extracting the table data information of each leaf node of the syntax tree, and obtaining the optimal connection sequence data, specifically including:

[0070] For each table sequence in the original connection sequence data, a corresponding SQL statement is constructed, and the constructed SQL statement is saved in a separate file to obtain the original database file;

[0071] Execute the above SQL statement using a database management system to obtain the real cardinality of the columns in the table sequence under the predicate;

[0072] When the database management system executes to the syntax tree generation stage, the data information table-column-predicate (tcp) pre-saved in each leaf node of the syntax tree is changed to table-column-predicate-true cardinality (tcpe);

[0073] When the database management system executes to the query optimization stage, the input parameter of the cost model in the database management system is changed from the preset cardinality to the actual cardinality;

[0074] When the database management system completes execution, it obtains the query optimization result of the SQL statement, that is, the number of physical operators;

[0075] Extract the data information of the leaf nodes of the physical operator tree from left to right and from top to bottom to obtain an optimal table sequence;

[0076] All table sequences in the original connection sequence data are operated through the above steps to obtain all optimal table sequences, and the set composed of all optimal table sequences is the optimal continuous sequence data;

[0077] The original continuous sequence data in the database is replaced by the optimal continuous sequence data, and is saved in another independent file to obtain the optimal database file.

[0078] S103: The original connection sequence data and the optimal connection sequence data of the table are used as training sets to train the transformer model, and the model is tuned according to the training results to obtain the final transformer model, which specifically includes:

[0079] Get the dataset for the transformer model;

[0080] Divide the dataset into training and validation sets according to the specified ratio, including:

[0081] Save the original continuous sequence data and the optimal continuous sequence data to a text file;

[0082] Assume that the original continuous sequence data is JS={js}, and the optimal continuous sequence data is OJS={ojs}; wherein {js} represents the set of data elements in the original continuous sequence data, and js is one of the elements; {ojs} represents the set of data elements in the original continuous sequence data, and ojs is one of the elements;

[0083] The data elements in the original continuous sequence data and the optimal continuous sequence data are used to construct the data format of each line in the text file: "JS": "js", "OJS": "ojs". The data in the text file is the data set of the transformer model.

[0084] Input the training set into the existing transformer model for training; wherein the parameters of the transformer model adopt default parameters or are adjusted as required;

[0085] Use the validation set to verify and tune the trained transformer model, including:

[0086] Input the validation set into the trained transformer model, output the validation results of the model, judge the model effect and optimize it based on the validation results, and save the SQL statements corresponding to the poor validation results into a separate file, which is the tuning SQL file;

[0087] Wherein, judging the model effect and optimizing it according to the verification results includes:

[0088] If the output results show inconsistent numbers of tables or inconsistent table contents, it indicates that the model has serious generalization problems. You need to merge the tuning SQL file with the original SQL file and retrain the model for tuning.

[0089] If the result format of the model output is correct, but the execution effect of the SQL statement corresponding to the validation set data is not as good as the execution effect of the optimal SQL statement corresponding to the original SQL statement, it is necessary to further increase the high-quality data set to tune the model.

[0090] S104: The data queried by the newly input SQL statement is adjusted into data conforming to the original connection sequence data format through simple data processing, and input into the final transformer model to obtain the connection sequence adjustment result of the table.

[0091] This embodiment uses a database provided by a public Benchmark, and through the above steps, an accurate database connection order adjustment result is achieved, including:

[0092] According to the method in step S101, a table sequence D = {t1, t2, t3} is obtained through a public Benchmark database;

[0093] The data mode corresponding to each table is: t1:{c1int}; t2:{c1int}; t3:{c1int}, where c1 represents a column of tables t1, t2, and t3 respectively, and int represents an integer;

[0094] The column data corresponding to each table is:

[0095] t1.c1:{1,3,4,7,2,10,8,9,11,13,15}

[0096] t2.c1:{11,13,15,20,25,31,22,27,40};

[0097] t3.c1:{35,37,30,31,24,44,43}

[0098] For the above database, the method for solving the corresponding predicate set in each table according to step S101 is: as well as

[0099] Construct the original sequential connection data, taking one of the connection sequence data as an example, specifically:

[0100] According to the method of step S102, the SQL statement for connecting the sequential data is constructed to solve the real cardinality of the predicate in each column of each table:

[0101]

[0102] in, as well as represents the true cardinality of the predicate on column c1 in tables t1, t3, and t2, represents the first predicate element in the predicate set of table t1. represents the 0th predicate element in the predicate set of table t3. Represents the first predicate element in the predicate set of table t2;

[0103] Use the actual cardinality of the predicates corresponding to each table to replace the original connection order data as follows:

[0104] For the original connection sequence data replaced above, construct the SQL statement:

[0105] select 1from t1,t3,t2 where t1.c1=t3.c1 and t3.c1=t2.c1 and

[0106] Execute the above statement and during the execution, the true cardinality of the predicate corresponding to each table is as well as Inject it into the corresponding syntax tree node, capture the query optimization result, that is, the physical operator tree, extract the data information of each node in the physical operator tree, and obtain the optimal connection sequence data:

[0107] According to the method of step S103, a data set of a transfomer model is constructed:

[0108] “JS”: “OJS”:

[0109] Based on the above data, the transformer model is trained and tuned to obtain the final transformer model.

[0110] According to the method of step S104, for the newly input SQL query statement, the queried data is converted into a data set in the format of "JS": "js", "OJS": "ojs", and input into the final transformer model to obtain the connection order adjustment result.

[0111] In summary, through the verification of this embodiment, it is shown that the present invention constructs the original connection sequence data and obtains the optimal connection sequence data based on it, which reflects the mapping relationship between the database execution plan level and the optimal execution plan, and avoids the generation of suboptimal plans. At the same time, through the process of adjusting the original connection sequence of the database online, as well as offline training and continuous tuning of the transformer model, the generalization ability of the model is enhanced, so that the result of connection sequence adjustment is obtained efficiently and accurately:

[0112] The technical solution of the present invention is not limited to the above-mentioned specific embodiments. All technical variations made according to the technical solution of the present invention fall within the protection scope of the present invention.

Claims

1. A database connection order adjustment method based on an encoder-decoder architecture, characterized in that: The method comprises the following steps: Obtain table sequences of different lengths from the database, and obtain the column set of each table in each table sequence; construct a predicate set corresponding to each column in the column set; fill the table sequence with data including the table, each column corresponding to the table, and the predicate set corresponding to each column to obtain the original connection sequence data; Through each table sequence in the original connection data, an SQL statement corresponding to each table sequence is constructed; through the database management system, the SQL statement corresponding to each table sequence is executed to obtain the real cardinality of the predicate in each table sequence, and in the process of executing the SQL statement, the real cardinality of the predicate is added to the original connection sequence data; the real cardinality of the predicate in the original connection sequence data is injected into the syntax tree corresponding to the SQL statement, the physical operator tree of the query optimization result is obtained, and the table data information of each leaf node of the physical operator tree is extracted to obtain the optimal connection sequence data; The original connection sequence data and the optimal connection sequence data of the table are used as training sets to train the transformer model to obtain the final transformer model; The data queried by the newly input SQL statement is adjusted to the data format that conforms to the original connection sequence through simple data processing, and is input into the final transformer model to obtain the connection sequence adjustment result of the table.

2. The method for adjusting database connection order based on encoder-decoder architecture according to claim 1, characterized in that: The acquisition of the original connection sequence data comprises the following steps: According to the database, the table sequence is constructed as T = {t}, and the column set of each table is constructed as t = {c}; where i, j = 1, 2, 3, ..., {t} represents the table sequence, t is a table in the table sequence, {c} is a column set of a table, and c represents a column in the column set; in addition, the value range of each column c is represents the minimum value of a column c in table t, Indicates the maximum value of a column c in table t; For the table sequence {t}, construct numbers from 1 to | {t} | Each permutation of the table corresponds to a table connection order, and a total of k connection orders are constructed; where k = 1 + 2! +…+ | {t} | ! ; For each table in the join order, obtain its corresponding column set {c}, and for each column, construct the corresponding predicate set P; Construct a table set by each table t in each connection sequence, each column c corresponding to table t, and the predicate set P corresponding to each column. Among them, the symbol represents the Cartesian product; Select the number of tables from 1 to k in the connection order, for the number of tables i, including There are several permutation results. For each permutation result, table t x Change to in, represents the full permutation, Indicates attachment to table t x Columns, Denotes attachment to a column The predicate of; The set consisting of all the changed table arrangements is used as the original connection sequence data.

3. The method for adjusting database connection order based on encoder-decoder architecture according to claim 2, characterized in that: The step of constructing a corresponding predicate set for each column includes the following steps: Sort the values ​​in the column in ascending order to obtain sequence A; Randomly select K values ​​from A as the center of the data cluster; the selection of K value is determined by the amount of data in sequence A. The larger the amount of data in sequence A, the larger the K value; Subtract K values ​​from sequence A, calculate the distance between the remaining values ​​and the cluster center, and assign the data point to the cluster corresponding to the closest cluster center; Calculate the mean of all member data points in the cluster and update the position of the cluster center; Repeat the above steps until the position of the cluster center no longer changes, obtain all clusters of each column, and form a predicate p; where each cluster corresponds to an interval, each interval is [rl,ru], rl and ru represent the minimum and maximum values ​​corresponding to the interval, and rl≤p≤ru, p∈P, where P is the predicate set corresponding to each column.

4. The method for adjusting database connection order based on encoder-decoder architecture according to claim 1, characterized in that: The acquisition of the optimal connection sequence data comprises the following steps: For each table sequence in the original connection sequence data, a corresponding SQL statement is constructed, and the constructed SQL statement is saved in a separate file to obtain an original SQL file; Execute the above SQL statement using a database management system to obtain the real cardinality of the columns in the table sequence under the predicate; When the database management system executes to the syntax tree generation stage, the data information table-column-predicate (tcp) pre-saved in each leaf node of the syntax tree is changed to table-column-predicate-true cardinality (tcpe); When the database management system executes to the query optimization stage, the input parameter of the cost model in the database management system is changed from the preset cardinality to the actual cardinality; When the database management system completes execution, it obtains the query optimization result of the SQL statement, that is, the number of physical operators; Extract the data information of the leaf nodes of the physical operator tree from left to right and from top to bottom to obtain an optimal table sequence; All table sequences in the original connection sequence data are operated through the above steps to obtain all optimal table sequences, and the set composed of all optimal table sequences is the optimal continuous sequence data; The original continuous sequential data in the database is replaced by the optimal continuous sequential data, and is saved in another independent file to obtain the optimal SQL file.

5. The method for adjusting database connection order based on encoder-decoder architecture according to claim 1, characterized in that: The final transformer model is obtained by: Get the dataset for the transformer model; Divide the data set into training set and validation set according to the specified ratio; Input the training set into the existing transformer model for training; wherein the parameters of the transformer model adopt default parameters or are adjusted as required; The validation set is used to verify and tune the trained transformer model.

6. The method for adjusting database connection order based on encoder-decoder architecture according to claim 5, characterized in that: The acquisition of the data set of the transformer model includes: Save the original continuous sequence data and the optimal continuous sequence data to a text file; Assume that the original continuous sequence data is JS={js}, and the optimal continuous sequence data is OJS={ojs}; wherein {js} represents the set of data elements in the original continuous sequence data, and js is one of the elements; {ojs} represents the set of data elements in the original continuous sequence data, and ojs is one of the elements; Through the data elements in the original continuous sequence data and the optimal continuous sequence data, the data format of each line in the text file is constructed as follows: "JS":"js","OJS":"ojs". The data in the text file is the data set of the transformer model.

7. The method for adjusting database connection order based on encoder-decoder architecture according to claim 5, characterized in that: The validation set is used to validate and tune the trained transformer model, including: Input the validation set into the trained transformer model, output the validation results of the model, judge the model effect and optimize it based on the validation results, and save the SQL statements corresponding to the poor validation results into a separate file, which is the tuning SQL file; Wherein, judging the model effect and optimizing it according to the verification results includes: If the output result is inconsistent with the number of tables or the content of the tables, it indicates that the model has serious generalization problems. You need to merge the tuning SQL file with the original SQL file and retrain the model for tuning. If the result format of the model output is correct, but the execution effect of the SQL statement corresponding to the validation set data is not as good as the execution effect of the optimal SQL statement corresponding to the original SQL statement, it is necessary to further increase the high-quality data set to tune the model.

Citation Information

Patent Citations

  • Database query optimization method and system based on graph neural network

    CN113010547A

  • Self-adaptive multi-table connection cardinal number estimation method and system

    CN116150189A

  • Cardinality estimation method based on attention mechanism

    CN118377781A

  • Determining query join orders

    US20210342351A1