Method, apparatus and device for determining time consumption of structured query language statement
By constructing the topological structure and vector transformation of SQL statements, the problem of being unable to predict the execution time of SQL statements is solved, and the effect of optimizing and predicting the time consumption of SQL statements in advance is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA UNITED NETWORK COMM GRP CO LTD
- Filing Date
- 2023-09-18
- Publication Date
- 2026-04-21
AI Technical Summary
Current technology cannot predict the execution time of unexecuted SQL statements, making it impossible to optimize slow query statements in advance.
By constructing the topological structure of SQL statements and converting it into vectors, the time taken for unexecuted SQL statements can be predicted using the reference vectors and execution times of existing SQL nodes.
It enables the prediction of SQL statement execution time before execution, facilitating early optimization and reducing the execution time of slow queries.
Smart Images

Figure CN117235103B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data and data processing technology, and in particular to a method, apparatus and device for determining the time consumption of a structured query language statement. Background Technology
[0002] Network services generate large amounts of digital data, which needs to be stored in a database for later retrieval and processing. When retrieving data from the database, SQL (Structured Query Language) statements are typically used to extract the data.
[0003] Currently, the query speed of SQL statements varies in existing technologies. Some SQL statements are slow to query, so it is necessary to enable the slow query function and have a slow query log to find these slow SQL statements for optimization.
[0004] However, the inventors have discovered that the existing technology has at least the following technical problem: the current technology cannot predict the execution time of unexecuted SQL statements. Summary of the Invention
[0005] This application provides a method, apparatus, and device for determining the execution time of Structured Query Language statements, in order to solve the problem of being unable to predict the execution time of unexecuted SQL statements.
[0006] In a first aspect, this application provides a method for determining the time consumption of a Structured Query Language (SQL) statement, comprising: receiving a target SQL statement sent by a terminal device; obtaining a target table corresponding to the target SQL statement; obtaining a topology structure corresponding to the target table, the topology structure including at least one existing SQL node, wherein the existing SQL node has a corresponding reference vector and a reference time consumption; calculating a target vector corresponding to the target SQL statement; and determining the target time consumption of the target SQL statement based on the target vector and the reference vector and reference time consumption of the existing SQL node.
[0007] In one possible implementation, there are existing SQL nodes, including an origin node and at least one branch node, with the origin node associated with at least one branch node. Accordingly, based on the target vector and the reference vector and reference time corresponding to the existing SQL node, the target time of the target SQL statement is determined, including: identifying the branch node associated with the origin node as the target branch node; calculating a first distance between the target vector and the origin node based on the target vector and the reference vector of the origin node; calculating a second distance between the target vector and any target branch node based on the target vector and the reference vector of any target branch node; if the first distance is less than each of the second distances, then the origin node is determined as a reference node; if any second distance is less than the first distance and less than the other second distances, then the target branch node corresponding to any second distance is determined as a new origin node, and the steps of determining the target branch node and comparing the first and second distances are repeated until the new origin node is not associated with any new branch node, and the finally determined new origin node is determined as a reference node, or until a reference node is determined; the reference time corresponding to the reference node is used to determine the target time.
[0008] In one possible implementation, the target time of the target SQL statement is determined based on the target vector and the reference vectors and reference times corresponding to the existing SQL nodes. This includes: calculating the distance between the target vector and the reference vectors of each existing SQL node; determining the existing SQL node closest to the target vector as the reference node; and determining the reference time corresponding to the reference node as the target time.
[0009] In one possible implementation, before obtaining the topology corresponding to the target table, the method further includes: obtaining a slow query log; reading the slow query SQL statements, their execution times, and the tables corresponding to them from the slow query log; calculating the vector corresponding to each slow query SQL statement; determining the slow query SQL statements for each table based on the tables corresponding to the slow query SQL statements; and determining the topology corresponding to any table based on the vector of the slow query SQL statements for any table.
[0010] In one possible implementation, the topology of any table is determined based on the vector of slow query SQL statements corresponding to that table. This includes: obtaining the number of slow query SQL statements corresponding to any table; if the number of slow query SQL statements is less than or equal to a preset threshold, creating a star topology based on the vector of all slow query SQL statements corresponding to any table; if the number of slow query SQL statements is greater than the preset threshold, clustering all slow query SQL statements corresponding to any table based on the vector of all slow query SQL statements corresponding to that table to obtain multiple statement classes; calculating the distance between slow query SQL statements in each statement class based on the vector of each slow query SQL statement; and creating a fully connected topology based on the distance between slow query SQL statements in each statement class.
[0011] In one possible implementation, a fully connected topology is created based on the distance between slow query SQL statements in each statement class. This includes: determining the target slow query SQL statement in the target statement class as the origin node, with the coordinates of the origin node being the vector corresponding to the target slow query SQL statement; the target statement class being any statement class and the target slow query SQL statement being any slow query SQL statement; determining the slow query SQL statements other than the target slow query SQL statement in the target statement class as branch nodes, with the coordinates of the branch nodes being the corresponding vectors; determining the branch nodes whose distance from the origin node is less than a preset distance as nodes to be associated; associating the nodes to be associated with the origin node; determining the nodes to be associated with as the new origin node, determining the statement class to which the new origin node belongs as the new target statement class, and re-executing the steps of determining the nodes to be associated and associating the nodes to be associated with the origin node using the new origin node and the new target statement class, until all slow query SQL statements in each statement class are traversed to obtain the fully connected topology.
[0012] In one possible implementation, after calculating the target vector corresponding to the target SQL statement, the method further includes: determining the nearest neighbor node to the target SQL statement based on the target vector and the topology; executing the target SQL statement to obtain its execution time; identifying the target SQL statement as a new node; associating the new node with its neighbor nodes; and establishing a mapping relationship between the new node and its execution time.
[0013] Secondly, this application provides a structured query language (SQL) statement time determination device, comprising: a statement receiving module for receiving a target SQL statement sent by a terminal device; a target table acquisition module for acquiring the target table corresponding to the target SQL statement; a structure acquisition module for acquiring the topology structure corresponding to the target table, the topology structure including at least one existing SQL node, wherein the existing SQL node has a corresponding reference vector and reference time; a vector calculation module for calculating the target vector corresponding to the target SQL statement; and a time determination module for determining the target time of the target SQL statement based on the target vector and the reference vector and reference time corresponding to the existing SQL node.
[0014] Thirdly, this application provides an electronic device, including: a processor and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, causing the processor to execute the method for determining the time consumption of a structured query language statement as described in the first aspect.
[0015] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method for determining the time consumption of a structured query language statement as described in the first aspect.
[0016] The method, apparatus, and device for determining the execution time of a Structured Query Language (SQL) statement provided in this application receive a target SQL statement sent by a terminal device, obtain the table corresponding to the target SQL statement, find the corresponding topology from the table, convert the target SQL statement into a vector to obtain a target vector, and determine the target execution time of the target SQL statement by using the target vector, the reference vector corresponding to the existing SQL node in the topology, and the reference execution time. This allows the expected execution time of the SQL statement to be obtained before it is executed, facilitating adjustments to the SQL statement when the expected execution time is long. Attached Figure Description
[0017] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0018] Figure 1 A schematic diagram illustrating an application scenario for the method for determining the time consumption of a structured query language statement provided in this application embodiment;
[0019] Figure 2 A flowchart illustrating the method for determining the time consumption of a structured query language statement provided in this application embodiment;
[0020] Figure 3 This is a schematic diagram of the topology provided in an embodiment of this application;
[0021] Figure 4 This is a schematic diagram of the overall process of the method for determining the time consumption of a structured query language statement provided in the embodiments of this application;
[0022] Figure 5 This is a schematic diagram of the structure of the device for determining the time consumption of a structured query language statement provided in the embodiments of this application;
[0023] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0024] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation
[0025] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0026] As network service technologies mature, a large number of services are conducted via the network, generating a massive amount of digital data, which is typically stored in databases.
[0027] When data needs to be read and processed, SQL statements are typically used for data extraction and processing. Different SQL statements have different execution times, and some SQL statements take too long and require adjustment. Currently, checking whether the execution time of SQL statements is too long usually involves enabling slow query functionality to record the execution time of each SQL statement. This allows for analysis of the SQL execution time during or after execution, identifying SQL statements that need optimization. However, this method cannot predict the execution time of SQL statements before they are executed.
[0028] To address the aforementioned technical problems, the inventors propose the following technical concept: by constructing a topological structure of already executed SQL statements, the target SQL statements that need to be traversed or whose execution time needs to be determined are converted into target vectors. The target vectors are used to find similar existing SQL nodes in the topological structure, and the time consumption corresponding to the similar existing SQL nodes is used as the expected time consumption of the target SQL statement.
[0029] Figure 1This is a schematic diagram illustrating an application scenario for the method for determining the time consumption of a structured query language statement provided in this application embodiment. For example... Figure 1 In this scenario, the components include: terminal device 101, server 102, and database 103.
[0030] In the specific implementation process, the terminal device 101 may include computers, servers, tablets, mobile phones, PDAs (personal digital assistants), and laptops, etc. They can input and send data, and in some possible cases, they can also output data.
[0031] Server 102 can be implemented using a single server or a cluster of multiple servers with more powerful processing capabilities and higher security. Where possible, it can also be replaced by a computer or laptop with strong computing power.
[0032] Database 103 can include a single database or a combination of multiple databases. For example, it can include one or more databases such as Oracle, MySQL, DRDS (Distributed Relational Database Service), and ES (Elasticsearch). This application does not impose any special restrictions on it.
[0033] Terminal device 101 is used to receive instructions input by the user, which may be input information or information obtained by touch, etc., to obtain the target SQL statement, and send the target SQL statement to server 102. Server 102 is used to read the topology structure corresponding to the target SQL statement in the database, and use the obtained topology structure to determine the reference node corresponding to the target SQL statement in the topology structure, and determine the reference time corresponding to the reference node as the target time corresponding to the target SQL statement.
[0034] It is understood that the structure illustrated in the embodiments of this application does not constitute a specific limitation on the method for determining the time consumption of Structured Query Language statements. In other feasible embodiments of this application, the above architecture may include more or fewer components than illustrated, or combine some components, or split some components, or arrange different components, which can be determined according to the actual application scenario and is not limited here. Figure 1 The components shown can be implemented by hardware, software, or a combination of both.
[0035] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0036] Figure 2 This is a flowchart illustrating the method for determining the time consumption of a Structured Query Language statement provided in this application embodiment. The execution entity of this application embodiment can be... Figure 1 The server 102 in this embodiment can also be a computer and / or a mobile phone, etc., and this embodiment does not impose any special restrictions on it. Figure 2 As shown, the method includes:
[0037] S201: Receive the target Structured Query Language (SQL) statement sent by the terminal device.
[0038] In this step, the terminal device can send the target SQL statement to the server using methods such as messages, command lines, data tables, or strings.
[0039] S202: Retrieve the target table corresponding to the target SQL statement.
[0040] In this step, you can either read fields at preset positions in the target SQL statement to obtain the target table corresponding to the target SQL statement, or read fields after preset fields in the target SQL statement to obtain the target table corresponding to the target SQL statement, or use preset programs, commands, or scripts to find the target table corresponding to the target SQL statement.
[0041] S203: Obtain the topology structure corresponding to the target table. The topology structure includes at least one existing SQL node, where the existing SQL node has a corresponding reference vector and reference time.
[0042] In this step, the corresponding topology identifier can be found based on the identifier of the target table, and the corresponding topology can be read from the topology identifier.
[0043] The correspondence between table identifiers and topology structures can be stored using formats such as tables or key-value pairs. The topology structure can be the relationships between existing SQL nodes. Each existing SQL node corresponds to a reference vector and a reference time. The reference vector is obtained by converting the SQL statement of the existing SQL node, and the coordinates of the existing node can be represented using the corresponding reference vector.
[0044] S204: Calculate the target vector corresponding to the target SQL statement.
[0045] In this step, a preset program or algorithm can be used to calculate the vector of the target SQL statement. The number of dimensions of the calculated target vector can be preset by the staff and is the same as the dimension of the reference vector in the topology structure in step S203 above.
[0046] The preset program can be a continuous bag-of-words model of word2vec, a doc2vec model, etc.
[0047] S205: Determine the target time of the target SQL statement based on the target vector and the reference vector and reference time corresponding to the existing SQL node.
[0048] In this step, one approach is to determine the existing SQL node closest to the target vector based on the target vector and each reference vector, and then use the reference time of the closest SQL node as the target time of the target SQL statement. Alternatively, one approach is to find the N existing SQL nodes closest to the target vector based on the target vector and each reference vector, calculate the average of the reference times corresponding to these N existing SQL nodes, and use the average value as the target time, where N is a positive integer.
[0049] For example, if there are 100 existing SQL nodes, and each existing SQL node corresponds to a reference vector, and the target vector is closest to the existing SQL node F, then the reference time corresponding to the existing SQL node F will be used as the target time.
[0050] As can be seen from the description of the above embodiments, the embodiments of this application obtain the table corresponding to the target SQL statement by receiving the target SQL statement sent by the terminal device, thereby finding the corresponding topology structure from the table, converting the target SQL statement into a vector to obtain the target vector, and determining the target time of the target SQL statement by the target vector, the reference vector corresponding to the existing SQL node in the topology structure, and the reference time, thereby realizing that the expected running time of the SQL statement can be obtained before running the SQL statement, which is convenient for adjusting the SQL statement when the expected running time is long.
[0051] In one possible implementation, in step S205 above, there are existing SQL nodes, including entry nodes and branch nodes. Accordingly, based on the target vector and the reference vectors and reference times corresponding to the existing SQL nodes, the target time of the target SQL statement is determined, including: performing a full traversal calculation to find the closest node, or maintaining an approximate queue and sequentially traversing its neighboring nodes to find the node closest to the SQL statement to be tested. The approximate queue is a queue from the entry node to the connected remote branch nodes. The reference time of the closest existing SQL node is determined as the target time.
[0052] In one possible implementation, if a new SQL statement needs to be added to the topology, the vector of the new SQL statement is calculated, and the vector is used as the coordinates of the new node corresponding to the new SQL statement. The nearest neighbor node (the nearest existing SQL node) is found, and the new node is attached to the neighbor node (connecting or associating the new node with the neighbor node). A mapping relationship between the new node and the corresponding execution time is constructed.
[0053] Figure 3 This is a schematic diagram of the topology provided for an embodiment of this application. For example... Figure 3 As shown, in Figure 3 The left side shows a star-shaped graph structure, composed of a relatively small number of existing SQL nodes. Figure 3 The right side is a fully connected topology, consisting of a large number of existing SQL nodes.
[0054] Both types of topologies can be predetermined using existing data. The number of data points (fewer and more) can be determined by pre-set data volume thresholds. The topology can be stored as a table, array, or queue. For example, if node A is associated with nodes B, C, D, E, and F, it can be stored as "[A, B, C, D, E, F]" or "[A, B, C, D, E, F]", etc. If node B is also associated with nodes G and H, then the association relationship of node B can also be stored as "[B, G, H]".
[0055] In one possible implementation, there is an existing SQL node, including an origin node and at least one branch node, with the origin node associated with at least one branch node.
[0056] Wherein, the original node can be Figure 3 The nodes drawn with dashed lines in the diagram can be branch nodes. Figure 3 Nodes are drawn with solid lines. Origin nodes and branch nodes can be determined when creating the topology. The origin node is also referred to as the entry node above.
[0057] Accordingly, in step S205 above, the target time of the target SQL statement is determined based on the target vector and the reference vector and reference time corresponding to the existing SQL node, including:
[0058] S205A1: Determine the branch node associated with the origin node as the target branch node.
[0059] In this step, the branch node associated with the origin node can be... Figure 3 A branch node that is connected to the origin node, or a branch node that is associated with the origin node obtained by finding the relationship between the origin node and the origin node.
[0060] S205A2: Calculate the first distance between the target vector and the origin node based on the target vector and the reference vector of the origin node.
[0061] In this step, the distance between the target vector and the reference vector of the origin node can be determined as the first distance.
[0062] The distance between two vectors can be the reciprocal of the cosine similarity, Euclidean distance, etc. It can be calculated by inputting the target vector and the reference vector of the origin node into a pre-defined program or script, and then obtaining the distance output by the program or script.
[0063] S205A3: Calculate the second distance between the target vector and any target branch node based on the target vector and the reference vector of any target branch node.
[0064] In this step, the method for calculating the second distance is similar to that for calculating the first distance, and will not be repeated here. The terms "first" and "second" are used to distinguish between the two distances, and do not imply any order of priority.
[0065] S205A4: If the first distance is less than each of the second distances, then the origin node is determined as the reference node.
[0066] In this step, comparing the magnitudes of two distances can also be performed using a preset program or script.
[0067] For example, if the first distance is 0.3, and the three second distances are 0.4, 0.6, and 1 respectively, then the origin node is determined as the reference node. This application does not impose specific limitations on the distance values.
[0068] S205A5: If any second distance is less than the first distance and less than any other second distance, then the target branch node corresponding to any second distance is determined as the new origin node, and the step of determining the target branch node and comparing the first distance and the second distance is repeated until the new origin node is not associated with any new branch node. The finally determined new origin node is determined as the reference node, or until the reference node is determined.
[0069] In this step, the step of determining the target branch node and comparing the first and second distances can be the step of determining the new origin node in steps S205A1 to S205A5 above. The new origin node is not associated with any new branch node; the associated branch node can be the origin node from the previous distance calculation, or the new origin node may not have any stored association relationship. The finally determined new origin node can be any origin node that is not associated with any new branch node. Determining the reference node can be the step of determining the origin node as the reference node in step S205A4 above.
[0070] S205A6: The target time is determined by the reference time corresponding to the reference node.
[0071] In this step, for example, if the reference time corresponding to the reference node is 2 hours, then the target time is 2 hours. Or, for example, if the reference time corresponding to the reference node is 4 hours, then the target time is 4 hours. This application embodiment does not limit the specific time value.
[0072] As can be seen from the description of the above embodiments, the embodiments of this application calculate the distance between the target vector and the reference vector from the origin node to the branch node in the topological relationship. If the distance corresponding to the branch node is closer, the branch node is used as the new origin node to continue calculating the distance between the vectors until the distance between the reference vector and the target vector of the origin node is the closest, or until the new origin node has no associated branch node, thus obtaining the node closest to the target vector in the topological structure, thereby obtaining the closest reference time. The closest reference time is used as the target time, and the topological structure reduces the amount of data to be calculated and reduces the time to estimate the target SQL statement time.
[0073] In one possible implementation, steps S205A1 to S205A6 described above may be performed on a fully connected topology.
[0074] In one possible implementation, in step S205 above, the target time of the target SQL statement is determined based on the target vector and the reference vector and reference time corresponding to the existing SQL node, including:
[0075] S205B1: Calculate the distance between the target vector and the reference vectors of each existing SQL node.
[0076] In this step, the method for calculating the distance between vectors can be similar to the method for calculating the first distance in step S205A2 above, and will not be repeated here.
[0077] S205B2: The existing SQL node that is closest to the target vector is identified as the reference node.
[0078] In this step, you can either sort the distances corresponding to all existing SQL nodes and determine the SQL node with the smallest corresponding distance as the reference node, or compare the distances corresponding to each existing SQL node and determine the existing SQL node with the smallest distance as the reference node.
[0079] For example, if there are three existing SQL nodes with distances of 1, 5, and 7 respectively, then the first existing SQL node is determined as the reference node. This application does not impose specific limitations on the distance values.
[0080] S205B3: Determine the reference time corresponding to the reference node as the target time.
[0081] This step is similar to step S205A6 above, and will not be repeated here.
[0082] As can be seen from the description of the above embodiments, the embodiments of this application calculate the distance between the target vector and the reference vectors of all existing SQL nodes in the topology, find the existing SQL node closest to the target vector as the reference node, and use the reference time corresponding to the reference node as the target time. This achieves the prediction of the time of the target SQL statement by finding the closest reference node by traversing all nodes in the topology.
[0083] In one possible implementation, steps S205B1 to S205B3 can be performed on a star topology. Star topologies have less data and are easier to traverse.
[0084] In one possible implementation, before obtaining the topology structure corresponding to the target table in step S203 above, the following is also included:
[0085] S210: Get the slow query log.
[0086] In this step, slow query logs can be read from a preset location.
[0087] The preset positions can be set by staff or preset by the program.
[0088] S211: Read the slow query SQL statement, the execution time of the slow query SQL statement, and the table corresponding to the slow query SQL statement from the slow query log.
[0089] In this step, slow query SQL statements can be those whose execution time exceeds a preset time threshold. The slow query log can record slow query SQL statements and the tables they correspond to. The slow query SQL statement, its execution time, and the corresponding table can be written on the same line. During reading, they can be retrieved separately by position or key fields, and then mapped and correlated.
[0090] If any slow query SQL is executed multiple times, the execution time of the slow query SQL statement can be the average of the multiple execution times or the slowest execution time.
[0091] S212: Calculate the vector corresponding to each slow query SQL statement.
[0092] In this step, the method for calculating the vector corresponding to the slow query SQL statement is similar to the method for calculating the target vector corresponding to the target SQL statement in step S204 above, and will not be repeated here.
[0093] S213: Based on the tables corresponding to the slow query SQL statements, determine the slow query SQL statements corresponding to each table.
[0094] In this step, since there is a correspondence between slow query SQL statements and tables, there are also corresponding slow query SQL statements for each table.
[0095] For example, if the three slow query SQL statements A, B, and C correspond to tables X, Y, and Y respectively, then table X corresponds to slow query SQL statement A, and table Y corresponds to slow query SQL statements B and C.
[0096] S214: Determine the topology of any table based on the vector of slow query SQL statements corresponding to any table.
[0097] In this step, the vector of the slow query SQL statement corresponding to any table can be used as the coordinates of the node corresponding to the slow query SQL statement. Based on the coordinates of each node, adjacent nodes or nodes with a distance less than a preset distance are connected to obtain the topology. Since each node in the topology corresponds to a slow query SQL statement, each node has a corresponding execution time, i.e., the reference execution time in step S203 above.
[0098] As can be seen from the description of the above embodiments, the embodiments of this application obtain slow query logs, get the slow query SQL statements in the logs and their corresponding execution times and tables, calculate the vectors corresponding to each slow query SQL, and construct a topology structure for slow query SQL statements in the same table based on the corresponding vectors, so as to facilitate the subsequent use of nodes in the topology structure to obtain the target time.
[0099] In one possible implementation, in step S214 above, determining the topology of any table based on the vector of slow query SQL statements for any table includes:
[0100] S2141: Get the number of slow query SQL statements for any table.
[0101] In this step, you can increment the count by 1 for each slow query SQL statement in any table, until you have traversed all slow query SQL statements, and use the final count as the number of slow query SQL statements.
[0102] S2142: If the number of slow query SQL statements is less than or equal to a preset threshold, then create a star topology based on the vector of all slow query SQL statements corresponding to any table.
[0103] In this step, the quantity threshold can be preset by the staff. Creating a star topology can be achieved by selecting the vector of any slow query SQL statement as the coordinates of the origin node, using the vectors of the remaining slow query SQL statements as the coordinates of the branch nodes, and connecting the origin node and the branch nodes to obtain the star topology.
[0104] S2143: If the number of slow query SQL statements exceeds a preset threshold, then cluster all slow query SQL statements corresponding to any table based on their vectors to obtain multiple statement classes. Calculate the distance between slow query SQL statements within each statement class based on their vectors. Create a fully connected topology based on each statement class and the distances between slow query SQL statements within each class.
[0105] In this step, all slow query SQL statements corresponding to any table are clustered, using methods such as K-means clustering or mean-shift clustering. During clustering, the vectors of the slow query SQL statements are used as their position coordinates. The distances between slow query SQL statements are calculated by class, which can involve calculating the distance between each slow query SQL statement within each class. After obtaining the distances between slow query SQL statements within each class, statements with distances less than a preset distance are associated to obtain the topology. This step may also include randomly deleting one of two statements with a distance less than a preset minimum distance threshold to reduce the amount of data.
[0106] As can be seen from the description of the above embodiments, the embodiments of this application create a star topology structure from the vector of slow query SQL statements when the number of slow query SQL statements is small, and cluster the slow query SQL statements to obtain multiple statement classes when the number of slow query SQL statements is large. The slow query SQL statements in each statement class are connected according to the distance between each statement class to obtain a fully connected topology structure. This realizes that when the data volume is small, the star topology structure is used to reduce the time of establishing the topology structure in the early stage, and when the data volume is large, the fully connected topology structure is used to reduce the time spent in determining the target SQL statement in the later stage.
[0107] In one possible implementation, each slow query SQL statement is treated as a node. During the connection process, the neighboring nodes of each node are found (the number of neighboring nodes can be specified according to specific business requirements; neighboring nodes can be nodes whose relative distance is less than a preset distance value). Based on the idea that "a neighbor's neighbor is also a neighbor," the neighboring nodes of a node are expanded. All candidate neighboring nodes are sorted according to Euclidean distance or cosine distance, and the top N neighboring nodes in the sorted sequence are connected to the node. A pruning operation can also be performed on each node, deleting neighboring nodes with smaller angles to already added neighboring nodes based on spatial angle. A depth-first traversal is performed on the nodes, marking visited nodes. Unvisited nodes are attached to visited nodes, thus forming a fully connected graph topology.
[0108] In one possible implementation, in step S2143 above, a fully connected topology is created based on each statement class and the distance between each slow query SQL statement within each statement class, including:
[0109] S431: Determine the target slow query SQL statement in the target statement class as the origin node. The coordinates of the origin node are the vector corresponding to the target slow query SQL statement. The target statement class can be any statement class, and the target slow query SQL statement can be any slow query SQL statement.
[0110] In this step, for example, if there are 5 slow query SQL statements in the current target statement class, one is randomly selected as the origin node, and the coordinates of the origin node are the vector of the selected slow query SQL statement.
[0111] S432: Identify the slow query SQL statements other than the target slow query SQL statement in the target statement class as branch nodes, where the coordinates of the branch nodes are the corresponding vectors.
[0112] In this step, for example, if there are 8 slow query SQL statements in the target statement class, then the 7 slow query SQL statements other than the target slow query SQL statement will be identified as branch nodes.
[0113] S433: Branch nodes whose distance from the origin node is less than a preset distance are identified as nodes to be associated.
[0114] In this step, the distance between the branch node and the origin node is the distance between the corresponding vectors. The preset distance can be set by the staff based on experience or experimental data.
[0115] For example, if there are 5 branch nodes with distances of 3, 5, 5, 7, and 9 from the origin node, and the preset distance is 6, then the first three branch nodes will be identified as nodes to be associated.
[0116] S434: Associate the node to be associated with the origin node.
[0117] In this step, the identifier of the node to be associated and the origin node can be written into the same array, field or table to establish the association between the node to be associated and the origin node.
[0118] S435: Determine the node to be associated as the new origin node, determine the statement class to which the new origin node belongs as the new target statement class, and re-execute the steps of determining the node to be associated and associating the node to be associated with the origin node using the new origin node and the new target statement class, until all slow query SQL statements in each statement class are traversed to obtain a fully connected topology.
[0119] In this step, the steps of determining the nodes to be associated and associating them with the origin node can be steps S433 to S434 described above. For example, if there are currently 3 nodes to be associated, then each node to be associated is treated as a new origin node, and branch nodes with a distance less than a preset distance are found and associated. Each slow query SQL statement is identified as a node in the topology structure. After traversing all nodes, a fully connected topology structure is obtained.
[0120] The origin node of the final fully connected topology is still the origin node determined during the first execution of step S431. This application embodiment does not impose a specific limitation on the number of associated nodes.
[0121] As can be seen from the description of the above embodiments, the embodiments of this application find related branch nodes in the same statement class by starting with any slow query SQL statement in any statement class, and then find related branch nodes from the branch nodes, so as to finally connect all nodes and obtain a fully connected topology. Since clustering is performed first, the amount of data used to calculate the distance between nodes is smaller, which reduces the amount of calculation and speeds up the construction speed of the fully connected topology.
[0122] In one possible implementation, after calculating the target vector corresponding to the target SQL statement in step S204 above, the method further includes:
[0123] S220: Based on the target vector and topology, determine the nearest neighbor node to the target SQL statement.
[0124] This step is similar to steps S205A1 to S205A5 or steps S205B1 to S205B2 above, and the reference node is obtained as the neighbor node, which will not be described again here.
[0125] S221: Execute the target SQL statement and obtain the execution time of the target SQL statement.
[0126] In this step, the SQL statement can be executed based on its content. The start time is recorded when the execution begins, and the end time is recorded after execution. Subtracting the start time from the end time gives the execution time.
[0127] Both start and end times can be recorded by obtaining the timestamp and storing it.
[0128] S222: Identify the target SQL statement as a new node.
[0129] In this step, the coordinates of the newly added node are the target vector.
[0130] S223: Associate the newly added node with its neighboring nodes.
[0131] This step is similar to step S434 above, and will not be repeated here.
[0132] S224: Establish a mapping relationship between newly added nodes and execution time.
[0133] In this step, the identifier of the new node and the execution time can be stored in pairs using a table, key-value pairs, or other formats to obtain the mapping relationship between the new node and the execution time.
[0134] As can be seen from the description of the above embodiments, the embodiments of this application obtain the execution time of the target SQL statement by executing the target SQL statement, find the nearest neighbor node to the target SQL statement, determine the target SQL statement as a new node, associate the new node with the neighbor node, and establish a mapping relationship between the new node and the execution time, so as to add the node of the newly obtained SQL statement into the topology structure after the SQL statement is executed, making the topology structure more comprehensive.
[0135] Figure 4 This is a schematic diagram of the overall process of the method for determining the time consumption of a structured query language statement provided in the embodiments of this application.
[0136] like Figure 4 As shown, the overall process for determining the execution time of an SQL statement consists of three branches: offline index building, online execution time prediction, and incremental data processing. The offline index building process is represented by a solid line, the online execution time prediction process by a dashed line, and the incremental data processing process by a dashed line.
[0137] The offline index building process includes: collecting slow query logs, separating and mapping the SQL statements and time consumption in the slow query logs, calculating the vectors of the SQL statements in the slow query logs, and creating a topology index from the vectors of each SQL statement.
[0138] The online time consumption prediction process includes: receiving the target SQL statement sent by the terminal device, calculating the vector of the target SQL statement, and combining the topology index and the vector of the target SQL statement to determine the target time consumption of the target SQL statement.
[0139] The incremental data processing flow includes: extracting incremental SQL statements from the database, calculating the vector of incremental SQL statements, finding the nearest neighbor nodes of incremental SQL statements by combining the topological structure index, and adding incremental SQL statements to the topological structure index.
[0140] Figure 5 This is a schematic diagram of the structure of the device for determining the time consumption of a structured query language statement provided in an embodiment of this application. Figure 5 As shown, the Structured Query Language statement time determination device 500 includes: a statement receiving module 501, a target table acquisition module 502, a structure acquisition module 503, a vector calculation module 504, and a time determination module 505.
[0141] The statement receiving module 501 is used to receive target Structured Query Language (SQL) statements sent by the terminal device.
[0142] The target table retrieval module 502 is used to retrieve the target table corresponding to the target SQL statement.
[0143] The structure acquisition module 503 is used to acquire the topology structure corresponding to the target table. The topology structure includes at least one existing SQL node, wherein the existing SQL node has a corresponding reference vector and reference time.
[0144] Vector calculation module 504 is used to calculate the target vector corresponding to the target SQL statement.
[0145] The time consumption determination module 505 is used to determine the target time of the target SQL statement based on the target vector and the reference vector and reference time corresponding to the existing SQL node.
[0146] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0147] In one possible implementation, there are existing SQL nodes, including an origin node and at least one branch node, with the origin node associated with at least one branch node. A time consumption determination module 505 is used to determine the branch node associated with the origin node as the target branch node. Based on the target vector and the reference vector of the origin node, a first distance between the target vector and the origin node is calculated. Based on the target vector and the reference vector of any target branch node, a second distance between the target vector and any target branch node is calculated. If the first distance is less than any of the second distances, the origin node is determined as a reference node. If any second distance is less than the first distance and less than the other second distances, the target branch node corresponding to any second distance is determined as a new origin node, and the steps of determining the target branch node and comparing the first and second distances are repeated until the new origin node is not associated with any new branch node. The finally determined new origin node is then determined as a reference node, or until a reference node is determined. The reference time corresponding to the reference node is used to determine the target time.
[0148] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0149] In one possible implementation, the time consumption determination module 505 is used to calculate the distance between the target vector and the reference vectors of each existing SQL node. The existing SQL node closest to the target vector is determined as the reference node. The reference time corresponding to the reference node is determined as the target time.
[0150] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0151] In one possible implementation, the Structured Query Language statement time determination device 500 further includes a structure determination module 506.
[0152] The structure determination module 506 is used to obtain the slow query log. It reads the slow query SQL statements, their execution times, and the tables corresponding to those statements from the log. It calculates the vector for each slow query SQL statement. Based on the tables corresponding to the slow query SQL statements, it determines the slow query SQL statements for each table. Based on the vector of the slow query SQL statements for any given table, it determines the topology of that table.
[0153] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0154] In one possible implementation, the structure determination module 506 is used to obtain the number of slow query SQL statements corresponding to any table. If the number of slow query SQL statements is less than or equal to a preset threshold, a star topology is created based on the vectors of all slow query SQL statements corresponding to any table. If the number of slow query SQL statements is greater than the preset threshold, all slow query SQL statements corresponding to any table are clustered based on the vectors of all slow query SQL statements corresponding to any table, resulting in multiple statement classes. The distance between slow query SQL statements in each statement class is calculated based on the vectors of each slow query SQL statement. A fully connected topology is created based on the distances between slow query SQL statements in each statement class.
[0155] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0156] In one possible implementation, the structure determination module 506 is used to determine the target slow query SQL statement in the target statement class as the origin node, where the coordinates of the origin node are the vector corresponding to the target slow query SQL statement. The target statement class can be any statement class, and the target slow query SQL statement can be any slow query SQL statement. Slow query SQL statements other than the target slow query SQL statement in the target statement class are determined as branch nodes, where the coordinates of the branch nodes are the corresponding vectors. Branch nodes whose distance to the origin node is less than a preset distance are determined as nodes to be associated. These nodes are then associated with the origin node. The nodes to be associated are then determined as new origin nodes, and the statement class to which the new origin node belongs is determined as the new target statement class. Using the new origin node and the new target statement class, the steps of determining the nodes to be associated and associating them with the origin node are re-executed until all slow query SQL statements in each statement class are traversed, resulting in a fully connected topology.
[0157] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0158] In one possible implementation, the Structured Query Language statement time determination device 500 further includes a mapping establishment module 507.
[0159] The mapping establishment module 507 is used to determine the nearest neighbor node to the target SQL statement based on the target vector and topology. The target SQL statement is executed, and its execution time is obtained. The target SQL statement is then identified as a new node. This new node is associated with its neighbor nodes. Finally, a mapping relationship is established between the new node and its execution time.
[0160] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0161] To implement the above embodiments, this application also provides an electronic device.
[0162] refer to Figure 6 The diagram illustrates a structural schematic of an electronic device 600 suitable for implementing embodiments of this application. The electronic device 600 can be a terminal device or a server. The terminal device can include, but is not limited to, mobile terminals such as mobile phones, laptops, digital radio receivers, personal digital assistants (PDAs), portable Android devices (PADs), portable media players (PMPs), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 6 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0163] like Figure 6 As shown, the electronic device 600 may include a processor (e.g., a central processing unit, a graphics processing unit, etc.) 601 and a memory 602 communicatively connected to the processor. The processor can perform various appropriate actions and processes based on programs stored in the memory 602, computer-executed instructions, or programs loaded from storage device 608 into random access memory (RAM) 603, implementing the structured query language statement time determination method in any of the above embodiments. The memory may be read-only memory (ROM). The RAM 603 also stores various programs and data required for the operation of the electronic device 600. The processing device 601, the memory 602, and the RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0164] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0165] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable storage medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a storage device 608, or installed from a memory 602. When the computer program is executed by the processing device 601, it performs the functions defined in the methods of the embodiments of this application.
[0166] It should be noted that the computer-readable storage medium described above in this application can be a computer-readable signal medium or a computer storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0167] The aforementioned computer-readable storage medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0168] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the methods shown in the above embodiments.
[0169] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof. These programming languages include object-oriented programming languages—such as Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0170] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0171] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the units are not necessarily limiting of the module itself; for example, a structure acquisition module can also be described as a "topology acquisition module".
[0172] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0173] This application also provides a computer-readable storage medium storing computer-executable instructions. When a processor executes the computer-executable instructions, it implements the technical solution of the method for determining the time consumption of structured query language statements in any of the above embodiments. The implementation principle and beneficial effects are similar to those of the method for determining the time consumption of structured query language statements. Please refer to the implementation principle and beneficial effects of the method for determining the time consumption of structured query language statements, which will not be repeated here.
[0174] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0175] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the technical solution of the method for determining the time consumption of structured query language statements in any of the above embodiments. Its implementation principle and beneficial effects are similar to those of the method for determining the time consumption of structured query language statements, and can be found in the implementation principle and beneficial effects of the method for determining the time consumption of structured query language statements, which will not be repeated here.
[0176] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
[0177] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0178] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A method for determining the time consumption of a Structured Query Language statement, characterized in that, include: Get slow query logs; Read the slow query SQL statement, the execution time of the slow query SQL statement, and the table corresponding to the slow query SQL statement from the slow query log; Calculate the vector corresponding to each slow query SQL statement; determine the slow query SQL statement corresponding to each table based on the table corresponding to the slow query SQL statement; For any table, perform the following topology construction steps: Obtain the number of slow query SQL statements corresponding to any of the tables; if the number of slow query SQL statements is less than or equal to a preset threshold, then create a star topology based on the vectors of all slow query SQL statements corresponding to any of the tables; wherein the star topology uses the vector of any slow query SQL statement as the origin node and the vectors of the remaining slow query SQL statements as branch nodes. If the number of slow query SQL statements exceeds the preset threshold, then the following steps for constructing a fully interconnected topology will be performed: Based on the vector of all slow query SQL statements corresponding to any one of the tables, cluster all slow query SQL statements corresponding to any one of the tables to obtain multiple statement classes; For any statement class, perform the following operations to construct a fully connected topology: Any slow query SQL statement in any statement class is determined as the initial origin node, and the coordinates of the initial origin node are the corresponding vectors; other slow query SQL statements in any statement class besides the initial origin node are determined as branch nodes; branch nodes whose distance from the current origin node is less than a preset distance are determined as nodes to be associated, and the nodes to be associated are associated with the current origin node; the nodes to be associated are determined as the new current origin node, and the steps of determining nodes to be associated and associating are repeated using the new current origin node until all slow query SQL statements in any statement class are traversed to obtain the fully connected topology. Receive the target Structured Query Language (SQL) statement sent by the terminal device; Obtain the target table corresponding to the target SQL statement; Obtain the topology corresponding to the target table. The topology is a star topology or a fully connected topology constructed through the above topology construction steps. The topology includes at least one existing SQL node, wherein the existing SQL node has a corresponding reference vector and reference time. Calculate the target vector corresponding to the target SQL statement; The target time of the target SQL statement is determined based on the target vector and the reference vector and reference time corresponding to the existing SQL node.
2. The method according to claim 1, characterized in that, The existing SQL node includes an origin node and at least one branch node, wherein the origin node is associated with at least one branch node; Accordingly, determining the target time of the target SQL statement based on the target vector and the reference vector and reference time corresponding to the existing SQL node includes: The branch node associated with the origin node is identified as the target branch node; Calculate the first distance between the target vector and the origin node based on the target vector and the reference vector of the origin node; Based on the target vector and the reference vector of any target branch node, calculate the second distance between the target vector and any target branch node; If the first distance is less than each of the second distances, then the origin node is determined as the reference node; If any second distance is less than the first distance and less than any other second distance, then the target branch node corresponding to any second distance is determined as the new origin node, and the step of determining the target branch node to comparing the first distance and the second distance is repeated until the new origin node is not associated with any new branch node. The last determined new origin node is then determined as the reference node, or until the reference node is determined. The target time is determined by using the reference time corresponding to the reference node.
3. The method according to claim 1, characterized in that, The step of determining the target time of the target SQL statement based on the target vector and the reference vector and reference time corresponding to the existing SQL node includes: Calculate the distance between the target vector and the reference vector of each existing SQL node; The existing SQL node that is closest to the target vector is identified as the reference node; The reference time corresponding to the reference node is determined as the target time.
4. The method according to any one of claims 1 to 3, characterized in that, After calculating the target vector corresponding to the target SQL statement, the method further includes: Based on the target vector and the topology, determine the nearest neighbor node to the target SQL statement; Execute the target SQL statement and obtain the execution time of the target SQL statement; The target SQL statement is identified as a new node; Associate the newly added node with the neighboring node; Establish a mapping relationship between the newly added node and the execution time.
5. A device for determining the time consumption of a Structured Query Language statement, characterized in that, include: The structure determination module is used to: obtain slow query logs; Read the slow query SQL statement, the execution time of the slow query SQL statement, and the table corresponding to the slow query SQL statement from the slow query log; Calculate the vector corresponding to each slow query SQL statement; determine the slow query SQL statement corresponding to each table based on the table corresponding to the slow query SQL statement; The structure determination module is also used to perform the following topology construction steps for any table: Obtain the number of slow query SQL statements corresponding to any of the tables; if the number of slow query SQL statements is less than or equal to a preset threshold, then create a star topology based on the vectors of all slow query SQL statements corresponding to any of the tables; wherein the star topology uses the vector of any slow query SQL statement as the origin node and the vectors of the remaining slow query SQL statements as branch nodes. If the number of slow query SQL statements exceeds the preset threshold, the following fully connected topology construction steps are executed: Based on the vectors of all slow query SQL statements corresponding to any table, all slow query SQL statements corresponding to any table are clustered to obtain multiple statement classes; for any statement class, the following operations are performed to construct a fully connected topology: any slow query SQL statement in any statement class is determined as the initial origin node, and the coordinates of the initial origin node are the corresponding vectors; other slow query SQL statements in any statement class except the initial origin node are determined as branch nodes; branch nodes whose distance from the current origin node is less than a preset distance are determined as nodes to be associated, and the nodes to be associated are associated with the current origin node; the nodes to be associated are determined as the new current origin node, and the steps of determining nodes to be associated and associating are repeated using the new current origin node until all slow query SQL statements in any statement class are traversed to obtain the fully connected topology. The statement receiving module is used to receive target Structured Query Language (SQL) statements sent by the terminal device. The target table acquisition module is used to acquire the target table corresponding to the target SQL statement. The structure acquisition module is used to acquire the topology structure corresponding to the target table. The topology structure is a star topology structure or a fully connected topology structure constructed through the above topology structure construction steps. The topology structure includes at least one existing SQL node, wherein the existing SQL node has a corresponding reference vector and reference time. The vector calculation module is used to calculate the target vector corresponding to the target SQL statement; The time consumption determination module is used to determine the target time consumption of the target SQL statement based on the target vector and the reference vector and reference time corresponding to the existing SQL node.
6. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes the computer execution instructions stored in the memory, causing the processor to execute the method for determining the time consumption of a structured query language statement as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method for determining the time consumption of a structured query language statement as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Statement execution duration prediction method and device and storage medium
CN115858555A