A slow query analysis method and apparatus

By constructing a weighted abstract syntax tree and genetic coding, the problem of insufficient structural sensitivity in slow query analysis is solved, enabling accurate identification of slow queries and improving the accuracy of the identification results.

CN123115192APending Publication Date: 2026-11-17BEIJING JINGDONG YUANSHENG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510592636.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-08
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing slow query analysis methods lack structural sensitivity when identifying slow queries, resulting in poor accuracy of the identification results and a tendency to misjudge performance defects.

Method used

By constructing a weighted abstract syntax tree, the target gene coding sequence is generated, and similar gene patterns are retrieved from the historical gene database. The mixture difference is calculated, and the query statement is analyzed to determine whether it is a slow query by combining the target calibration threshold comparison.

Benefits of technology

It improves the structural sensitivity and accuracy of slow query identification, realizes the performance equivalence identification of different writing styles, and improves the accuracy of identification results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115192A_ABST
    Figure CN123115192A_ABST
Patent Text Reader

Abstract

This invention discloses a slow query analysis method and apparatus, relating to the field of computer technology. One specific implementation of the method includes: constructing a weighted abstract syntax tree (LST) based on the query to be analyzed; traversing the LST; generating a target gene coding sequence according to a preset gene rule base; retrieving similar gene patterns corresponding to the target gene coding sequence from a historical gene database; determining the mixed dissimilarity degree corresponding to the target gene coding sequence based on the similar gene patterns; wherein the mixed dissimilarity degree includes gene sequence dissimilarity and substructure dissimilarity; comparing the mixed dissimilarity degree with a target calibration threshold; and analyzing whether the query to be analyzed is a slow query based on the comparison results. This embodiment improves structural sensitivity by constructing a weighted abstract syntax tree and gene-based coding, achieving performance equivalence recognition of different syntaxes, thereby improving the accuracy of the recognition results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a slow query analysis method and apparatus. Background Technology

[0002] Slow queries in a database refer to queries that take longer than a preset threshold to execute in a database system. These queries typically lead to decreased database performance, consume significant resources, and impact system response time and concurrency capabilities; in severe cases, they can even cause system crashes. Currently, slow query analysis primarily employs methods such as rule matching, execution plan analysis, and machine learning. However, these methods lack structural sensitivity and are prone to misjudging performance defects, resulting in poor accuracy in the identification results. Summary of the Invention

[0003] In view of this, embodiments of the present invention provide a slow query analysis method and apparatus, which improves structural sensitivity by constructing a weighted abstract syntax tree and genetic coding, realizes the performance equivalence identification of different writing styles, and thus improves the accuracy of the identification results.

[0004] To achieve the above objectives, according to one aspect of the present invention, a slow query analysis method is provided, comprising:

[0005] A weighted abstract syntax tree is constructed based on the query statement to be analyzed. The weighted abstract syntax tree is traversed, and the target gene coding sequence is generated according to the preset gene rule library.

[0006] Similar gene patterns corresponding to the coding sequence of the target gene are retrieved from the historical gene database, and the mixed difference degree corresponding to the coding sequence of the target gene is determined based on the similar gene patterns; wherein, the mixed difference degree includes gene sequence difference degree and substructure difference degree;

[0007] The mixture difference is compared with the target calibration threshold, and the query statement to be analyzed is determined based on the comparison results to determine whether it is a slow query.

[0008] Optionally, a weighted abstract syntax tree is constructed based on the query statement to be analyzed, including:

[0009] The query statement to be analyzed is parsed to generate an initial abstract syntax tree; the initial abstract syntax tree includes multiple nodes.

[0010] Based on the field access characteristic information corresponding to the query statement to be analyzed, the nodes in the abstract syntax tree are weighted to obtain a weighted abstract syntax tree; among them, the field access characteristic information includes field selectivity and index coverage.

[0011] Optionally, the weighted abstract syntax tree is traversed to generate the target gene coding sequence according to a preset gene rule base, including:

[0012] By traversing the weighted abstract syntax tree through the gene coding engine, multiple nodes are mapped to multiple gene fragments based on a preset gene rule base.

[0013] Multiple gene fragments are spliced ​​together to generate an initial gene coding sequence;

[0014] The initial gene coding sequence is subjected to noise reduction processing based on the preset variation constraint matrix to obtain the target gene coding sequence.

[0015] Optionally, the degree of mixture dissimilarity corresponding to the target gene coding sequence is determined based on similar gene patterns, including:

[0016] The weighted edit distance algorithm is used to determine the gene sequence difference between similar gene patterns and target gene coding sequences;

[0017] Key subtrees are extracted from the weighted abstract syntax tree, and the structural similarity of the key subtrees is compared with that of the preset sliding window baseline library to obtain the substructure difference degree.

[0018] The gene sequence difference and the substructure difference are weighted and fused to obtain the mixed difference corresponding to the target gene coding sequence.

[0019] Optionally, the target calibration threshold is determined through the following steps:

[0020] Generate a difference data stream based on the mixed difference values ​​corresponding to multiple query statements to be analyzed;

[0021] Monitor the difference data stream and determine the target calibration threshold based on the monitoring results.

[0022] Optionally, after analyzing whether the query statement to be analyzed is a slow query based on the comparison results, the process also includes:

[0023] A judgment sample set is generated based on the analysis results of the query statement to be analyzed, and the misjudged samples in the judgment sample set are identified.

[0024] Optimize the target calibration threshold or historical gene pool based on misjudged samples.

[0025] According to a second aspect of the present invention, a slow query analysis apparatus is provided, comprising:

[0026] The construction module is used to build a weighted abstract syntax tree based on the query statement to be analyzed, traverse the weighted abstract syntax tree, and generate the target gene coding sequence according to the preset gene rule library;

[0027] The determination module is used to retrieve similar gene patterns corresponding to the coding sequence of the target gene from the historical gene database, and determine the mixed difference degree corresponding to the coding sequence of the target gene based on the similar gene patterns; wherein, the mixed difference degree includes gene sequence difference degree and substructure difference degree;

[0028] The analysis module is used to compare the mixing difference with the target calibration threshold and analyze whether the query to be analyzed is a slow query based on the comparison results.

[0029] According to a third aspect of the present invention, an electronic device is provided, comprising:

[0030] One or more processors;

[0031] Memory, used to store one or more programs.

[0032] When one or more programs are executed by one or more processors, the one or more processors implement the methods of any of the above embodiments.

[0033] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method of any of the above embodiments.

[0034] According to a fifth aspect of the present invention, a computer program product is provided, including a computer program that, when executed by a processor, implements the method of any of the above embodiments.

[0035] One embodiment of the above invention has the following advantages or beneficial effects: A weighted abstract syntax tree is constructed based on the query statement to be analyzed; the weighted abstract syntax tree is traversed; a target gene coding sequence is generated according to a preset gene rule base; similar gene patterns corresponding to the target gene coding sequence are retrieved from the historical gene database; and the mixed difference degree corresponding to the target gene coding sequence is determined based on the similar gene patterns; wherein, the mixed difference degree includes gene sequence difference degree and substructure difference degree; the mixed difference degree is compared with a target calibration threshold; and the query statement to be analyzed is analyzed based on the comparison results to determine whether it is a slow query. This embodiment improves structural sensitivity by constructing a weighted abstract syntax tree and gene-based coding, achieving performance equivalence recognition of different writing styles, thereby improving the accuracy of the recognition results.

[0036] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description

[0037] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:

[0038] Figure 1 This is a schematic diagram of the main flow of the slow query analysis method according to an embodiment of the present invention;

[0039] Figure 2 This is a schematic diagram of the main flow of a slow query analysis method according to an optional embodiment of the present invention;

[0040] Figure 3 This is a schematic diagram of the main modules of the slow query analysis device according to an embodiment of the present invention;

[0041] Figure 4 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;

[0042] Figure 5 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation

[0043] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0044] It should be noted that the acquisition, storage, and application of personal information involved in the embodiments of the present invention comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0045] Slow queries in a database refer to queries that take longer than a preset threshold to execute in a database system. These queries typically lead to decreased database performance, consume significant resources, and impact system response time and concurrency capabilities; in severe cases, they can even cause system crashes. Currently, slow query analysis primarily employs methods such as rule matching, execution plan analysis, and machine learning. However, these methods lack structural sensitivity and are prone to misjudging performance defects, resulting in poor accuracy in the identification results.

[0046] In view of this, according to one aspect of the present invention, a slow query analysis method is provided.

[0047] Figure 1 This is a schematic diagram of the main flow of the slow query analysis method according to an embodiment of the present invention. Figure 1 As shown, the slow query analysis method according to an embodiment of the present invention includes the following steps S101 to S103.

[0048] Step S101: Construct a weighted abstract syntax tree based on the query statement to be analyzed, traverse the weighted abstract syntax tree, and generate the target gene coding sequence according to the preset gene rule library.

[0049] The query statement to be analyzed refers to the database query instruction to be identified as a slow query. It can be represented in Structured Query Language (SQL) or other query description languages. The weighted abstract syntax tree (BST) is a tree structure built based on the query statement to be analyzed. Each node in this tree structure represents a syntactic component in the query statement, and each node is appended with weight information representing query optimization-related characteristics. This weight information includes, but is not limited to, field selectivity, index utilization, and access frequency. Building a weighted abstract syntax tree based on the query statement to be analyzed allows for the dynamic assignment of performance-related weight information to each syntax node during syntax parsing, incorporating historical statistical data of fields or indexes. Additionally, weights can be reverse-labeled based on runtime information such as the execution cost and number of rows accessed by parsing the query execution plan.

[0050] The predefined gene rule base is a collection of predefined and maintained query structure and performance feature mapping rules. This rule base is used to systematically identify key patterns and their performance features in the weighted abstract syntax tree (FTLP). The target gene encoding sequence is an encoded representation describing the structure and performance features of the query statement to be analyzed. When traversing the FTLP and generating the target gene encoding sequence based on the predefined gene rule base, a depth-first traversal method can be used, sequentially visiting each node in the FTLP and extracting the corresponding structural and performance feature codes according to the gene rules. Alternatively, a breadth-first traversal method can be used, visiting nodes hierarchically, extracting feature codes based on node content and their adjacency relationships using gene rules, and finally concatenating them to form the complete target gene encoding sequence.

[0051] Step S102: Retrieve similar gene patterns corresponding to the target gene coding sequence from the historical gene database, and determine the mixed difference degree corresponding to the target gene coding sequence based on the similar gene patterns; wherein, the mixed difference degree includes gene sequence difference degree and substructure difference degree.

[0052] The historical gene database is a feature storage set built upon a large number of historical query statements and their performance characteristic samples, after gene encoding processing. Each record in the historical gene database corresponds to the gene encoding sequence of a historical query statement and its associated performance annotation information. Similar gene patterns are a set of historical gene encoding samples that are highly correlated with the target gene encoding sequence generated by the query statement to be analyzed in terms of structural or performance characteristics. They are used to assist in evaluating the similarity and potential performance between the current query statement to be analyzed and existing query patterns. Retrieving the set of similar gene patterns corresponding to the target gene encoding sequence from the historical gene database can be done by using the locality-sensitive hashing method to perform an approximate nearest neighbor search on the target gene encoding sequence to quickly locate structurally similar historical gene samples; alternatively, vectorization and cosine similarity calculation methods can be used to perform vector matching between the target gene encoding sequence and samples in the historical gene database, selecting gene patterns with similarity higher than a preset threshold as similar gene patterns.

[0053] Mixed dissimilarity refers to an index that comprehensively measures the degree of difference between the target gene coding sequence and similar gene patterns in terms of overall structural sequence and local substructural features. Specifically, it includes gene sequence dissimilarity and substructural dissimilarity, etc. To determine the mixed dissimilarity corresponding to the target gene coding sequence based on similar gene patterns, the edit distance and subgraph isomorphism dissimilarity between the target gene coding sequence and each similar gene pattern can be calculated separately, and a weighted summation can be used to generate the mixed dissimilarity. Alternatively, based on feature extraction methods, key sub-pattern features of the target gene coding sequence and similar gene patterns can be extracted and input into a pre-trained dissimilarity prediction model to obtain the corresponding mixed dissimilarity.

[0054] Step S103: Compare the mixing difference with the target calibration threshold, and analyze whether the query statement to be analyzed is a slow query based on the comparison result.

[0055] The target calibration threshold refers to the performance difference boundary value used to distinguish between slow queries and normal queries, either preset by the system or adaptively generated based on historical training samples. It reflects the maximum acceptable range of difference between the query and the benchmark query. When comparing the mixed difference degree with the target calibration threshold, the mixed difference degree value can be directly compared with the target calibration threshold value. If the mixed difference degree is greater than the target calibration threshold, it is considered to have a significant anomaly. Alternatively, the mean or standard deviation can be calculated within a sliding time window based on the changing trend of the mixed difference degree, and a dynamic detection boundary can be set in conjunction with the target calibration threshold to determine whether a slow query flag is triggered. Based on the above comparison results, the query to be analyzed is determined to be a slow query. For example, a single threshold judgment rule can be set: when the mixed difference degree exceeds the target calibration threshold, it is judged as a slow query; otherwise, it is a normal query. Alternatively, a hierarchical judgment mechanism can be introduced, classifying the mixed difference degree into different levels—normal, mild slow query, and severe slow query—based on the extent to which it exceeds the target calibration threshold, and outputting the slow query analysis results accordingly.

[0056] This invention constructs a weighted abstract syntax tree (LST) based on the query to be analyzed, traverses the LST, and generates a target gene coding sequence according to a preset gene rule base. It then retrieves similar gene patterns corresponding to the target gene coding sequence from a historical gene database and determines the mixed dissimilarity degree corresponding to the target gene coding sequence based on these similar gene patterns. The mixed dissimilarity degree includes gene sequence dissimilarity and substructure dissimilarity. The mixed dissimilarity degree is compared with a target calibration threshold, and the comparison results are used to analyze whether the query to be analyzed is a slow query. This embodiment improves structural sensitivity by constructing a weighted abstract syntax tree and gene-based coding, enabling the identification of performance equivalence between different coding styles, thereby improving the accuracy of the identification results.

[0057] Figure 2 This is a schematic diagram of the main flow of a slow query analysis method according to a preferred embodiment of the present invention. Figure 2 As shown, a weighted abstract syntax tree is constructed based on the query statement to be analyzed, including the following steps S201 to S202.

[0058] Step S201: Parse the query statement to be analyzed to generate an initial abstract syntax tree; wherein, the initial abstract syntax tree includes multiple nodes;

[0059] Step S202: Based on the field access characteristic information corresponding to the query statement to be analyzed, the nodes in the abstract syntax tree are weighted to obtain a weighted abstract syntax tree; wherein, the field access characteristic information includes field selectivity and index coverage.

[0060] In this embodiment, the query statement to be analyzed is parsed, and an initial abstract syntax tree (API) is generated according to the syntax rules of the database query language. The API includes multiple nodes, each corresponding to an operation unit in the query statement. Field access characteristic information associated with the query statement is obtained, including field selectivity and index coverage, etc. Based on this information, each node in the API is weighted to obtain a weighted API. The weighting process includes, but is not limited to, determining weight values ​​based on the field selectivity and index coverage of each node, and assigning these weight values ​​to the corresponding nodes to highlight the structural parts of the query statement that have a significant impact on execution performance. Alternatively, the nodes in the API can be weighted based on the actual execution time of each node in the historical execution plan of the query statement, or based on the node cost estimation information generated by the query optimizer. The weighted API constructed in this way can effectively characterize the structural characteristics and performance influencing factors of the query statement, helping to improve the accuracy and robustness of slow query detection.

[0061] Optionally, traversing the weighted abstract syntax tree and generating the target gene coding sequence according to a preset gene rule base includes: traversing the weighted abstract syntax tree through a gene coding engine, mapping multiple nodes to multiple gene fragments based on the preset gene rule base; splicing multiple gene fragments to generate an initial gene coding sequence; and performing noise reduction processing on the initial gene coding sequence according to a preset mutation constraint matrix to obtain the target gene coding sequence.

[0062] The weighted abstract syntax tree (SLP) is traversed using a gene coding engine, visiting each node sequentially according to a top-down or breadth-first traversal strategy. For each visited node, its structural features, weight information, and related semantic features are mapped to corresponding gene fragments based on mapping rules defined in a predefined gene rule base, resulting in multiple gene fragments. These gene fragments are then sequentially concatenated according to the traversal order of the nodes in the SLP to generate an initial gene coding sequence. Further, the initial gene coding sequence is subjected to noise reduction processing based on a predefined mutation constraint matrix. This noise reduction includes identifying and filtering irrelevant mutations introduced by execution environment noise and statistical biases in the gene fragments, thereby correcting noisy gene sites in the initial gene coding sequence and ultimately obtaining a stable target gene coding sequence with high discriminative power. Alternatively, a multi-level mapping system can be set up to first map nodes to intermediate feature fragments, and then generate the initial gene coding sequence based on specific sequence compression rules. Through the above traversal and encoding processes, the key execution characteristics of the query statement to be analyzed can be fully preserved, while improving the accuracy and robustness of subsequent similar pattern retrieval and slow query determination, and enhancing the system's adaptability to complex query statements.

[0063] Optionally, the mixture dissimilarity degree corresponding to the target gene coding sequence is determined based on similar gene patterns, including: determining the gene sequence dissimilarity degree between similar gene patterns and the target gene coding sequence based on a weighted edit distance algorithm; extracting key subtrees from a weighted abstract syntax tree, comparing the key subtrees with a preset sliding window baseline library for structural similarity, and obtaining substructure dissimilarity degree; and weightedly fusing the gene sequence dissimilarity degree and the substructure dissimilarity degree to obtain the mixture dissimilarity degree corresponding to the target gene coding sequence.

[0064] In this embodiment, the gene sequence difference between similar gene patterns and the target gene coding sequence is calculated based on a weighted edit distance algorithm. This weighted edit distance algorithm, based on traditional edit distance, introduces node weight factors to assign different weights to different types of change operations (such as insertion, deletion, and replacement) to more accurately measure the true differences between gene sequences. Key subtrees reflecting the key logical structure of the query statement are extracted from the weighted abstract syntax tree, and the extracted key subtrees are compared with standard structures in a preset sliding window baseline library for structural similarity. Based on the subtree structural feature matching degree, the substructure difference is obtained. According to the set fusion weights, the gene sequence difference and the substructure difference are weighted and fused to obtain a mixed difference degree that comprehensively reflects the semantic and structural differences of the query statement. Alternatively, a dynamic time warping algorithm (DTW algorithm) can be used to align the gene fragment sequences along the time axis to calculate the difference, or a substructure matching model based on a graph neural network can be used to measure the difference of the abstract syntax tree substructure to further improve the sensitivity and discrimination accuracy to changes in the features of complex query statements. The above method not only captures the dual changes in the logical content and execution plan structure of the query statement with fine granularity, improving the accuracy of mixed difference calculation, but also effectively supports subsequent intelligent identification of slow queries, improving the overall detection efficiency and accuracy of the system.

[0065] Optionally, the target calibration threshold is determined by the following steps: generating a difference data stream based on the mixed difference corresponding to multiple queries to be analyzed; monitoring the difference data stream, and determining the target calibration threshold based on the monitoring results.

[0066] For multiple queries to be analyzed, their respective mixture dissimilarity degrees are calculated, and all mixture dissimilarity degree results are organized into a dissimilarity data stream according to time order or processing order. This dissimilarity data stream can reflect the changing trends and overall distribution characteristics of different queries at the feature level in real time. By monitoring the dissimilarity data stream, its distribution statistics, such as mean, standard deviation, skewness, and other feature indicators, are extracted, or abrupt changes and segmentation characteristics in the data stream are detected. Based on the monitored data stream characteristics, combined with preset optimization strategies (such as setting by percentiles or based on anomaly detection), a target calibration threshold that can reasonably distinguish between normal queries and slow queries is dynamically determined. Alternatively, clustering algorithms (such as Gaussian mixture model clustering) can be used to perform unsupervised clustering analysis on the mixture dissimilarity, automatically generating the target calibration threshold based on cluster centers or boundary values; or an adaptive sliding window mechanism can be introduced to dynamically track the dissimilarity change trend and self-adjust based on the rate of change to determine the target calibration threshold, thereby further improving the system's responsiveness and stability to changes in query load. The above method enables dynamic, accurate, and adaptive determination of the target calibration threshold, avoiding errors caused by manual experience setting, improving the accuracy of slow query detection and the real-time performance of the system, while enhancing the system's self-adaptation and optimization capabilities under different load environments.

[0067] Optionally, after analyzing whether the query statement to be analyzed is a slow query based on the comparison results, the method further includes: generating a judgment sample set based on the analysis results of the query statement to be analyzed, identifying misjudged samples in the judgment sample set, and optimizing the target calibration threshold or historical gene library based on the misjudged samples.

[0068] After analyzing whether the query to be analyzed is a slow query, a corresponding judgment sample set is generated based on the analysis results. The judgment sample set includes various samples that were judged as slow queries (passed or failed), reflecting the applicability of the current slow query judgment rules. False judgment detection is performed on the judgment sample set to identify incorrectly judged samples, such as those misjudged as slow queries or vice versa. Based on these false judgment samples, targeted optimization operations are performed. For example, the target calibration threshold can be dynamically adjusted based on the false judgment samples to make subsequent judgment criteria more accurate and reduce the false judgment rate. Similarly, the gene patterns in the historical gene pool can be optimized and corrected based on the false judgment samples, updating gene feature expression to enhance adaptability to special query patterns or new query structures. Furthermore, machine learning methods can be introduced, such as feature retraining based on false judgment samples, adjusting the feature weights of the slow query judgment model through incremental learning mechanisms, thereby indirectly optimizing the target calibration threshold or the historical gene pool. Through the above methods, the present invention can achieve closed-loop self-optimization of slow query detection, that is, real-time correction of the judgment logic and feature library based on misjudged samples, thereby improving the accuracy, robustness and adaptability of slow query detection and effectively supporting dynamic and ever-changing data query environments.

[0069] According to a preferred embodiment of the present invention, a slow query diagnosis method based on fusion of syntactic structure weight analysis and gene encoding matching is provided. Specifically, firstly, to address the problem of performance defect misjudgment caused by insufficient structural sensitivity, a mechanism combining weighted AST (Abstract Syntax Tree) construction and gene encoding is proposed. During the SQL (Structured Statement) parsing stage, a syntax segmenter performs lexical and syntactic analysis on the input SQL statement to generate a basic AST structure. Through a subquery tagging engine, the AST nodes are recursively traversed to detect all nested SELECT statements (query statements) and identify them as subquery nodes. For subquery nodes, this embodiment introduces a dynamic weight injector, assigning dynamic weights to each node based on node type, nesting level, and execution cost characteristics. Specifically, a base weight of 0.7 is applied to the SUBQUERY node (subquery node), and an additional weight of 0.1 is added for each level of nesting depth to accurately reflect its importance in the overall query execution. The weight calculation of each node follows a preset weight configuration table. For example, for a JOIN node (connection node), if the associated field has no index, the weight is increased by 0.3 on the basis of the base weight of 0.6 to enhance the ability to identify potential performance bottlenecks.

[0070] To overcome performance evaluation biases caused by the lack of weight dimensions in traditional methods, this approach, based on a weighted AST, further standardizes the query structure through a gene encoding engine. Specifically, the execution order reordering unit reorders the AST nodes according to the natural execution order of the FROM clause, JOIN operation, and WHERE condition, and calculates a comprehensive weight based on node weight and logical depth, such as by adjusting the comprehensive weight W = original weight × log(nesting depth + 1). The reordered structure is processed by a weight normalization pool to eliminate weight scale differences caused by different SQL syntaxes, and then a standardized gene sequence is generated by an anti-mutation encoder. This gene sequence uniformly maps semantically equivalent structures, such as the equivalent transformation of JOIN operations, subqueries, and WITH expressions (common table expressions) with different orders, thereby effectively identifying the performance equivalence behind different SQL syntaxes and avoiding misjudgments caused by superficial differences.

[0071] To address the issue of missed detections due to insufficient dynamic adaptability under new query patterns, this embodiment constructs a dynamic DNA feature library and designs a self-learning comparison engine. The dynamic DNA feature library pre-includes gene coding patterns of over 300 known performance defects, covering typical problems such as unnecessary subqueries, Cartesian product JOINs, and indexless sorting. For each diagnostic query sample, the adaptive comparison engine uses a difference calculator to measure the similarity between the gene coding of the input query and the defect coding in the feature library. If the difference is lower than the dynamic threshold θ, it is identified as a potential defect. To adapt to changes in query patterns, the difference threshold θ is not fixed but dynamically adjusted based on actual detection results. The adjustment formula is θ_new = θ_old + 0.05 × (Δactual - Δpredicted), where Δactual represents the difference between the true missed detection rate and the hit rate, and Δpredicted is the expected error, thereby achieving self-optimization of diagnostic sensitivity. Furthermore, to further improve robustness, this embodiment introduces a fuzzy matching strategy in the difference calculation, allowing for variations in node weights and order within a certain range to capture potential variant query patterns.

[0072] In terms of system implementation, the core components of this embodiment include: a weighted AST parser in the input layer, a gene coding engine and an adaptive alignment engine in the computation layer, a dynamic DNA feature library in the storage layer, and a containerized deployment platform in the infrastructure layer. These components are interconnected via a RESTful API protocol (a web service interface protocol based on the REST architectural style) to ensure efficient and reliable data processing.

[0073] In summary, this embodiment, by integrating weighted AST construction, execution order-sensitive gene encoding, dynamic threshold adaptive mechanism, and self-learning defect comparison system, can not only accurately identify potential performance problems in complex nested queries and equivalent rewriting scenarios, but also effectively address new defects brought about by the evolution of query patterns, significantly improving the comprehensiveness, accuracy, and adaptability of slow query analysis and diagnosis.

[0074] According to a second aspect of the present invention, a slow query analysis apparatus is provided.

[0075] Figure 3 This is a schematic diagram of the main modules of a slow query analysis device according to an embodiment of the present invention. Figure 3 As shown, the slow query analysis device 300 includes:

[0076] Module 301 is used to construct a weighted abstract syntax tree based on the query statement to be analyzed, traverse the weighted abstract syntax tree, and generate the target gene coding sequence according to the preset gene rule library;

[0077] The determination module 302 is used to retrieve similar gene patterns corresponding to the target gene coding sequence from the historical gene database, and determine the mixed difference degree corresponding to the target gene coding sequence based on the similar gene patterns; wherein, the mixed difference degree includes gene sequence difference degree and substructure difference degree;

[0078] Analysis module 303 is used to compare the mixing difference with the target calibration threshold and analyze whether the query statement to be analyzed is a slow query based on the comparison results.

[0079] Optionally, the building module 301 is also used for:

[0080] The query statement to be analyzed is parsed to generate an initial abstract syntax tree; the initial abstract syntax tree includes multiple nodes.

[0081] Based on the field access characteristic information corresponding to the query statement to be analyzed, the nodes in the abstract syntax tree are weighted to obtain a weighted abstract syntax tree; among them, the field access characteristic information includes field selectivity and index coverage.

[0082] Optionally, the building module 301 is also used for:

[0083] By traversing the weighted abstract syntax tree through the gene coding engine, multiple nodes are mapped to multiple gene fragments based on a preset gene rule base.

[0084] Multiple gene fragments are spliced ​​together to generate an initial gene coding sequence;

[0085] The initial gene coding sequence is subjected to noise reduction processing based on the preset variation constraint matrix to obtain the target gene coding sequence.

[0086] Optionally, the determining module 302 is also used for:

[0087] The weighted edit distance algorithm is used to determine the gene sequence difference between similar gene patterns and target gene coding sequences;

[0088] Key subtrees are extracted from the weighted abstract syntax tree, and the structural similarity of the key subtrees is compared with that of the preset sliding window baseline library to obtain the substructure difference degree.

[0089] The gene sequence difference and the substructure difference are weighted and fused to obtain the mixed difference corresponding to the target gene coding sequence.

[0090] Optionally, the analysis device 300 also includes a monitoring module, which is used for:

[0091] Generate a difference data stream based on the mixed difference values ​​corresponding to multiple query statements to be analyzed;

[0092] Monitor the difference data stream and determine the target calibration threshold based on the monitoring results.

[0093] Optionally, the analysis apparatus 300 further includes an optimization module, which is used for:

[0094] A judgment sample set is generated based on the analysis results of the query statement to be analyzed, and the misjudged samples in the judgment sample set are identified.

[0095] Optimize the target calibration threshold or historical gene pool based on misjudged samples.

[0096] It should be noted that the specific implementation details of the slow query analysis device of the present invention have been described in detail in the slow query analysis method above, so the details will not be repeated here.

[0097] According to a third aspect of the present invention, an electronic device is provided, comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the present invention.

[0098] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method provided in the first aspect of the present invention.

[0099] According to a fifth aspect of the present invention, a computer program product is provided, including a computer program that, when executed by a processor, implements the method provided in the first aspect of the present invention.

[0100] Figure 4An exemplary system architecture 400 is shown that can be applied to the slow query analysis method or slow query analysis apparatus of the present invention.

[0101] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, and 403, a network 404, and a server 405. Network 404 serves as the medium for providing communication links between terminal devices 401, 402, and 403 and server 405. Network 404 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0102] Users can use terminal devices 401, 402, and 403 to interact with server 405 via network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, and 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).

[0103] Terminal devices 401, 402, and 403 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0104] Server 405 can be a server that provides various services, such as a backend management server that supports shopping websites browsed by users using terminal devices 401, 402, and 403 (for example only). The backend management server can analyze and process data such as received slow query analysis requests, and feed back the processing results (such as slow query analysis results - for example only) to the terminal devices.

[0105] It should be noted that the slow query analysis method provided in this embodiment of the invention is generally run by server 405, and correspondingly, the slow query analysis device is generally set in server 405.

[0106] It should be understood that Figure 4 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0107] The following is for reference. Figure 5 It shows a schematic diagram of the structure of a computer system 500 suitable for implementing a terminal device of the present invention. Figure 5 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0108] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 502 or programs loaded from storage section 508 into random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of the system 500. The CPU 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0109] The following components are connected to I / O interface 505: an input section 506 including a keyboard, mouse, etc.; an output section 507 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, modem, etc. The communication section 509 performs communication processing via a network such as the Internet. Drive 510 is also connected to I / O interface 505 as needed. Removable media 511, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 510 as needed so that computer programs read from them can be installed into storage section 508 as needed.

[0110] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable 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 communication section 509, and / or installed from removable medium 511. When the computer program is run by the central processing unit (CPU) 501, it performs the functions defined above in the system of this invention.

[0111] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination thereof. 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 invention, 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 invention, 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. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit programs for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0112] 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 the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more operable 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 operate substantially in parallel, and they may sometimes operate in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may 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.

[0113] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor can be described as including a construction module, a determination module, and an analysis module. The names of these modules do not necessarily limit the module itself; for example, the analysis module can also be described as "a module for comparing the mixing difference with a target calibration threshold and analyzing whether the query to be analyzed is a slow query based on the comparison results."

[0114] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include: constructing a weighted abstract syntax tree based on a query statement to be analyzed; traversing the weighted abstract syntax tree; generating a target gene coding sequence according to a preset gene rule base; retrieving similar gene patterns corresponding to the target gene coding sequence from a historical gene database; determining the mixed difference degree corresponding to the target gene coding sequence based on the similar gene patterns; wherein the mixed difference degree includes gene sequence difference degree and substructure difference degree; comparing the mixed difference degree with a target calibration threshold; and analyzing whether the query statement to be analyzed is a slow query based on the comparison result.

[0115] The computer program product provided in this embodiment of the invention includes a computer program that, when executed by a processor, implements the slow query analysis method in this embodiment of the invention.

[0116] The technical solution of this invention has the following advantages or beneficial effects: A weighted abstract syntax tree is constructed based on the query statement to be analyzed; the weighted abstract syntax tree is traversed; a target gene coding sequence is generated according to a preset gene rule base; similar gene patterns corresponding to the target gene coding sequence are retrieved from a historical gene database; and the mixed difference degree corresponding to the target gene coding sequence is determined based on the similar gene patterns; wherein, the mixed difference degree includes gene sequence difference degree and substructure difference degree; the mixed difference degree is compared with a target calibration threshold; and the query statement to be analyzed is analyzed based on the comparison results to determine whether it is a slow query. This embodiment improves structural sensitivity by constructing a weighted abstract syntax tree and gene coding, achieving performance equivalence recognition of different writing styles, thereby improving the accuracy of the recognition results.

[0117] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

[0118] It should be noted that the acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

Claims

1. A method of slow query analysis, the method comprising: include: A weighted abstract syntax tree is constructed based on the query statement to be analyzed. The weighted abstract syntax tree is traversed, and the target gene coding sequence is generated according to the preset gene rule library. Similar gene patterns corresponding to the target gene coding sequence are retrieved from the historical gene database, and the mixed difference degree corresponding to the target gene coding sequence is determined based on the similar gene patterns; wherein, the mixed difference degree includes gene sequence difference degree and substructure difference degree; The mixture difference is compared with the target calibration threshold, and the query statement to be analyzed is analyzed based on the comparison results to determine whether it is a slow query.

2. The method of claim 1, wherein, A weighted abstract syntax tree is constructed based on the query statement to be analyzed, including: The query statement to be analyzed is parsed to generate an initial abstract syntax tree; wherein the initial abstract syntax tree includes multiple nodes; Based on the obtained field access characteristic information corresponding to the query statement to be analyzed, the nodes in the abstract syntax tree are weighted to obtain a weighted abstract syntax tree; wherein, the field access characteristic information includes field selectivity and index coverage.

3. The method of claim 2, wherein, Traverse the weighted abstract syntax tree and generate the target gene coding sequence according to the preset gene rule base, including: The weighted abstract syntax tree is traversed by the gene coding engine, and the multiple nodes are mapped to multiple gene fragments based on the preset gene rule base. The multiple gene fragments are spliced ​​together to generate an initial gene coding sequence; The initial gene coding sequence is subjected to noise reduction processing based on a preset variation constraint matrix to obtain the target gene coding sequence.

4. The method of claim 1, wherein, Determining the degree of mixture dissimilarity corresponding to the target gene coding sequence based on the similar gene pattern includes: The gene sequence difference between the similar gene patterns and the target gene coding sequence is determined based on a weighted edit distance algorithm. The key subtree is extracted from the weighted abstract syntax tree, and the key subtree is compared with the preset sliding window baseline library to obtain the substructure difference degree. The gene sequence difference and the substructure difference are weighted and fused to obtain the mixed difference corresponding to the target gene coding sequence.

5. The method according to claim 1, characterized in that, The target calibration threshold is determined through the following steps: Generate a difference data stream based on the mixed difference values ​​corresponding to multiple query statements to be analyzed; Monitor the difference data stream and determine the target calibration threshold based on the monitoring results.

6. The method according to claim 1, characterized in that, After analyzing whether the query statement to be analyzed is a slow query based on the comparison results, the following steps are also included: A judgment sample set is generated based on the analysis results of the query statement to be analyzed, and the misjudged samples in the judgment sample set are identified. The target calibration threshold or the historical gene library is optimized based on the misjudged samples.

7. A slow query analysis device, characterized in that, include: The construction module is used to build a weighted abstract syntax tree based on the query statement to be analyzed, traverse the weighted abstract syntax tree, and generate the target gene coding sequence according to the preset gene rule library; The determination module is used to retrieve similar gene patterns corresponding to the target gene coding sequence from the historical gene database, and determine the mixed difference degree corresponding to the target gene coding sequence based on the similar gene patterns; wherein, the mixed difference degree includes gene sequence difference degree and substructure difference degree; The analysis module is used to compare the mixing difference with the target calibration threshold, and analyze whether the query statement to be analyzed is a slow query based on the comparison result.

8. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-6.

9. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-6.