Query request coding method, data query method and related equipment
Through the encoding method of database query requests, the self-attention mechanism is used to combine the node relationship in the query plan to generate richer query information, which solves the problem of low parameter adjustment quality caused by coding limitations in the existing technology, and realizes the Higher query accuracy and efficiency.
Patent Information
- Application Number
- CN202411449630.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-02-14
AI Technical Summary
When encoding database query requests, the prior art has limitations, and it is difficult to effectively capture the node relationship and execution process information in complex query plans, resulting in low parameter adjustment quality.
A coding method based on query plan is proposed, and the target encoding is generated by encoding multiple nodes in the query plan into vectors and combining the connection relationship between nodes. This method uses the self-attention mechanism to calculate the self-attention score, captures the long-distance dependence between multiple nodes, and generates richer query information.
By including more query execution process information, query accuracy is improved, especially in query plans with a large number of nodes and complex node relationships, the quality and efficiency of parameter adjustment are significantly improved.
Smart Images

Figure CN119441270A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a query request encoding method, a data query method, and related devices. Background Art
[0002] In the field of computer technology, a database is usually used to store data, and data can be queried from the database based on a query request. There are adjustable system parameters in the database. In the related art, database operation and maintenance personnel usually rely on their own experience to adjust the parameters of the database, and it takes a lot of time to tune these parameters.
[0003] The inventors of the present disclosure have discovered that a machine learning method can be used in the related art to automatically adjust the parameters of a database, but this method has certain limitations when encoding query requests. Summary of the invention
[0004] The present disclosure proposes a query request encoding method, a data query method and related devices to solve or partially solve the above problems.
[0005] In a first aspect, the present disclosure provides a method for encoding a query request, comprising:
[0006] receiving a query request;
[0007] Obtaining a query plan corresponding to the query request, the query plan including a plurality of nodes and connection relationships between the plurality of nodes;
[0008] Encoding the multiple nodes respectively to obtain multiple vectors;
[0009] A target code corresponding to the query request is determined according to the connection relationship between the multiple nodes and the multiple vectors.
[0010] In a second aspect of the present disclosure, a data query method is provided, comprising:
[0011] Receiving a query request for target data, wherein the query request is used to request to query the target data in a target database;
[0012] Using the method described in the first aspect, encoding the query request to obtain a target code corresponding to the query request;
[0013] determining at least one target database parameter of the target database based on the target encoding;
[0014] adjusting at least one database parameter of the target database based on the at least one target database parameter;
[0015] Based on the query request, the target data is queried in the target database after parameter adjustment.
[0016] In a third aspect of the present disclosure, a query request encoding device is provided, comprising:
[0017] The receiving module is configured to: receive a query request;
[0018] An acquisition module is configured to: acquire a query plan corresponding to the query request, wherein the query plan includes a plurality of nodes and connection relationships between the plurality of nodes;
[0019] The encoding module is configured to: encode the multiple nodes respectively to obtain multiple vectors;
[0020] The determination module is configured to determine the target code corresponding to the query request according to the connection relationship between the multiple nodes and the multiple vectors.
[0021] In a fourth aspect of the present disclosure, a data query device is provided, comprising:
[0022] A receiving module is configured to: receive a query request for target data, wherein the query request is used to request to query the target data in a target database;
[0023] The encoding module is configured to: adopt the method described in the first aspect to encode the query request to obtain a target code corresponding to the query request;
[0024] A determination module is configured to: determine at least one target database parameter of the target database based on the target encoding;
[0025] An adjustment module, configured to: adjust at least one database parameter of the target database based on the at least one target database parameter;
[0026] The query module is configured to: based on the query request, query the target data in the target database after parameter adjustment.
[0027] In a fifth aspect of the present disclosure, a computer device is provided, comprising one or more processors, a memory; and one or more programs, wherein the one or more programs are stored in the memory and executed by the one or more processors, and the program includes instructions for executing the method according to the first aspect or the second aspect.
[0028] According to a sixth aspect of the present disclosure, a non-volatile computer-readable storage medium containing a computer program is provided. When the computer program is executed by one or more processors, the processors execute the method described in the first aspect or the second aspect.
[0029] In a seventh aspect of the present disclosure, a computer program product is provided, comprising computer program instructions, which, when executed on a computer, cause the computer to execute the method described in the first aspect or the second aspect.
[0030] The query request encoding method, data query method and related equipment provided by the embodiments of the present disclosure generate multiple vectors based on multiple nodes of the query plan, and combine the connection relationship information between the nodes in the multiple vectors, so that the target encoding can contain richer query information, thereby improving the query accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the present disclosure or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0032] Figure 1 A schematic diagram showing an exemplary system provided by an embodiment of the present disclosure is shown.
[0033] Figure 2A A schematic diagram of an exemplary encoding method provided by an embodiment of the present disclosure is shown.
[0034] Figure 2B A schematic diagram of a process for calculating self-attention encoding according to an embodiment of the present disclosure is shown.
[0035] Figure 3 A flowchart of an exemplary method provided by an embodiment of the present disclosure is shown.
[0036] Figure 4 Another flowchart of an exemplary method provided by an embodiment of the present disclosure is shown.
[0037] Figure 5 A schematic diagram of the hardware structure of an exemplary computer device provided in an embodiment of the present disclosure is shown.
[0038] Figure 6 A schematic diagram of an exemplary device provided by an embodiment of the present disclosure is shown.
[0039] Figure 7 A schematic diagram showing another exemplary device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0040] In order to make the objectives, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.
[0041] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the embodiments of the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. "Including" or "comprising" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0042] It is understandable that before using the technical solutions of each embodiment of the present disclosure, the type, scope of use, usage scenarios, etc. of the personal information involved will be informed to the user in an appropriate manner, and the user's authorization will be obtained.
[0043] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly remind the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can independently choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.
[0044] As an optional but non-limiting implementation, in response to receiving the user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0045] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet relevant laws and regulations may also be applied to the implementation of the present disclosure.
[0046] Figure 1 A schematic diagram of an exemplary system 100 provided by an embodiment of the present disclosure is shown.
[0047] like Figure 1As shown, the system 100 may include a terminal device 102, a terminal device 104, a server 106, and a database server 108. A medium (e.g., a network) providing a communication link may be included between the terminal device 102, the terminal device 104 and the server 106 and the database server 108. The network may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0048] Exemplarily, various applications (APPs) may be installed on the terminal device 104, such as life service applications, collaborative office applications, video conferencing applications, reading applications, video applications, social applications, payment applications, web browsers, and instant messaging tools.
[0049] The terminal device 102 and the terminal device 104 here can be hardware or software. When the terminal device 102 and the terminal device 104 are hardware, they can be various electronic devices with display screens, including but not limited to smart phones, tablet computers, e-book readers, MP3 players, laptop computers (Laptops) and desktop computers (PCs), etc. When the terminal device 102 and the terminal device 104 are software, they can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules (for example, to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0050] The server 106 may be a server that provides various services, such as a background server that provides support for various applications displayed on the terminal devices 102 and 104. The database server 108 may also be a database server that provides various services. It is understood that if the server 106 can implement the relevant functions of the database server 108, the database server 108 may not be set in the system 100.
[0051] Here, the server 106 and the database server 108 can also be hardware or software. When they are hardware, they can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When they are software, they can be implemented as multiple software or software modules (for example, for providing distributed services), or as a single software or software module. No specific limitation is made here.
[0052] It should be understood that Figure 1 The number of terminal devices, users, servers and database servers in the embodiment is only for illustration. Any number of terminal devices, users, servers and database servers may be provided as required.
[0053] As an exemplary scenario, one or more database servers 108 may constitute a database for storing data and searching for corresponding data based on a query request when receiving a query request and then returning the data, etc. For example, a user 112 may use any application of a terminal device 104 to request a service, and the service needs to obtain corresponding data to return to the terminal device 104. At this time, a query request may be generated based on the request of the user 112 and sent to the database for data query. The database queries the corresponding data based on the query request and returns it to the terminal device 104.
[0054] As mentioned above, there are many adjustable system parameters in the database. In the related art, the parameters are usually adjusted by database operation and maintenance personnel based on their own experience (for example, user 110 remotely adjusts the hardware parameters of any database server 108 of the database through terminal device 102), and it may take a lot of time to tune these parameters. This manual parameter adjustment method has low work efficiency, and it is difficult to achieve real-time parameter adjustment, and the system performance is poor.
[0055] As an example, a machine learning method can be used to adjust parameters, which shortens the time required for tuning and improves the quality of tuning.
[0056] For example, this type of parameter adjustment method usually requires encoding the query request as the input of the machine learning model, and then outputting the corresponding parameters for parameter adjustment. In addition, the machine learning model also needs to be trained based on the encoding of historical query requests.
[0057] The inventors of the present disclosure have discovered that in this process, how to encode the query request has a great impact on the quality of parameter adjustment. In particular, the encoding effect of the query request will greatly affect the effect of model learning. If the encoding of the query request is not accurate or effective enough, it will be difficult for the model to accurately learn the relationship between the query, parameters and database performance. In this way, the quality of the final recommended parameters will also be affected. Therefore, the encoding of the query request is a very critical link in the entire parameter adjustment process, which needs to be given sufficient attention and optimization.
[0058] In the related art, some encoding methods based on the text of query requests have obvious limitations. Such methods only encode the text representation of the query request (for example, SQL statement) as a feature vector as the model input, which cannot cover the information of the query execution process, which means that they lack fine-grained effective information. The query execution process involves many key factors, such as the order of execution, the flow of data, and the processing of intermediate results. Without this information, it is difficult for the encoding to fully reflect the actual situation of the query, which may cause the subsequent parameter adjustment process to be inaccurate and ineffective.
[0059] In other related technologies, information such as query operations, table names, and cost information can be encoded together with the query request, but such encoding methods that include query operations, table names, and cost information also have problems. When the query is very complex (for example, it contains multiple nested subqueries), it is difficult for these methods to accurately express the information of the query plan. In complex queries, the query plan usually consists of multiple nodes, and the relationships between these nodes are intricate. The encoding methods of related technologies are difficult to model such complex relationships.
[0060] In view of this, an embodiment of the present disclosure provides a query request encoding method to solve or partially solve the above problem.
[0061] Figure 2A Schematic diagram of an exemplary encoding method 200 provided by an embodiment of the present disclosure is shown. The method 200 can be used to generate a target encoding based on a query request, and the target encoding can be used to train a parameter generation model or used as an input of the parameter generation model to obtain relevant parameters for a database to adjust the database. Optionally, the system 200 can be implemented as Figure 1 The server 106 may be implemented as Figure 1 The server 106 and the database server 108 are connected.
[0062] like Figure 2A As shown, a query request (Query) 202 may be received first. Optionally, the query request 202 may be, for example, a Structured Query Language (SQL) command, which is used to request execution of a corresponding query operation.
[0063] Optionally, the query request 202 can be real-time or historical. The real-time query request can be used for real-time query of data, and the historical query request can be used to train a parameter generation model so that the parameter generation model can be used to generate recommended parameters to adjust the parameters of the database.
[0064] Then, if Figure 2AAs shown, a corresponding query plan (Query Plan) 204 may be obtained based on the query request 202 .
[0065] The query plan 204 is a specific step in the database system for executing the query request 202 (eg, SQL command), which describes in detail how to obtain the required data, including which indexes to use, how to connect tables, the order in which data is read, etc.
[0066] In some embodiments, in a relational database management system (RDBMS), the query plan 204 may be generated by the database management system (DBMS) based on the submitted query request 202 (e.g., SQL command), and is an optimized representation for efficiently accessing, retrieving, and processing data. Alternatively, the query plan 204 may be a product of a query optimizer, which is a component of the RDBMS that is used to build, evaluate, and select the most effective query plan. The query plan 204 generated by the query optimizer may reduce the resource consumption and time required to execute the query, while improving the query speed and accuracy.
[0067] As an optional embodiment, the query plan can be abstracted into multiple nodes (Plan Node), and according to the query steps described in the query plan, these nodes can also have an execution sequence, and this execution sequence can be abstracted as a connection relationship between the nodes.
[0068] In some embodiments, based on the information included in the query plan 204, the query plan 204 can be converted into a directed acyclic graph ( Figure 2A In the tree structure) or tree diagram. Figure 2A As shown, the directed acyclic graph (DAG) is composed of vertices and edges, wherein each edge points from one vertex to another vertex, wherein each vertex corresponds to one node, and the edge represents the connection relationship between the nodes. In this way, the information of the query execution process can be refined based on the directed acyclic graph, and the information can be combined into the target code, so that the target code can contain the relevant information of the query execution process, thereby improving the query accuracy.
[0069] Optionally, an adjacency matrix 210 can be determined based on the directed acyclic graph, and the adjacency matrix 210 is used to indicate the connection relationship between the multiple nodes. When encoding is performed subsequently, the adjacency matrix can be used to mask the pre-coding, and then the connection relationship between the nodes can be incorporated into the encoding to improve the query accuracy.
[0070] Further, after obtaining multiple nodes of the query plan 204, the multiple nodes may be encoded respectively to obtain multiple vectors, for example, vectors 206A to 206E. Figure 2A shown.
[0071] Specifically, each node may be encoded into a vector. Optionally, encoding may be performed based on multiple description information of each node related to the query request 202. Optionally, the multiple description information may include at least one of an operator, a connection, a scan table, a predicate, and a cardinality estimate. In this way, the vector encoded based on the description information may contain more query plan information, thereby improving query accuracy.
[0072] In some embodiments, for each of the nodes, the multiple description information of the node can be converted into multiple one-hot vectors. Taking the case where the operators include three operators A, B, and C, if the operator of the node is A, the one-hot vector corresponding to the operator can be [1,0,0], if the operator of the node is B, the one-hot vector corresponding to the operator can be [0,1,0], and if the operator of the node is C, the one-hot vector corresponding to the operator can be [0,0,1]. In this way, each description information can be encoded into a one-hot vector.
[0073] Next, the multiple one-hot vectors corresponding to each of the nodes may be connected to obtain the vector corresponding to the node. In this way, the vector corresponding to each node is encoded.
[0074] In some embodiments, if the self-attention score corresponding to each node needs to be calculated later, the multiple one-hot vectors can be connected in a predetermined order to obtain the vector corresponding to the node; wherein the predetermined order corresponding to each node is the same. In this way, accuracy can be guaranteed when calculating the self-attention score. It can be understood that the predetermined order of connection can be arbitrary, as long as the connection order of each vector is the same.
[0075] Optionally, after obtaining the multiple vectors corresponding to the multiple nodes, the target code 212 corresponding to the query request 202 may be determined according to the connection relationship between the multiple nodes and the multiple vectors.
[0076] In this way, multiple vectors are generated based on multiple nodes of the query plan, and the connection relationship information between the nodes is combined in the multiple vectors, so that the target code 212 can contain richer query information, which can improve the query accuracy. In particular, this method is suitable for query plans with a large number of nodes and complex relationships between nodes, and the effect of improving accuracy is more obvious.
[0077] The attention mechanism plays a vital role in the field of machine learning. It can be understood as a resource allocation mechanism that enables the model to focus on important parts and ignore less critical content when processing information. In practical applications, when the model handles complex tasks, such as machine translation and text summary generation in natural language processing, or image recognition and target detection in computer vision, the input data often contains a lot of information. The attention mechanism can dynamically calculate the importance weights of different parts according to the current task requirements.
[0078] In order to solve the problem of encoding schemes in related technologies to a certain extent, the query plan is encoded in the form of a vector. Under the premise of specifying the vector size, as much value information as possible is encoded, and a trade-off can be made between encoding information and encoding space.
[0079] Therefore, in some embodiments, Figure 2A As shown, the self-attention module 208 can be used to calculate the self-attention score and obtain the self-attention code. According to the connection relationship between the multiple nodes, the self-attention scores of the multiple vectors can be calculated to obtain multiple self-attention codes corresponding to the multiple nodes, and then the target code corresponding to the query request can be determined according to the multiple self-attention codes. The self-attention mechanism allows the model to automatically focus on different parts of the input according to the attention score when processing data, and assign different weights according to their importance. Unlike the traditional attention mechanism, self-attention mainly focuses on the relationship within the input itself. In this way, through the self-attention mechanism, the long-distance dependency between multiple nodes can be captured, rather than just limited to local contextual information, which is very helpful for understanding complex language structures and semantic relationships. In addition, combined with the connection relationship, the self-attention scores of the nodes with the connection relationship can be introduced into the target code, while enriching the encoding information as much as possible, ensuring the simplicity of the encoding. In addition, the self-attention mechanism can be calculated in parallel, which greatly improves the calculation efficiency. At the same time, it can adaptively learn the relationship between different nodes without manually designing complex feature extractors, which makes the model more flexible and powerful and can better handle various complex tasks and data. In addition, self-attention also provides a certain degree of interpretability for the model. By observing the distribution of attention weights, we can understand the key areas that the model focuses on when processing data.
[0080] In some embodiments, taking any node as a target node as an example, according to the connection relationship between the multiple nodes, the self-attention scores are calculated for the multiple vectors to obtain multiple self-attention codes corresponding to the multiple nodes, such as Figure 2B As shown, the following steps may be further included.
[0081] In step 222, a target node may be first determined among the plurality of nodes, for example, a node corresponding to vector 206A.
[0082] In step 224, a self-attention score between a target vector corresponding to the target node and other vectors in the multiple vectors except the target node may be calculated to obtain a first self-attention score corresponding to the target node.
[0083] In some embodiments, the step 204 of calculating the self-attention scores between the target vector corresponding to the target node and other vectors in the plurality of vectors except the target node to obtain the first self-attention score corresponding to the target node may further include the following steps:
[0084] The multiple vectors are converted into multiple queries, multiple keys, and multiple values, and then a first self-attention score corresponding to the target node is calculated according to the target query and target key of the target vector of the target node and the multiple other queries and multiple other keys of the other vectors.
[0085] Specifically, for an input sequence containing many vectors (e.g., vectors 206A to 206E), the self-attention mechanism can first use three different linear layers to project each vector into a new representation, represented as Q, K, and V, namely query, key, and value, respectively.
[0086] Then, the attention calculation is defined as:
[0087]
[0088] Here, attention is calculated by calculating the correlation score between Q and K, and then multiplied by the normalized value V. is a scaling factor designed to obtain more stable gradients during training. The output is the encoded representation of the input elements. Before normalization (for example, normalization by the softmax function), the matrix form in the brackets can be decomposed, where the unnormalized attention score between any two nodes i and j is given by:
[0089]
[0090] Here, H represents an input vector (eg, vectors 206A-206E), Q represents a query, and K represents a key, that is, a token in the query.
[0091] Therefore, when encoding the target vector, the equation calculates the attention score between the target vector and the other vectors.
[0092] In the related art, these attention scores and the target value V corresponding to the target vector can be used to calculate the weighted sum as the encoding representation of the target vector. However, because there is no data flow between two unconnected nodes. And the attention mechanism itself lacks the ability to capture the internal structural information of the DAG. Therefore, in this embodiment, for a given pair of nodes i and j, the attention score is calculated only when there is an edge connecting the two nodes.
[0093] Therefore, in step 226, the second self-attention score corresponding to the target node can be determined based on the adjacency matrix 210 and the first self-attention score.
[0094] Here, the adjacency matrix 210 is extracted by analyzing the DAG. In the adjacency matrix 210, if node i and node j are connected by an edge, the item bij in the adjacency matrix 210 is set to 1, otherwise it is 0. This matrix is used to mask the attention score, that is, the attention score is equal to Aij multiplied by bij. Therefore, the attention score of any unconnected node pair is set to 0, so that there is no need to perform subsequent calculations based on these attention scores, saving computing resources.
[0095] In step 228, the target self-attention code corresponding to the target node can be determined based on the second self-attention score.
[0096] Here, since the first self-attention score is obtained by masking the adjacency matrix 210, when performing weighted calculation on the target value corresponding to the target vector, the target self-attention code corresponding to the target node can be determined based on the second self-attention score and the target value of the target vector.
[0097] In this way, the above method is used to obtain the self-attention code for the vector corresponding to each node, so that the target code 212 corresponding to the query request 202 can be obtained.
[0098] It can be seen from the above embodiments that the query request encoding method provided by the embodiments of the present disclosure proposes a database query plan encoding scheme based on the Attention mechanism, which can encode information such as the operation type and table name cost of the query plan node, and is suitable for query plans with a large number of nodes and complex relationships between nodes. It can fully encode information about the query execution process and still has a good encoding effect for query plans with a large number of nodes and complex relationships between nodes.
[0099] It should be noted that the method of the embodiment of the present disclosure can be performed by a single device, such as a computer or a server. The method of the present embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present disclosure, and the multiple devices will interact with each other to complete the described method.
[0100] It should be noted that the above describes some embodiments of the present disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0101] The disclosed embodiment also provides a method for encoding query features. Figure 3 FIG. 3 is a flow chart of an exemplary method 300 provided by an embodiment of the present disclosure. The method 300 may be Figure 1 It can be implemented by the server 106, or it can be implemented by the server 106 and the database server 108, or by Figure 1 The system 100 is implemented as Figure 3 As shown, the method 300 may include the following steps.
[0102] In step 302, a query request (e.g., Figure 2A Query request 202);
[0103] In step 304, a query plan corresponding to the query request is obtained (for example, Figure 2A A query plan 204), wherein the query plan includes a plurality of nodes and connection relationships between the plurality of nodes;
[0104] In step 306, the plurality of nodes are encoded respectively to obtain a plurality of vectors (eg, Figure 2A Vectors 206A to 206E);
[0105] In step 308, a target code (eg, Figure 2A target code 212).
[0106] The query request encoding method provided by the embodiment of the present disclosure generates multiple vectors based on multiple nodes of the query plan, and combines the connection relationship information between the nodes in the multiple vectors, so that the target encoding can contain richer query information, which can improve the query accuracy.
[0107] In some embodiments, the node includes a plurality of description information of the node related to the query request;
[0108] Encoding the multiple nodes respectively to obtain multiple vectors includes: for each of the nodes, performing the following steps:
[0109] Convert the plurality of description information of the node into a plurality of one-hot vectors;
[0110] The multiple one-hot vectors are connected to obtain a vector corresponding to the node.
[0111] Thus, by encoding the description information into a one-hot vector, each of the vectors (e.g., Figure 2A The lengths of the vectors 206A-206E) are kept consistent to facilitate subsequent attention score calculation.
[0112] In some embodiments, connecting the multiple one-hot vectors to obtain the vector corresponding to the node includes:
[0113] Connecting the multiple one-hot vectors in a predetermined order to obtain a vector corresponding to the node;
[0114] The predetermined order corresponding to each of the nodes is the same.
[0115] In this way, accuracy can be guaranteed when calculating the self-attention score.
[0116] In some embodiments, the plurality of description information includes at least one of an operator, a connection, a scan table, a predicate, and a cardinality estimate. Thus, the vector encoded based on the description information can contain more query plan information, thereby improving query accuracy.
[0117] In some embodiments, determining the target code corresponding to the query request according to the connection relationship between the multiple nodes and the multiple vectors includes:
[0118] Calculating self-attention scores for the multiple vectors according to the connection relationship between the multiple nodes to obtain multiple self-attention codes corresponding to the multiple nodes;
[0119] Determine a target code corresponding to the query request based on the multiple self-attention codes.
[0120] In this way, multiple vectors are generated based on multiple nodes of the query plan, and the connection relationship information between nodes is combined in multiple vectors, so that the target code can contain richer query information and improve the query accuracy. In particular, this method is suitable for query plans with a large number of nodes and complex relationships between nodes, and the effect of improving accuracy is more obvious.
[0121] In some embodiments, obtaining a query plan corresponding to the query request further includes:
[0122] Convert the query plan to a directed acyclic graph (refer to Figure 2A As shown), the directed acyclic graph includes the multiple nodes;
[0123] According to the directed acyclic graph, an adjacency matrix (eg, Figure 2A An adjacency matrix 210) is used to indicate the connection relationship between the multiple nodes.
[0124] In this way, the information of the query execution process can be refined based on the directed acyclic graph, and the information can be incorporated into the target code, so that the target code can contain relevant information of the query execution process, thereby improving the query accuracy. In the subsequent encoding, the adjacency matrix can be used to mask the pre-coding, and then the connection relationship between nodes can be incorporated into the coding to improve the query accuracy.
[0125] In some embodiments, according to the connection relationship between the multiple nodes, calculating the self-attention scores for the multiple vectors to obtain multiple self-attention codes corresponding to the multiple nodes includes:
[0126] determining a target node among the plurality of nodes;
[0127] Calculate the self-attention scores between the target vector corresponding to the target node and other vectors in the multiple vectors except the target node, to obtain a first self-attention score corresponding to the target node;
[0128] Determine a second self-attention score corresponding to the target node according to the adjacency matrix and the first self-attention score;
[0129] According to the second self-attention score, determine the target self-attention code corresponding to the target node.
[0130] In this way, the adjacency matrix is used to mask the attention scores, and the attention scores of any unconnected node pairs are set to 0, so that there is no need to perform subsequent calculations based on these attention scores, saving computing resources.
[0131] In some embodiments, calculating the self-attention scores between the target vector corresponding to the target node and other vectors in the plurality of vectors except the target node to obtain a first self-attention score corresponding to the target node includes:
[0132] converting the plurality of vectors into a plurality of queries, a plurality of keys, and a plurality of values;
[0133] Calculate a first self-attention score corresponding to the target node according to the target query and the target key of the target vector of the target node and multiple other queries and multiple other keys of the other vectors.
[0134] The self-attention mechanism allows the model to automatically focus on different parts of the input according to the attention score when processing data, and assign different weights according to their importance. Unlike traditional attention mechanisms, self-attention focuses on the relationship within the input itself. In this way, through the self-attention mechanism, long-distance dependencies between multiple nodes can be captured, rather than just limited to local contextual information, which is very helpful for understanding complex language structures and semantic relationships. In addition, combined with the connection relationship, the self-attention scores of nodes with connection relationships can be introduced into the target encoding, while enriching the encoding information as much as possible, ensuring the simplicity of the encoding. In addition, the self-attention mechanism can be calculated in parallel, greatly improving the computational efficiency. At the same time, it can adaptively learn the relationship between different nodes without manually designing complex feature extractors, which makes the model more flexible and powerful, and can better handle various complex tasks and data. In addition, self-attention also provides a certain degree of interpretability for the model. By observing the distribution of attention weights, we can understand the key areas that the model focuses on when processing data.
[0135] In some embodiments, determining a target self-attention code corresponding to the target node according to the second self-attention score includes:
[0136] Determine a target self-attention code corresponding to the target node according to the second self-attention score and the target value of the target vector.
[0137] Since the second self-attention score is obtained by processing the first self-attention score through the adjacency matrix mask, when performing weighted calculation on the target value corresponding to the target vector, the target self-attention code corresponding to the target node can be determined based on the second self-attention score and the target value of the target vector, which reduces the amount of calculation, saves resources, and improves calculation efficiency.
[0138] It should be noted that the method of the embodiment of the present disclosure can be performed by a single device, such as a computer or a server. The method of the present embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present disclosure, and the multiple devices will interact with each other to complete the described method.
[0139] It should be noted that the above describes some embodiments of the present disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0140] The disclosed embodiment also provides a data query method. Figure 4 FIG. 4 is a flow chart of an exemplary method 400 provided in an embodiment of the present disclosure. The method 400 may be Figure 1 It can be implemented by the server 106, or it can be implemented by the server 106 and the database server 108, or by Figure 1 The system 100 is implemented as Figure 4 As shown, the method 400 may include the following steps.
[0141] At step 402, a query request for target data is received (e.g., Figure 2A A query request 202 is provided, wherein the query request is used to request to query the target data in the target database.
[0142] In step 404, any embodiment or permutation or combination of the method 300 is used to encode the query request to obtain a target code corresponding to the query request (e.g., Figure 2A target code 212).
[0143] In step 406, based on the target code, the target database (e.g., Figure 1 at least one target database parameter of a database provided by the database server 108.
[0144] At step 408, at least one database parameter of the target database is adjusted based on the at least one target database parameter.
[0145] In step 410, based on the query request, the target data is queried in the target database after parameter adjustment.
[0146] The data query method provided by the embodiment of the present disclosure generates multiple vectors based on multiple nodes of the query plan, and combines the connection relationship information between the nodes in the multiple vectors, so that the target code can contain richer query information, which can improve the query accuracy.
[0147] In some embodiments, based on the target code, determining at least one target database parameter of the target database includes: inputting the target code into a parameter generation model, and outputting at least one target database parameter of the target database. Since the target code contains richer query information, the parameter generation model can output more accurate target database parameters, and thus after adjusting the parameters of the target database, the query accuracy can be improved.
[0148] Optionally, the parameter generation model can also be pre-trained, and the pre-trained training data can be a plurality of codes for training obtained by encoding a plurality of historical query requests using any embodiment or arrangement or combination of the method 300, and the codes are used together with the database parameters corresponding to the historical query requests as training data. The initial model is then trained using the training data to obtain the parameter generation model. In this way, the model obtained by training the plurality of codes for training obtained by encoding a plurality of historical query requests using any embodiment or arrangement or combination of the method 300 can make the output database parameters more matched with the query request and improve the query accuracy. It can be understood that the parameter generation model can be any machine learning model, such as a neural network model, a deep neural network model, a reinforcement learning model, a deep reinforcement learning model, and the like.
[0149] The embodiment of the present disclosure further provides a computer device for implementing the above method 300 or method 400. Figure 5 FIG. 5 is a schematic diagram showing the hardware structure of an exemplary computer device 500 provided in an embodiment of the present disclosure. The computer device 500 can be used to implement Figure 1 The server 106 can also be used to implement Figure 1 In some scenarios, the computer device 500 can also be used to implement Figure 1 The database server 108.
[0150] like Figure 5 As shown, the computer device 500 may include: a processor 502, a memory 504, a network module 506, a peripheral interface 508 and a bus 510. The processor 502, the memory 504, the network module 506 and the peripheral interface 508 are connected to each other in communication within the computer device 500 through the bus 510.
[0151] Processor 502 may be a central processing unit (CPU), an image processor, a neural network processor (NPU), a microcontroller (MCU), a programmable logic device, a digital signal processor (DSP), an application specific integrated circuit (ASIC), or one or more integrated circuits. Processor 502 may be used to perform functions related to the technology described in this disclosure. In some embodiments, processor 502 may also include multiple processors integrated into a single logical component. For example, Figure 5 As shown, processor 502 may include a plurality of processors 502a, 502b, and 502c.
[0152] The memory 504 may be configured to store data (eg, instructions, computer code, etc.). Figure 5 As shown, the data stored in the memory 504 may include program instructions (e.g., program instructions for implementing the method 300 or method 400 of the embodiment of the present disclosure) and data to be processed (e.g., the memory may store configuration files of other modules, etc.). The processor 502 may also access the program instructions and data stored in the memory 504, and execute the program instructions to operate on the data to be processed. The memory 504 may include a volatile storage device or a non-volatile storage device. In some embodiments, the memory 504 may include a random access memory (RAM), a read-only memory (ROM), an optical disk, a magnetic disk, a hard disk, a solid-state drive (SSD), a flash memory, a memory stick, etc.
[0153] The network interface 506 can be configured to provide the computer device 500 with communication with other external devices via a network. The network can be any wired or wireless network capable of transmitting and receiving data. For example, the network can be a wired network, a local wireless network (e.g., Bluetooth, WiFi, near field communication (NFC)), a cellular network, the Internet, or a combination thereof. It is understood that the type of network is not limited to the above specific examples.
[0154] The peripheral interface 508 can be configured to connect the computer device 500 to one or more peripheral devices to achieve information input and output. For example, the peripheral devices can include input devices such as a keyboard, a mouse, a touch pad, a touch screen, a microphone, and various sensors, and output devices such as a display, a speaker, a vibrator, and an indicator light.
[0155] The bus 510 may be configured to transmit information between various components of the computer device 500 (e.g., the processor 502, the memory 504, the network interface 506, and the peripheral interface 508), such as an internal bus (e.g., a processor-memory bus), an external bus (USB port, PCI-E bus), etc.
[0156] It should be noted that, although the architecture of the above-mentioned computer device 500 only shows the processor 502, the memory 504, the network interface 506, the peripheral interface 508 and the bus 510, in the specific implementation process, the architecture of the computer device 500 may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the architecture of the above-mentioned computer device 500 may also only include the components necessary for implementing the embodiments of the present disclosure, and does not necessarily include all the components shown in the figure.
[0157] The disclosed embodiment also provides a query request encoding device. Figure 6 FIG. 6 is a schematic diagram of an exemplary device 600 provided by an embodiment of the present disclosure. Figure 6 As shown, the device 600 can be used to implement the method 300 and can further include the following modules.
[0158] The receiving module 602 is configured to: receive a query request;
[0159] The acquisition module 604 is configured to: acquire a query plan corresponding to the query request, wherein the query plan includes a plurality of nodes and connection relationships between the plurality of nodes;
[0160] The encoding module 606 is configured to: encode the multiple nodes respectively to obtain multiple vectors;
[0161] The determination module 608 is configured to determine a target code corresponding to the query request according to the connection relationship between the multiple nodes and the multiple vectors.
[0162] In some embodiments, the node includes a plurality of description information of the node related to the query request;
[0163] The encoding module 606 is configured to:
[0164] For each of the nodes, perform the following steps:
[0165] Convert the plurality of description information of the node into a plurality of one-hot vectors;
[0166] The multiple one-hot vectors are connected to obtain a vector corresponding to the node.
[0167] In some embodiments, the encoding module 606 is configured to:
[0168] Connecting the multiple one-hot vectors in a predetermined order to obtain a vector corresponding to the node;
[0169] The predetermined order corresponding to each of the nodes is the same.
[0170] In some embodiments, the plurality of description information includes at least one of an operator, a join, a scan table, a predicate, and a cardinality estimate.
[0171] In some embodiments, the determination module 608 is configured to:
[0172] Calculating self-attention scores for the multiple vectors according to the connection relationship between the multiple nodes to obtain multiple self-attention codes corresponding to the multiple nodes;
[0173] Determine a target code corresponding to the query request based on the multiple self-attention codes.
[0174] In some embodiments, the acquisition module 604 is configured to:
[0175] Converting the query plan into a directed acyclic graph, wherein the directed acyclic graph includes the plurality of nodes;
[0176] An adjacency matrix is determined according to the directed acyclic graph, where the adjacency matrix is used to indicate connection relationships between the multiple nodes.
[0177] In some embodiments, the determination module 608 is configured to:
[0178] Determining a target node among the plurality of nodes;
[0179] Calculate the self-attention scores between the target vector corresponding to the target node and other vectors in the multiple vectors except the target node, to obtain a first self-attention score corresponding to the target node;
[0180] Determine a second self-attention score corresponding to the target node according to the adjacency matrix and the first self-attention score;
[0181] According to the second self-attention score, determine the target self-attention code corresponding to the target node.
[0182] In some embodiments, the determination module 608 is configured to:
[0183] converting the plurality of vectors into a plurality of queries, a plurality of keys, and a plurality of values;
[0184] Calculate a first self-attention score corresponding to the target node according to the target query and the target key of the target vector of the target node and multiple other queries and multiple other keys of the other vectors.
[0185] In some embodiments, the determination module 608 is configured to:
[0186] Determine a target self-attention code corresponding to the target node according to the second self-attention score and the target value of the target vector.
[0187] For the convenience of description, the above device is described by dividing it into various modules according to its functions. Of course, when implementing the present disclosure, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0188] The device of the above embodiment is used to implement the corresponding method 300 in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.
[0189] The disclosed embodiment also provides a data query device. Figure 7 FIG. 7 is a schematic diagram of an exemplary device 700 provided by an embodiment of the present disclosure. Figure 7 As shown, the device 700 can be used to implement the method 400, and can further include the following modules.
[0190] The receiving module 702 is configured to: receive a query request for target data, wherein the query request is used to request to query the target data in a target database;
[0191] The encoding module 704 is configured to: adopt any embodiment or arrangement or combination of the embodiments of the method 300 to encode the query request to obtain a target code corresponding to the query request;
[0192] The determination module 706 is configured to: determine at least one target database parameter of the target database based on the target encoding;
[0193] The adjustment module 708 is configured to: adjust at least one database parameter of the target database based on the at least one target database parameter;
[0194] The query module 710 is configured to query the target data in the target database after parameter adjustment based on the query request.
[0195] In some embodiments, the determination module 706 is configured to: generate a model by inputting the target encoding parameters, and output at least one target database parameter of the target database.
[0196] For the convenience of description, the above device is described by dividing it into various modules according to its functions. Of course, when implementing the present disclosure, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0197] The device of the above embodiment is used to implement the corresponding method 400 in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.
[0198] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute method 300 or method 400 as described in any of the above embodiments.
[0199] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0200] The computer instructions stored in the storage medium of the above embodiments are used to enable the computer to execute method 300 or method 400 as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0201] Based on the same inventive concept, corresponding to the method 300 or the method 400 in any of the above embodiments, the present disclosure further provides a computer program product, which includes a computer program. In some embodiments, the computer program is executable by one or more processors so that the processors execute the method 300 or the method 400. Corresponding to the execution subject corresponding to each step in each embodiment of the method 300 or the method 400, the processor that executes the corresponding step may belong to the corresponding execution subject.
[0202] The computer program product of the above embodiment is used to enable the processor to execute method 300 or method 400 as described in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be described in detail here.
[0203] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present disclosure (including the claims) is limited to these examples. Based on the concept of the present disclosure, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present disclosure as described above, which are not provided in detail for the sake of simplicity.
[0204] In addition, to simplify the description and discussion, and in order not to make the embodiments of the present disclosure difficult to understand, the known power / ground connections to the integrated circuit (IC) chips and other components may or may not be shown in the provided figures. In addition, the device can be shown in the form of a block diagram to avoid making the embodiments of the present disclosure difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform on which the embodiments of the present disclosure will be implemented (that is, these details should be fully within the scope of understanding of those skilled in the art). Where specific details (e.g., circuits) are set forth to describe exemplary embodiments of the present disclosure, it is apparent to those skilled in the art that the embodiments of the present disclosure can be implemented without these specific details or with changes in these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.
[0205] Although the present disclosure has been described in conjunction with specific embodiments of the present disclosure, many replacements, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.
[0206] The embodiments of the present disclosure are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present disclosure should be included in the scope of protection of the present disclosure.
Claims
1. A method for encoding a query request, comprising: receiving a query request; Obtaining a query plan corresponding to the query request, the query plan including a plurality of nodes and connection relationships between the plurality of nodes; Encoding the multiple nodes respectively to obtain multiple vectors; A target code corresponding to the query request is determined according to the connection relationship between the multiple nodes and the multiple vectors.
2. The method of claim 1, wherein: The node includes a plurality of description information of the node related to the query request; Encoding the multiple nodes respectively to obtain multiple vectors includes: for each of the nodes, performing the following steps: Convert the plurality of description information of the node into a plurality of one-hot vectors; The multiple one-hot vectors are connected to obtain a vector corresponding to the node.
3. The method of claim 2, wherein: Connecting the multiple one-hot vectors to obtain a vector corresponding to the node includes: Connecting the multiple one-hot vectors in a predetermined order to obtain a vector corresponding to the node; The predetermined order corresponding to each of the nodes is the same.
4. The method of claim 2, wherein: The plurality of description information includes at least one of an operator, a connection, a scan table, a predicate, and a cardinality estimate.
5. The method of claim 2, wherein: Determining a target code corresponding to the query request according to the connection relationship between the multiple nodes and the multiple vectors includes: Calculating self-attention scores for the multiple vectors according to the connection relationship between the multiple nodes to obtain multiple self-attention codes corresponding to the multiple nodes; Determine a target code corresponding to the query request based on the multiple self-attention codes.
6. The method of claim 5, wherein: Obtaining a query plan corresponding to the query request further includes: Converting the query plan into a directed acyclic graph, wherein the directed acyclic graph includes the plurality of nodes; An adjacency matrix is determined according to the directed acyclic graph, where the adjacency matrix is used to indicate connection relationships between the multiple nodes.
7. The method of claim 6, wherein: Calculating self-attention scores for the multiple vectors according to the connection relationship between the multiple nodes to obtain multiple self-attention codes corresponding to the multiple nodes includes: determining a target node among the plurality of nodes; Calculate the self-attention scores between the target vector corresponding to the target node and other vectors in the multiple vectors except the target node, to obtain a first self-attention score corresponding to the target node; Determine a second self-attention score corresponding to the target node according to the adjacency matrix and the first self-attention score; According to the second self-attention score, determine the target self-attention code corresponding to the target node.
8. The method of claim 7, wherein: Calculating the self-attention scores between the target vector corresponding to the target node and other vectors in the multiple vectors except the target node to obtain a first self-attention score corresponding to the target node, including: converting the plurality of vectors into a plurality of queries, a plurality of keys, and a plurality of values; Calculate a first self-attention score corresponding to the target node according to the target query and the target key of the target vector of the target node and multiple other queries and multiple other keys of the other vectors.
9. The method of claim 8, wherein: Determining a target self-attention code corresponding to the target node according to the second self-attention score includes: Determine a target self-attention code corresponding to the target node according to the second self-attention score and the target value of the target vector.
10. A data query method, comprising: Receiving a query request for target data, wherein the query request is used to request to query the target data in a target database; Using the method according to any one of claims 1 to 9, encoding the query request to obtain a target code corresponding to the query request; determining at least one target database parameter of the target database based on the target encoding; adjusting at least one database parameter of the target database based on the at least one target database parameter; Based on the query request, the target data is queried in the target database after parameter adjustment.
11. The method of claim 10, wherein: Determining at least one target database parameter of the target database based on the target encoding includes: The target encoding is input into a parameter generation model, and at least one target database parameter of the target database is output.
12. An encoding device for a query request, comprising: The receiving module is configured to: receive a query request; An acquisition module is configured to: acquire a query plan corresponding to the query request, wherein the query plan includes a plurality of nodes and connection relationships between the plurality of nodes; The encoding module is configured to: encode the multiple nodes respectively to obtain multiple vectors; The determination module is configured to determine the target code corresponding to the query request according to the connection relationship between the multiple nodes and the multiple vectors.
13. A data query device, comprising: A receiving module is configured to: receive a query request for target data, wherein the query request is used to request to query the target data in a target database; The encoding module is configured to: adopt the method according to any one of claims 1 to 9 to encode the query request to obtain a target code corresponding to the query request; A determination module is configured to: determine at least one target database parameter of the target database based on the target encoding; An adjustment module, configured to: adjust at least one database parameter of the target database based on the at least one target database parameter; The query module is configured to: based on the query request, query the target data in the target database after parameter adjustment.
14. A computer device comprising one or more processors, a memory; and one or more programs, wherein the one or more programs are stored in the memory and executed by the one or more processors, and the programs include instructions for executing the method according to any one of claims 1 to 9 or the method according to claim 10 or 11.
15. A non-volatile computer-readable storage medium containing a computer program, which, when executed by one or more processors, causes the processors to perform the method of any one of claims 1 to 9 or the method of claim 10 or 11.
16. A computer program product, comprising computer program instructions, which, when executed on a computer, cause the computer to execute the method according to any one of claims 1 to 9 or the method according to claim 10 or 11.
Citation Information
Patent Citations
Video clip search method and system oriented to open domain query
CN115687687A
Data query method and query prediction model training method
CN116108072A
Data query method and device, terminal equipment and storage medium
CN116775724A
Sequencing method and device for search recommendation words and electronic equipment
CN117874354A
Reading sequence extraction method and device, computer readable storage medium and system
CN118334688A