Knowledge distillation-based database test method, system, equipment and medium

By using multimodal feature extraction based on knowledge distillation and deep learning models, the inefficiency and false positive problems of existing database testing methods are solved, realizing intelligent database testing with high coverage and low human intervention, and improving the accuracy and adaptability of anomaly detection.

CN122019397AActive Publication Date: 2026-05-12民航机场成都电子工程设计有限责任公司
View PDF 5 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
民航机场成都电子工程设计有限责任公司
Filing Date
2026-04-16
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Existing database testing methods are inefficient, and the test coverage is highly subjective and random, making it difficult to discover potential defects in complex scenarios. Furthermore, automated testing frameworks suffer from misjudgments and lack self-evolution capabilities, making them unable to effectively identify new types of defects.

Method used

By employing a knowledge distillation-based approach, teacher and student models are constructed through multimodal feature extraction and deep learning models to achieve accurate representation and prediction of database execution behavior. The model is then updated using knowledge distillation techniques, forming a self-optimizing closed loop.

Benefits of technology

It achieves intelligent database function testing with high coverage and low human intervention, improves the accuracy and interpretability of anomaly detection, and can adaptively identify new defects, thereby improving testing efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122019397A_ABST
    Figure CN122019397A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of database testing, in particular to a database testing method, system and equipment based on knowledge distillation and a medium, and the method comprises the following steps: constructing a multi-modal feature extractor, and performing multi-dimensional feature extraction on an input structured query statement and an execution context thereof; training the first network model based on a multi-modal feature sample generated by executing the historical test case in the reference database and execution behavior data corresponding to the multi-modal feature sample to obtain a teacher model; training the second network model according to the output probability distribution of the teacher model and the middle layer features to obtain a student model; and processing the structured query statement query of the to-be-tested database by the multi-modal feature extractor, respectively inputting the processed structured query statement query into the trained teacher model and student model, and judging whether functional abnormality exists in the current query or not according to the difference of output prediction results. The objective of the invention is to realize database function testing with high coverage rate, low manual intervention and interpretability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database testing technology, and specifically to database testing methods, systems, equipment, and media based on knowledge distillation. Background Technology

[0002] Currently, functional testing of database systems primarily relies on manual work by test engineers and script-based automated testing frameworks. In manual testing, engineers design test cases based on requirements specifications and past experience. This method is not only inefficient, but also highly subjective and random in its test coverage, making it difficult to systematically construct complex scenarios such as boundary conditions, concurrent transaction sequences, and extreme parameter configurations. This results in many potential defects going undetected. While automated testing frameworks improve execution efficiency through script recording and playback, they fundamentally fail to address the issue of test case generation. The richness and effectiveness of the test case library depend on manual maintenance, inherently limiting its capabilities.

[0003] In the field of database compatibility testing, existing technologies often employ a method of comparing the results of the database under test with those of a mature database as benchmarks. This involves simply comparing the execution results of the database under test with the output of the benchmark database to determine functional correctness. However, due to objective differences in design philosophy, functional implementation paths, and the degree of SQL standard support among different database products, simple result comparisons can lead to numerous misjudgments due to reasonable differences, introducing a large amount of noise into defect analysis. Secondly, existing comparison methods only remain at a superficial level of comparing the final result set or return code, lacking correlation analysis of deep execution behavior characteristics such as execution plans, locking mechanisms, transaction logs, and resource consumption. This makes it difficult for developers to quickly locate the root cause of problems, increasing debugging and repair costs. Furthermore, existing testing processes present an open-loop structure, with test case libraries in a static state. This prevents the learning and abstraction of characteristic patterns leading to defects from discovered anomalies. The testing system itself lacks self-evolution capabilities, making it difficult to adaptively identify new defects, thus limiting the improvement of test coverage and the continuous optimization of testing efficiency. Summary of the Invention

[0004] To achieve high coverage, low human intervention, and interpretable database functional testing through intelligent feature modeling and difference detection, this invention provides a database testing method, system, device, and medium based on knowledge distillation. The specific technical solution adopted is as follows:

[0005] The first aspect of the present invention provides a database testing method based on knowledge distillation, the method comprising: Construct a multimodal feature extractor to extract multi-dimensional features from the input structured query statement and its execution context, and convert the extraction results into feature vectors; Based on the multimodal feature samples generated from historical test cases executed on the benchmark database and their corresponding execution behavior data, the first network model is trained to obtain a teacher model used to characterize the execution behavior of the benchmark database. Based on the output probability distribution of the teacher model and the features of the intermediate layer, the second network model is trained to obtain the student model used to predict the execution behavior of the database under test. The structured query statement of the database under test is processed by the multimodal feature extractor and then input into the trained teacher model and student model respectively. The difference in the output prediction results is used to determine whether there is a functional abnormality in the current query. The query samples identified as abnormal and their execution information are fed back to the training sample set to incrementally update the teacher model, and the student model is updated synchronously through knowledge distillation.

[0006] Furthermore, a multimodal feature extractor is constructed to extract multi-dimensional features from the input structured query statement and its execution context, and the extraction results are converted into feature vectors, including: Lexical analysis and syntactic parsing are performed on the input structured query statement to generate an abstract syntax tree, and syntactic structural features containing operation types, table column dependencies and predicate distribution information are extracted. The execution plan of structured query statements in the database is parsed to extract execution plan features including operator sequence, operator estimated cost, actual number of rows executed, and index usage. Collect system status data during database operation and extract runtime status features including CPU utilization, memory usage, lock wait event sequences, and transaction log information; The result set returned after the execution of the structured query statement is hashed to generate a digital signature of the result set, and the cardinality and column value range distribution information of the result set are extracted as the result signature features; The grammatical structure features, execution plan features, runtime state features, and result signature features are vectorized, aligned, and fused to obtain feature vectors.

[0007] Furthermore, based on the multimodal feature samples generated from executing historical test cases in the benchmark database and their corresponding execution behavior data, the first network model is trained to obtain a teacher model used to characterize the execution behavior in the benchmark database, including: Construct a first network model, which includes a first branch for processing syntactic structure features, a second branch for processing execution plan features, and a third branch for processing runtime state features. A hierarchical attention mechanism is set at the output of each branch to adaptively weight and fuse the features of the multi-branch outputs to generate a comprehensive behavioral representation vector. The first network model is trained using a multi-task learning framework. The training tasks include at least a result signature prediction task based on contrastive learning and an execution plan regression task based on mean squared error. Using verified correct execution behavior data from historical test cases as supervisory signals, and combining weight decay regularization strategies to optimize the parameters of the first network model, the teacher model learns the execution behavior mapping relationship of the benchmark database in the multi-dimensional feature space.

[0008] Furthermore, based on the output probability distribution of the teacher model and the features of the intermediate layer, the second network model is trained to obtain a student model for predicting the execution behavior of the test database, including: Construct a second network model and calculate the KL divergence between the prediction results of the second network model and the soft label probability distribution output by the teacher model, which is used as the first distillation loss; The intermediate layer features of the second network model are mapped to the implicit feature space of the teacher model through a projection matrix. The mean square error between the mapped features and the corresponding layer features of the teacher model is calculated as the feature alignment loss. A comprehensive loss function is constructed based on the first distillation loss and feature alignment loss, and the parameters of the second network model are optimized.

[0009] Furthermore, based on the output probability distribution of the teacher model and the features of the intermediate layer, the second network model is trained to obtain a student model for predicting the execution behavior of the test database, which also includes: An adversarial distillation loss function is constructed, which adjusts the hidden layer feature distribution of the student model by minimizing the probability that the discriminator network correctly identifies the features generated by the student model. The sample weight coefficients are calculated based on the predicted entropy value output by the teacher model, and an uncertainty-aware sample weighted loss function is constructed. The sample weighted loss function adjusts the contribution of different samples in training according to the sample weight coefficients. The adversarial distillation loss function and the uncertainty-aware sample weighted loss function are added to the comprehensive loss function, which together with the first distillation loss and the feature alignment loss function constitute a multi-objective optimization framework. The student model is jointly optimized through a dynamic weight allocation mechanism.

[0010] Furthermore, the structured query statements from the database under test are processed by a multimodal feature extractor and then input into the trained teacher and student models, respectively. The differences in the output prediction results are used to determine whether the current query exhibits functional abnormalities, including: Calculate the first sub-score in the result signature channel, the second sub-score in the execution plan channel, the third sub-score in the transaction log channel, and the fourth sub-score in the system status channel for the first prediction result output by the teacher model and the second prediction result output by the student model. The comprehensive anomaly score is calculated by weighting and fusing the first sub-score, the second sub-score, the third sub-score, and the fourth sub-score together with preset weighting coefficients. The comprehensive anomaly score is compared with a preset decision threshold. If the comprehensive anomaly score exceeds the preset decision threshold, it is determined that the current query has a functional anomaly.

[0011] Furthermore, the query samples identified as abnormal and their execution information are fed back to the training sample set to incrementally update the teacher model, and the student model is synchronously updated through knowledge distillation, including: Based on the updated training sample set, the teacher model is retrained using an incremental learning strategy to fit the boundary data distribution contained in the newly added abnormal samples. Based on the joint analysis of the prediction confidence of the student model and the difference between the output of the teacher model and the student model, samples with confidence scores below the first threshold and differences greater than the second threshold are selected from the newly added abnormal samples as priority labeled samples and included in the next round of training sample set. The updated teacher model is used as a knowledge source, and the student model is then adjusted or retrained using knowledge distillation techniques.

[0012] The second aspect of the present invention provides a database testing system based on knowledge distillation, used to execute the database testing method based on knowledge distillation described in the first aspect of the present invention, the system comprising: The multimodal feature extraction module is configured to build a multimodal feature extractor, perform multi-dimensional feature extraction on the input structured query statement and its execution context, and convert the extraction results into feature vectors; The teacher model training module is configured to train the first network model based on multimodal feature samples generated by executing historical test cases from the benchmark database and their corresponding execution behavior data, thereby obtaining a teacher model that represents the execution behavior of the benchmark database. The student model training module is configured to train the second network model based on the output probability distribution of the teacher model and the intermediate layer features, so as to obtain a student model for predicting the execution behavior of the database under test. The anomaly detection module is configured to process the structured query statement of the database under test through a multimodal feature extractor, and then input it into the trained teacher model and student model respectively, and determine whether there is a functional anomaly in the current query based on the difference in the output prediction results. The self-learning update module is configured to feed back query samples judged as abnormal and their execution information to the training sample set, incrementally update the teacher model, and synchronously update the student model through knowledge distillation.

[0013] The third aspect of the present invention provides an electronic device, comprising: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, which, when executed, enable the at least one processor to perform the knowledge distillation-based database testing method as described in the first aspect of the present invention.

[0014] The fourth aspect of the present invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the database testing method based on knowledge distillation as described in the first aspect of the present invention.

[0015] The present invention has the following beneficial effects: This invention provides a database testing method based on knowledge distillation. It extracts multi-dimensional features from structured query statements and their execution context, converting them into feature vectors. A teacher model is trained using historical test data from a benchmark database, enabling it to accurately represent the execution behavior of mature databases and establishing a reliable reference benchmark for functional verification. A student model is trained using knowledge distillation based on the output probability distribution of the teacher model and intermediate layer features. This lightweight student model efficiently predicts the execution behavior of the database under test, ensuring detection accuracy while remaining suitable for online testing environments. The query from the database under test, after feature extraction, is input into both the teacher and student models. The difference between their predicted outputs is used to determine if functional anomalies exist, achieving a leap from single-result comparison to multi-dimensional behavioral feature difference analysis. This effectively avoids misjudgments due to reasonable differences and improves the accuracy and interpretability of anomaly detection. Anomaly-identified samples and their execution information are fed back to the training sample set and incrementally updated in the teacher model. Knowledge distillation then synchronously updates the student model, forming a continuous self-optimization closed loop for the testing model. This allows the testing system to continuously learn and accumulate experience from detected anomalies, achieving adaptive identification of new defects. Therefore, this invention achieves a high-coverage, low-manual-intervention, and interpretable intelligent database function testing process, thereby improving testing efficiency and accuracy. Attached Figure Description

[0016] The above and other objects, features, and advantages of the present invention will become more apparent from the more detailed description of the embodiments of the invention in conjunction with the accompanying drawings. The drawings are provided to further illustrate the embodiments of the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings, the same reference numerals generally represent the same parts or steps.

[0017] Figure 1 This is a schematic diagram of a database testing method based on knowledge distillation provided in an exemplary embodiment of the present invention; Figure 2 This is a schematic diagram of the database testing system structure based on knowledge distillation provided in an exemplary embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of an application embodiment of the electronic device of the present invention. Detailed Implementation

[0018] The present invention will be further described below with reference to the embodiments shown in the accompanying drawings. Obviously, the described embodiments are merely some embodiments of the present invention, and not all embodiments of the present invention. It should be understood that the present invention is not limited to the exemplary embodiments described herein.

[0019] It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values ​​of the components and steps described in these embodiments do not limit the scope of the invention.

[0020] Those skilled in the art will understand that the terms "first," "second," etc., in the embodiments of the present invention are only used to distinguish different steps, devices, or modules, and do not represent any specific technical meaning, nor do they indicate a necessary logical order between them.

[0021] It should also be understood that in the embodiments of the present invention, "multiple" can refer to two or more, and "at least one" can refer to one, two or more.

[0022] It should also be understood that any component, data or structure mentioned in the embodiments of the present invention can generally be understood as one or more unless explicitly defined or given contrary instructions in the context.

[0023] Furthermore, the term "and / or" in this invention is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this invention generally indicates that the preceding and following related objects have an "or" relationship.

[0024] It should also be understood that the description of the various embodiments in this invention emphasizes the differences between the various embodiments, and the similarities or similarities can be referred to each other. For the sake of brevity, they will not be described in detail.

[0025] At the same time, it should be understood that, for ease of description, the dimensions of the various parts shown in the accompanying drawings are not drawn according to actual scale.

[0026] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the invention or its application or use.

[0027] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.

[0028] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.

[0029] Example 1 Figure 1 This is a schematic flowchart of a database testing method based on knowledge distillation provided by an exemplary embodiment of the present invention. The method can be executed on a server (e.g., a cloud service platform, a locally deployed server).

[0030] Specifically, refer to Figure 1 The database testing method based on knowledge distillation includes: Step 100: Construct a multimodal feature extractor to extract multi-dimensional features from the input structured query statement and its execution context, and convert the extracted results into feature vectors. Specifically, this step aims to transform unstructured SQL queries and their related execution information into machine-learnable structured feature representations. First, lexical analysis and syntax parsing are performed on the input structured query statement to generate an abstract syntax tree, and syntactic structure features containing operation types, table column dependencies, and predicate distribution information are extracted from the abstract syntax tree. Second, the execution plan of the structured query statement in the database is parsed, and execution plan features containing operator sequences, operator estimated costs, actual number of rows executed, and index usage are extracted from the execution plan. Third, system status data during database operation is collected, and runtime status features containing CPU utilization, memory usage, lock wait event sequences, and transaction log information are extracted. Then, the result set returned after the structured query statement is executed is hashed to generate a digital signature for the result set, and the cardinality and column value range distribution information of the result set are extracted as result signature features. Finally, the syntactic structure features, execution plan features, runtime state features, and result signature features are vectorized, aligned, and fused to obtain a feature vector of uniform dimension, which serves as the standard data format for subsequent model input.

[0031] Step 200: Based on the multimodal feature samples generated by executing historical test cases in the benchmark database and their corresponding execution behavior data, train the first network model to obtain a teacher model used to characterize the execution behavior of the benchmark database. Specifically, this step aims to construct a high-capacity teacher model capable of learning and representing the execution behavior of a benchmark database. First, a first network model is constructed, employing a multi-branch architecture. This model includes a first branch for processing syntactic structure features, a second branch for processing execution plan features, and a third branch for processing runtime state features. The first branch uses a graph neural network or transformer network to encode the abstract syntax tree, extracting deep syntactic and semantic representations. The second branch uses a sequence-to-sequence model or tree-structured encoder to model the execution plan operator sequence, capturing the topological structure and execution order features of the operators. The third branch uses a long short-term memory network or temporal convolutional network to process the runtime state temporal data, extracting the dynamic changes in system state. A hierarchical attention mechanism is implemented at the output of each branch to adaptively weight and fuse the features output from multiple branches. Weights are dynamically assigned based on the importance of each modality feature to the current query, generating a comprehensive behavioral representation vector. Second, a multi-task learning framework is used to train the first network model. The training tasks include at least a result signature prediction task based on contrastive learning and an execution plan regression task based on mean squared error. The result signature prediction task aims to teach the model the mapping relationship from input features to the digital signatures of the result set. A contrastive learning loss function is used to ensure that the result signatures of similar queries remain close in the feature space. The execution plan regression task teaches the model to predict the operator sequence and key statistics of the execution plan, using a mean squared error loss function to measure the deviation between the predicted and actual values. Finally, based on the validated execution behavior data from historical test cases as supervision signals, the parameters of the first network model are optimized using a weight decay regularization strategy. This enables the teacher model to learn the mapping relationship of the benchmark database's execution behavior in the multi-dimensional feature space, ultimately obtaining a teacher model capable of representing the execution behavior of the benchmark database.

[0032] Step 300: Based on the output probability distribution of the teacher model and the intermediate layer features, train the second network model to obtain the student model used to predict the execution behavior of the database under test. Specifically, this step aims to transfer knowledge from the teacher model to a lightweight student model using knowledge distillation. First, a second network model is constructed, employing a lightweight architecture with depthwise separable convolutional layers or shallow transformer structures with reduced parameters to reduce computational complexity and inference latency. Second, the KL divergence between the predictions of the second network model and the soft-label probability distribution output by the teacher model is calculated as the first distillation loss. Then, the intermediate layer features of the second network model are mapped to the implicit feature space of the teacher model using a projection matrix, and the mean squared error between the mapped features and the corresponding layer features of the teacher model is calculated as the feature alignment loss. A comprehensive loss function is constructed based on the first distillation loss and the feature alignment loss to optimize the parameters of the second network model. Furthermore, to further improve the distillation effect, an enhanced distillation strategy can be introduced, constructing an adversarial distillation loss function. This function adjusts the hidden feature distribution of the student model by minimizing the probability that the student model's generated features are correctly identified by the discriminator network, making it difficult to distinguish from the hidden feature distribution of the teacher model. Based on the predicted entropy value output by the teacher model, sample weight coefficients are calculated, and an uncertainty-aware sample weighted loss function is constructed. This loss function adjusts the contribution of different samples in training according to the sample weight coefficients, assigning higher weights to high-confidence samples to strengthen their training effect. The adversarial distillation loss function and the uncertainty-aware sample weighted loss function are added to the comprehensive loss function, which, together with the first distillation loss and the feature alignment loss function, constitutes a multi-objective optimization framework. The student model is jointly optimized through a dynamic weight allocation mechanism, ultimately obtaining a student model that can efficiently predict the execution behavior of the test database.

[0033] Step 400: After the structured query statement of the database to be tested is processed by the multimodal feature extractor, it is input into the trained teacher model and student model respectively, and the difference in the output prediction results is used to determine whether there is a functional abnormality in the current query. Specifically, this step aims to achieve anomaly detection through the collaborative work of teacher-student models. The structured query statement of the database to be tested is input into the multimodal feature extractor, and corresponding feature vectors are generated according to the method described in step 100. These feature vectors are then input into the trained teacher model and student model respectively. The teacher model outputs a first prediction result based on the behavior patterns of the benchmark database, and the student model outputs a second prediction result based on the behavior patterns of the database to be tested, and a comprehensive anomaly score is calculated. Finally, the comprehensive anomaly score is compared with a preset decision threshold. If the comprehensive anomaly score exceeds the preset decision threshold, the current query is determined to have a functional anomaly.

[0034] Step 500: Feed back the query samples identified as abnormal and their execution information to the training sample set, incrementally update the teacher model, and synchronously update the student model through knowledge distillation.

[0035] Specifically, this step aims to construct a self-learning closed loop for the testing system, enabling continuous model evolution. First, the query samples identified as abnormal in step 400, along with their complete execution information (including feature vectors, actual execution results, and anomaly scores), are fed back into the training sample set, expanding the existing multimodal feature sample library. Based on the updated training sample set, an incremental learning strategy is used to retrain the teacher model, enabling it to fit the boundary data distribution contained in the newly added abnormal samples. The incremental learning strategy only fine-tunes the model parameters rather than completely retraining, maintaining the stability of existing knowledge while absorbing new knowledge. Second, based on the joint analysis of the student model's prediction confidence and the differences between the teacher and student model outputs, samples with confidence levels below a first threshold and differences greater than a second threshold are selected from the newly added abnormal samples as priority labeled samples and included in the next round of training sample set. Then, using the updated teacher model as a new knowledge source, the student model's parameters are fine-tuned or retrained again using knowledge distillation techniques, ensuring the student model synchronously acquires the updated knowledge and maintains consistency with the teacher model. Through iterative steps, the testing system can continuously learn and accumulate experience from detected anomalies, achieving adaptive identification capabilities for new types of defects.

[0036] As described above, the database testing method based on knowledge distillation provided by this invention extracts multi-dimensional features from structured query statements and their execution context, converts them into feature vectors, and trains a teacher model based on historical test data from a benchmark database. This model accurately represents the execution behavior of mature databases, establishing a reliable reference benchmark for functional verification. Through knowledge distillation, a student model is trained based on the output probability distribution of the teacher model and intermediate layer features. This lightweight student model efficiently predicts the execution behavior of the database under test, ensuring detection accuracy while being suitable for online testing environments. The query from the database under test, after feature extraction, is input into both the teacher and student models. The difference between their output predictions determines whether functional anomalies exist, achieving a leap from single-result comparison to multi-dimensional behavioral feature difference analysis. This effectively avoids misjudgments due to reasonable differences and improves the accuracy and interpretability of anomaly detection. Samples identified as anomalies and their execution information are fed back to the training sample set and incrementally updated in the teacher model. Then, knowledge distillation synchronously updates the student model, forming a continuous self-optimization closed loop for the testing model. This allows the testing system to continuously learn and accumulate experience from detected anomalies, achieving adaptive identification of new defects.

[0037] Example 2 Based on Embodiment 1 above, as an optional implementation, a multimodal feature extractor is constructed to extract multi-dimensional features from the input structured query statement and its execution context, and the extraction results are converted into feature vectors, including: Step 110: Perform lexical analysis and syntactic parsing on the input structured query statement to generate an abstract syntax tree (AST) and extract syntactic structural features containing information on operation types, table column dependencies, and predicate distribution. Specifically, this step aims to extract deep syntactic structural information from the text form of the SQL statement. First, perform lexical analysis on the input structured query statement, splitting the continuous SQL text string into a series of lexical units with independent semantics, including keywords, identifiers, operators, constants, etc. Then, perform syntactic parsing, organizing the sequence of lexical units into a tree structure, i.e., the abstract syntax tree, according to the syntactic rules of the SQL statement. The abstract syntax tree expresses the syntactic structure of the SQL statement in a tree-like form, where each node corresponds to a syntactic component. For example, the root node represents the entire query statement, and child nodes represent components such as the SELECT clause, FROM clause, and WHERE clause. Based on the abstract syntax tree, further extract three types of syntactic structural features: Operation type characteristics: By identifying key nodes in the tree, the basic operation category of the query is determined, including data query operations such as SELECT, data operation operations such as INSERT, UPDATE, DELETE, and data definition operations such as CREATE, ALTER, etc. For complex queries, it is also necessary to identify the JOIN types they contain, such as inner join, outer join, cross join, and subquery types such as scalar subqueries, table subqueries, and correlated subqueries. Table column dependency characteristics are used to construct a dependency graph between the query statement and the underlying database objects by traversing the table name nodes and column name nodes involved in the abstract syntax tree, and to determine the data tables accessed by the query and the association relationships established between the tables through the join conditions. The predicate distribution information features focus on filtering predicates in WHERE clauses, HAVING clauses, and ON join conditions. It counts the number and type of predicates, such as comparison predicates, range predicates, null value judgments, pattern matching, and existence judgments. It analyzes the complexity of predicates, such as single predicates, multi-predicate combinations, and nested predicates, and extracts the column names involved in the predicates and their comparison relationships with constants.

[0038] Step 120: Parse the execution plan of the structured query statement in the database and extract the execution plan features, including operator sequence, operator estimated cost, actual number of rows executed, and index usage. Specifically, this step aims to capture the physical execution strategy employed by the database when executing SQL statements. First, the execution plan of the query is obtained using the EXPLAIN command or PROFILE tool provided by the database. The execution plan is typically presented in a tree structure or table format, describing the combination of operators selected by the database optimizer for executing the query and their execution order. Four key features are extracted from the execution plan: operator sequence features, which convert the tree structure of the execution plan into a linear sequence of operator nodes or an encoding that preserves the tree topology. Operator types include scan operators such as table scans, index scans, bitmap scans; join operators such as nested loop joins, hash joins, merge joins; aggregation operators such as grouping aggregations, sorting operators, deduplication operators, etc., each corresponding to a specific algorithm implementation and resource consumption pattern; operator cost estimation features, which extract the execution cost estimated by the optimizer for each operator, typically including startup cost, total cost, estimated number of output rows, and estimated row width. These estimates reflect the optimizer's prediction of the query execution cost, and comparison with the actual execution results can reveal… The data includes: 1) the accuracy deviation of the optimizer's estimation; 2) the actual number of rows processed, obtained by executing queries with PROFILE to determine the actual number of rows processed by each operator, including rows returned during the scan phase, intermediate result rows generated during the join phase, and groupings processed during the aggregation phase. Comparing the actual number of rows with the estimated number reflects the accuracy of the statistical information and the rationality of the optimizer selection; 3) index usage characteristics, identifying whether indexes were used in the execution plan and the type of index (e.g., B-tree index, hash index, bitmap index, full-text index), the index usage method (e.g., index scan, index-only scan, index condition filtering, index covering scan), and the degree of index matching (e.g., the number of columns matched by the index and the extent of index condition pushback). These features collectively constitute a quantitative description of the query execution process, providing a basis for subsequent analysis of query performance characteristics and identification of abnormal execution behavior.

[0039] Step 130: Collect system status data of the database during operation, and extract runtime status features including CPU utilization, memory usage, lock wait event sequence and transaction log information; Specifically, this step aims to capture the dynamic behavioral characteristics of the database system during query execution. First, during query execution, system status data is collected in real time through the operating system interface and database system views. The collection frequency can be set to milliseconds or seconds as needed to form a time-series data sequence. The collected data includes four categories: CPU utilization, which records the percentage of CPU time used by the database process during query execution, including user-mode CPU time and system-mode CPU time. High CPU utilization may indicate that the query involves a large amount of computation or that indexes are not being used effectively; memory usage, which monitors changes in the memory usage of the database process, including shared memory, working memory, and cache pool usage. Abnormal fluctuations in memory usage may indicate memory leaks or inefficient memory operations; lock wait event sequences, which capture lock acquisition, lock wait, lock escalation, and deadlock events that occur during query execution through the database's lock monitoring view. It records lock types such as table-level locks, row-level locks, intention locks, lock holding time, wait time, and the number of blocked transactions. Lock wait event sequences can reveal resource contention in concurrent scenarios; and transaction log information, which extracts transaction operation records related to the current query from the transaction log, including transaction start time, transaction commit or rollback time, log write volume, and log synchronization wait time. For write operations, it also records the number of modified data pages and the range of log sequence numbers. The collected raw time series data needs to be preprocessed, including outlier removal, missing value imputation, and data normalization. Then, the long time series is divided into fixed-length window sequences using the sliding window method. The time series data in each window is encoded through a temporal convolutional network or a long short-term memory network to extract deep feature representations that can characterize the dynamic changes in the system state, which serve as runtime state features.

[0040] Step 140: Hash the result set returned after the structured query statement is executed to generate a digital signature for the result set, and extract the cardinality and column value range distribution information of the result set as the result signature features; Specifically, to generate a digital signature for the result set, this embodiment employs a segmented hashing strategy: the result set is divided into multiple consecutive data blocks by rows, each containing a fixed number of rows. A hash value is calculated independently for each data block, and then the hash values ​​of all data blocks are combined sequentially and hashed again to obtain the final digital signature for the result set. The segmented hashing strategy can support local comparison of the result set while ensuring signature uniqueness, and can effectively reduce computational overhead when the result set is large. Secondly, the cardinality feature of the result set is extracted, i.e., the total number of rows returned in the result set, which reflects the data volume of the query results. Then, the column value range distribution information of the result set is extracted. For each column in the result set, its basic statistics include maximum, minimum, average, standard deviation, proportion of null values, and number of unique values. For multi-column result sets, correlation information between columns, such as Pearson correlation coefficient and Spearman rank correlation coefficient, also needs to be extracted.

[0041] Step 150: Perform vectorized alignment and fusion encoding on the syntax structure features, execution plan features, runtime state features, and result signature features to obtain feature vectors; Specifically, this step aims to uniformly encode the four heterogeneous features extracted in the preceding steps into a vector form that the model can process. In the syntactic structure features, the abstract syntax tree is encoded into a fixed-dimensional vector using a graph neural network or a tree-structured long short-term memory network; operation types are converted into vector form using one-hot encoding or embedding encoding; and table column dependencies can be constructed as adjacency matrices and encoded as vectors. In the execution plan features, operator sequences are converted into vectors using sequence encoding models such as transformer encoders; numerical features such as estimated costs and actual row counts are directly concatenated after normalization; and index usage is represented using multi-hot encoding or embedding encoding. Runtime state features are directly output as feature vectors after processing by a temporal convolutional network or a long short-term memory network. In the result signature features, digital signatures are directly used as fixed-length binary vectors; and the cardinality column value range distribution statistics are concatenated into numerical vectors after normalization. In some embodiments, due to the significant differences in the original dimensions of various features, each feature vector can be mapped to the same semantic space dimension through independent projection layers.

[0042] This embodiment constructs a multimodal feature representation system that fully covers the syntax structure, execution plan, runtime state, and result output. This transforms unstructured SQL queries and their execution process into structured, quantified feature vectors, providing a comprehensive and interpretable data foundation for deep learning-based anomaly detection models. The deep fusion of features across four dimensions enables both the teacher and student models to fully understand the query execution behavior from different granularities and levels, thereby improving the accuracy and interpretability of anomaly detection.

[0043] Example 3 Based on Embodiments 1 and 2 above, as an optional implementation, the first network model is trained using multimodal feature samples generated from historical test cases executed on the benchmark database and their corresponding execution behavior data to obtain a teacher model for characterizing the execution behavior of the benchmark database, including: Step 210: Construct a first network model, which includes a first branch for processing syntactic structure features, a second branch for processing execution plan features, and a third branch for processing runtime state features. Specifically, the first branch is the syntactic processing branch, which uses a graph neural network or transformer network architecture to encode the abstract syntax tree in the input syntactic structure features. The second branch is the plan processing branch, which uses a sequence-to-sequence model or tree structure encoder to model the execution plan features. The sequence-to-sequence model uses a long short-term memory network to process operator sequences, while the tree structure encoder aggregates operator information from bottom to top through a recurrent neural network and outputs a plan feature vector. The third branch is the temporal processing branch, which uses a long short-term memory network or temporal convolutional network to model the temporal data of the runtime state features, extracts the dynamic change pattern of the system state over time, and outputs a temporal feature vector.

[0044] Step 220: Set up a hierarchical attention mechanism at the output of each branch to adaptively weight and fuse the features of the multi-branch outputs to generate a comprehensive behavior representation vector; Specifically, this step dynamically adjusts the importance of each modality feature through an attention mechanism. First, the feature vectors output from the three branches are concatenated. Then, a learnable attention network is used to calculate the attention weights for each modality, reflecting the importance of each modality feature to the current query. The attention network can consist of fully connected layers and a softmax activation function, with the concatenated features as input and normalized weight coefficients as output. Finally, the feature vectors of each branch are weighted and summed with their corresponding weight coefficients to obtain a comprehensive behavioral representation vector that integrates multimodal information. This fusion vector combines information from three modalities, and the attention mechanism enables the model to adaptively adjust modality importance for different queries. Step 230: Train the first network model using a multi-task learning framework. The training tasks include at least a result signature prediction task based on contrastive learning and an execution plan regression task based on mean squared error. The model training uses a multi-task learning framework, and its loss function is defined as:

[0045] in, This is the total loss function value, used to guide the gradient update of model parameters; The weighting coefficients for the result signature prediction task are used to balance the contribution of that task to the total loss. The loss function value for the result signature prediction task is implemented using contrastive learning loss, which aims to make queries with the same result signature closer in the feature space and queries with different result signatures farther apart. Weighting coefficients for the regression task of the execution plan; To calculate the loss function value for the regression task of the execution plan, the mean squared error loss can be used to measure the deviation between the key statistics of the execution plan predicted by the model and the actual values. The weight coefficients for the regularization term; The regularization loss function value is achieved through weight decay and dropout mechanisms to prevent model overfitting. In this embodiment, the training dataset includes validated historical regression test samples, high-quality data manually labeled by experts, and boundary samples automatically generated through syntax-guided genetic programming techniques.

[0046] Step 240: Based on the verified correct execution behavior data in historical test cases as supervision signals, optimize the parameters of the first network model by combining the weight decay regularization strategy, so that the teacher model learns the execution behavior mapping relationship of the benchmark database in the multi-dimensional feature space. Specifically, this step uses validated execution behavior data from historical test cases as supervision signals, including digital signatures of the result set, detailed statistics of the execution plan, and labels of potential anomalous behaviors. Stochastic gradient descent or its variant optimizer is used to optimize parameters with the multi-task loss function defined in step 230 as the objective. The goal of the teacher model is to learn an accurate mapping from multimodal input features to high-fidelity execution behavior in the benchmark database, including the statistical distribution of intermediate results, the structural evolution trend of the execution plan under different loads, and labels of potential anomalous behaviors.

[0047] This embodiment constructs a teacher model with a multi-branch hybrid architecture, employing a multi-task learning framework to jointly optimize result signature prediction and execution plan regression tasks. By combining contrastive learning and mean squared error loss, it forces the model to adhere to the dual constraints of consistency in learning results and accuracy in the execution process. By integrating a multi-source training dataset consisting of historical regression test samples, expert-annotated data, and automatically generated boundary samples, the teacher model enhances its performance in recognizing boundary scenarios while maintaining basic generalization capabilities. The resulting high-capacity teacher model accurately represents the execution behavior mapping relationship of the benchmark database in a multi-dimensional feature space, providing a reliable knowledge source for the subsequent lightweight distillation and online anomaly detection of the student model.

[0048] Example 4 Based on the above embodiments 1, 2, and 3, as an optional implementation, the second network model is trained according to the output probability distribution of the teacher model and the intermediate layer features to obtain a student model for predicting the execution behavior of the database under test, including: Step 310: Construct a second network model and calculate the KL divergence between the prediction results of the second network model and the soft label probability distribution output by the teacher model, as the first distillation loss. Specifically, this step first constructs a lightweight architecture for the second network model. This model can employ shallow transformers, depthwise separable convolutional networks, or miniature multilayer perceptrons to reduce computational complexity and inference latency, making it suitable for online testing environments. During training, the student model needs to simultaneously learn the hard targets of the real labels and the soft targets output by the teacher model, defining the basic loss function. Its expression is:

[0049] In the formula, This is a hyperparameter used to adjust the weights of the monitoring signal and the distillation signal; Cross-entropy loss is used to measure the student model's predicted distribution. Distribution of real hard labels The differences between them are specifically in the form of ,in Iterate through all possible output categories. For the real label in the first Probability on class, Predicting the first student model The probability of a class; KL divergence is used to measure the distribution of student model predictions. The probability distribution of soft labels output by the teacher model The differences between them are specifically in the form of ,in The first prediction for the teacher model Class probability; by minimizing This enables the student model to mimic the output distribution of the teacher model while fitting the real labels, thus achieving preliminary knowledge transfer. Step 320: Map the intermediate layer features of the second network model to the implicit feature space of the teacher model using a projection matrix, and calculate the mean squared error between the mapped features and the corresponding layer features of the teacher model as the feature alignment loss; specifically, to enable the student model to learn the internal representation of the teacher model more deeply, a feature space alignment loss is introduced. We select a certain intermediate layer from both the teacher model and the student model as the prompting layer, and obtain the feature representation output by that layer; let the first layer be the first intermediate layer. For each training sample, the feature output of the teacher model's prompting layer is: The feature output of the corresponding layer in the student model is Since the two dimensions may differ, a learnable projection matrix is ​​introduced. The feature alignment loss is defined as mapping student features to the dimensional space of teacher features:

[0050] in, The total number of training samples; express The square of the norm is the mean square error, which is specifically calculated as the sum of the squares of the elements of the vector. For the teacher model prompt layer, the first The feature vector output by each sample For the student model corresponding to the first layer The feature vector output by each sample The learnable projection matrix has the following dimensions: , For teacher characteristics dimension, The student feature dimension is used; this loss function prompts the intermediate layer features of the student model to be as close as possible to the corresponding layer features of the teacher model after linear transformation, thereby achieving knowledge transfer at the feature level.

[0051] Step 330: Construct a comprehensive loss function based on the first distillation loss and feature alignment loss, and optimize the parameters of the second network model; specifically, the basic distillation loss and feature alignment loss are weighted and combined to obtain a preliminary comprehensive loss function. The preliminary summation loss function is updated through the backpropagation algorithm to update the student model parameters and projection matrix, so that the student model approximates the teacher model in terms of output distribution and intermediate layer features.

[0052] Step 340: Construct an adversarial distillation loss function, which adjusts the hidden layer feature distribution of the student model by minimizing the probability that the discriminator network correctly identifies the features generated by the student model. Specifically, to further improve the realism of the student model's feature representations, an adversarial distillation mechanism is introduced. A lightweight discriminator network is constructed. Its task is to perform binary classification on the source of the input features, distinguishing whether the feature comes from the teacher model or the student model. This involves adversarial distillation loss. Defined as:

[0053] in, and These are the feature outputs of a hidden layer in the teacher model and the student model, respectively. The expected value can be approximated by averaging within a small batch. This represents the probability that the discriminator will classify the teacher's features as true. This represents the probability that the discriminator classifies a student's features as true; during training, the discriminator... The goal is to maximize the ability to classify correctly, that is, to maximize The goal of the student model is to generate features sufficient to confuse the discriminator, that is, to obtain... Approaching 1, thus minimizing Zhongyu The relevant part; through this adversarial training, the hidden feature distribution of the student model is forced to converge with the feature distribution of the teacher model, thus learning a more consistent decision boundary.

[0054] Step 350: Calculate sample weight coefficients based on the prediction entropy value output by the teacher model, and construct an uncertainty-aware sample weighted loss function. This sample weighted loss function adjusts the contribution of different samples in training according to the sample weight coefficients. Specifically, considering the different contributions of different training samples to knowledge distillation, an uncertainty-aware sample weighting strategy is introduced. For the first... Calculate the probability distribution of the teacher model output from a sample. Information entropy A lower entropy value indicates a more certain prediction from the teacher's model for that sample, and a more reliable knowledge contained in that sample; a higher entropy value indicates a more uncertain prediction, which may contain noise or boundary conditions. Information entropy. Defined as:

[0055] In the formula, Iterate through all categories. For the teacher model to the first The predicted number of samples Class probability; based on this, the sample weight coefficient is defined. This assigns higher weights to high-confidence samples, with weight values ​​ranging from [0,1]; uncertainty-aware sample weighted loss. Defined as:

[0056] in, For the student model to the first The output probability distribution of each sample The KL divergence between the output distributions of teachers and students is given by the following form: This loss function strengthens the role of high-confidence samples in the distillation process, making the student model focus more on the knowledge that the teacher model is confident in, thereby improving learning efficiency and robustness.

[0057] Step 360: Add the adversarial distillation loss function and the uncertainty-aware sample weighted loss function to the comprehensive loss function. Together with the first distillation loss and the feature alignment loss function, they form a multi-objective optimization framework. The student model is jointly optimized through a dynamic weight allocation mechanism. The total loss function is defined as:

[0058] in, , , , These are adjustable weight coefficients, all positive real numbers, used to balance the contributions of different types of loss to model optimization. They can be dynamically adjusted based on convergence during training and validation set performance; by minimizing... The student model is simultaneously subject to multiple constraints, including output distribution matching, feature alignment, adversarial distribution approximation, and uncertainty-weighted reconstruction, achieving comprehensive knowledge transfer from the feature level, distribution level, and sample level. The final trained student model maintains its lightweight and low-latency advantages while possessing representational capabilities and generalization performance close to those of the teacher model. It can predict the execution behavior of the test database online in real time and output confidence estimates.

[0059] This embodiment employs a multi-stage knowledge distillation strategy to efficiently transfer knowledge from a high-capacity teacher model to a lightweight student model. (Basic distillation loss) By combining supervised signals with soft label matching, the student model initially learns the output distribution of the teacher model; feature alignment loss. Through intermediate layer feature mapping, the student model mimics the internal representation of the teacher model; adversarial distillation loss. Introducing discriminator adversarial training further narrows the distribution of hidden features in the teacher-student model; uncertainty-aware sample weighted loss. The sample weights are dynamically adjusted based on the teacher's predicted entropy value to enhance the transfer of high-confidence knowledge. These various enhanced loss functions, together with the basic loss, constitute a multi-objective optimization framework, achieving joint optimization through dynamic weight allocation. The resulting student model maintains low inference latency while achieving anomaly detection accuracy similar to the teacher model, making it suitable for large-scale online testing deployment.

[0060] Example 5 Based on the above embodiments 1, 2, 3, and 4, as an optional implementation, the structured query statement of the database to be tested is processed by a multimodal feature extractor and then input into the trained teacher model and student model respectively. The difference in the output prediction results is used to determine whether the current query has a functional abnormality, including: Step 410: Calculate the first sub-score in the result signature channel, the second sub-score in the execution plan channel, the third sub-score in the transaction log channel, and the fourth sub-score in the system status channel for the first prediction result output by the teacher model and the second prediction result output by the student model, respectively. Specifically, this step aims to quantify the differences between the teacher model and the student model outputs across four independent dimensions. The first prediction result is denoted as... The first prediction includes the teacher model's complete behavioral prediction for the current query, including information such as result signature, execution plan, transaction log, and system status; the second prediction result is denoted as... , which is the corresponding prediction for the student model.

[0061] The first sub-score of the result signature channel The similarity is calculated based on the hash signatures of the result set. The result signature predicted by the teacher model is denoted as... The signature of the student model prediction result is denoted as Using a hash similarity function This function measures the similarity between two items, returning a similarity value between 0 and 1, where 1 indicates complete similarity and 0 indicates complete dissimilarity. The first sub-score is defined as:

[0062] in The similarity between two signatures can be calculated using methods such as Hamming distance or Jaccard coefficient. This sub-score reflects the degree of inconsistency between the resulting signatures; a higher score indicates a greater difference.

[0063] Second sub-score of the execution plan channel This incorporates the normalized bias of the execution cost and row count estimates. The execution plan cost predicted by the teacher model is denoted as... The execution plan cost predicted by the student model is denoted as The number of execution plan rows predicted by the teacher model is denoted as... The number of rows in the execution plan predicted by the student model is denoted as The cost bias and row count bias are normalized separately, and then summed:

[0064] in The normalization function maps deviation values ​​to the interval between 0 and 1. This sub-score reflects the degree of difference in key statistics of the execution plan.

[0065] Third sub-score of the transaction log channel Anomaly detection based on error code matching and semantic analysis, the transaction log sequence predicted by the teacher model is denoted as follows: The transaction log sequence predicted by the student model is denoted as Define function Analyze the two log sequences to detect any abnormal events or pattern mismatches:

[0066] In the formula, The system can output a score between 0 and 1, representing the degree of anomaly at the log level, through methods such as error code comparison, log event type matching, and time-series pattern anomaly detection. The fourth sub-score of the system status channel Resource sequences are analyzed based on a time-series anomaly detection algorithm; the system state time-series data predicted by the teacher model includes the CPU occupancy sequence. Input / output waiting sequence Lock wait event sequence The corresponding sequence predicted by the student model is: , , Define function A comprehensive analysis of these time series data was conducted:

[0067] In the formula, Temporal similarity measures such as dynamic time warping or residual-based anomaly detection methods can be used to calculate the difference between the system state sequences predicted by the two models and output a score from 0 to 1.

[0068] Step 420: Based on the first sub-score, second sub-score, third sub-score, and fourth sub-score, and combined with preset weighting coefficients, a weighted fusion is performed to calculate the comprehensive anomaly score; specifically, the sub-scores of the four channels are linearly weighted and fused to obtain the comprehensive anomaly score. Let the weighting coefficients be respectively , , , To ensure that all weighting coefficients are non-negative and can be configured according to actual needs, the comprehensive anomaly score calculation formula is as follows:

[0069] In the formula, The weighting coefficient for the result signature channel. The weighting coefficients for the execution plan channels. This represents the weighting coefficient for the transaction log channel. These are the weighting coefficients for the system state channels. to The system can be automatically optimized based on historical data through ROC curve analysis, or it can be manually calibrated by testers to ensure the accuracy of anomaly detection and its adaptability to business scenarios.

[0070] In some embodiments, a simplified anomaly scoring function may be used as an alternative to define a difference vector. Its components include result set similarity. Execution plan tree edit distance and normalized performance difference measurement ; and These are the result sets predicted by the teacher model and the student model, respectively. and For the predicted execution plan tree, This represents the deviation from the overall performance index. The simplified anomaly scoring function is as follows:

[0071] in , , For configurable weight parameters, satisfy These correspond to the contributions of result similarity, execution plan differences, and performance deviations to the total score, respectively. This simplified scheme reduces computational complexity and is suitable for online real-time detection scenarios.

[0072] Step 430: Compare the comprehensive anomaly score with the preset decision threshold. If the comprehensive anomaly score exceeds the preset decision threshold, it is determined that the current query has a functional anomaly.

[0073] Specifically, let the preset decision threshold be... This threshold can be obtained through training on experimental data, for example, by selecting the optimal threshold based on the ROC curve on the validation set. The calculated comprehensive anomaly score will then be used. and Comparison: like If so, it is determined that the current query has a functional abnormality; like If so, the current query function is considered to be working properly.

[0074] While identifying anomalies, the system can output a confidence score. The confidence score is calculated based on the dispersion of each dimension of the difference vector. For example, the consistency of the anomaly identification is measured by calculating the variance or standard deviation of the four sub-scores; the smaller the variance, the higher the confidence score.

[0075] This embodiment constructs a multi-channel fusion anomaly scoring mechanism, which quantitatively analyzes four independent dimensions—result signature, execution plan, transaction log, and system status—and weights them together to generate a comprehensive anomaly score, achieving a comprehensive measurement of the differences between the teacher model and the student model's output. This method not only effectively avoids misjudgments caused by reasonable differences but also improves the coverage and interpretability of anomaly detection.

[0076] Example 6 Based on the above embodiments 1, 2, 3, 4, and 5, as an optional implementation, query samples determined to be abnormal and their execution information are fed back to the training sample set to incrementally update the teacher model, and the student model is synchronously updated through knowledge distillation, including: Step 510: Based on the updated training sample set, the teacher model is retrained using an incremental learning strategy to fit the boundary data distribution contained in the newly added abnormal samples. Specifically, this step aims to continuously optimize the teacher model using abnormal samples accumulated during online detection. All query samples identified as abnormal in Step 430, along with their complete execution information, including multimodal feature vectors, actual execution results, execution plan statistics, transaction logs, and system status time-series data, are uniformly added to the original training sample set to form the updated training sample set. Since the new samples mainly originate from actual detected boundary conditions and abnormal patterns, their data distribution often differs from the original training set. To efficiently absorb new knowledge while avoiding catastrophic forgetting, an incremental learning strategy is used to retrain the teacher model. The incremental learning strategy can choose methods such as elastic weight consolidation or learning rate replay, which apply importance weight constraints to the model parameters to optimize the loss of new samples while maintaining the responsiveness to old samples. Specifically, the updated training sample set is used as input, and the multi-task loss function defined in step 230 is used as the target. Several rounds of iterative optimization are performed using a small learning rate, so that the teacher model gradually fits the boundary data distribution contained in the newly added abnormal samples.

[0077] Step 520: Based on the joint analysis of the student model's prediction confidence and the differences between the teacher and student model outputs, samples with confidence levels below a first threshold and differences greater than a second threshold are selected from the newly added abnormal samples as priority labeled samples and included in the next round of training sample set. Specifically, this step aims to automatically select the most valuable samples from a massive number of newly added abnormal samples to improve sample utilization efficiency and model evolution speed. For each newly added abnormal sample, the prediction confidence of the student model for that sample is first obtained. This confidence level can be calculated from the maximum value of the student model's output probability distribution or the reciprocal of its entropy. Simultaneously, the comprehensive abnormal score of the teacher and student models on that sample is obtained, which has already been calculated in step 420. A first threshold is set to determine the level of confidence, and a second threshold is set to determine the magnitude of the output difference. If a sample meets the condition that the student model's prediction confidence is below the first threshold and the difference between the two models' outputs is greater than the second threshold, then that sample is determined to be a priority labeled sample with high learning value. These samples, selected from the newly added abnormal samples, can be sent to a manual review process for precise labeling or directly included in the next round of training sample set as high-weight samples.

[0078] Step 530: Using the updated teacher model as a knowledge source, the student model is retrained or its parameters adjusted using knowledge distillation technology. Specifically, this step aims to enable the lightweight student model to synchronously acquire the updated knowledge from the teacher model, maintaining consistency between the teacher and student models. The teacher model, which underwent incremental updates in Step 510, is used as a new knowledge source. The student model is retrained or its parameters fine-tuned using the multi-stage knowledge distillation framework described in Example 4. The distillation process can utilize the updated training sample set. During distillation, the student model uses the output probability distribution and intermediate layer features of the teacher model as supervision signals, updating its parameters by minimizing the total loss function. After several rounds of distillation iterations, the student model absorbs the newly learned boundary knowledge from the teacher model, thereby maintaining detection performance similar to that of the teacher model. Through iterative steps 510 to 530, the testing system forms a complete self-learning loop, enabling the testing model to continuously learn from actual operation and constantly improve its ability to identify novel defects and complex scenarios.

[0079] In some embodiments, to further enhance the adaptive expansion capability of test coverage, the system also integrates a structured sample mutant; this mutant, based on syntax-guided constrained randomization techniques, performs multidimensional mutations on existing test cases: At the syntactic level, semantically preserved transformations such as join type conversion and subquery reconstruction are performed; at the data level, table cardinality and column value ranges are adjusted to simulate different data distribution characteristics; transaction conflict and lock contention mechanisms are injected into concurrent scenarios; and error injection of boundary values ​​and abnormal parameters is introduced. New test cases generated by mutations are added to the training sample set for the next round of incremental model training, thereby dynamically enriching the model's experience base and ensuring its robustness in complex and ever-changing testing environments.

[0080] As another implementation, the report generator presents the detection results through a multi-dimensional visualization interface based on structured test data. The system generates anomaly distribution heatmaps to reveal the clustering patterns of problematic statements, provides differential comparison views to highlight significant deviations in syntax structure and execution paths, and plots time-series monitoring curves to demonstrate the dynamic correlation between system resources and key indicators. Based on in-depth analysis results, the report generator automatically outputs a decision support checklist containing root cause analysis and optimization suggestions, forming a complete report solution integrating anomaly diagnosis, performance analysis, and remediation guidance, supporting rapid location of test conclusions and continuous optimization.

[0081] Through the above mechanism, the system has formed a complete evolutionary closed loop from sample generation, anomaly detection, model update to report output, which improves the adaptability to complex scenarios and testing efficiency, and realizes a continuous optimization database function testing process with low human intervention.

[0082] Example 7 It should be understood that the knowledge distillation-based database testing method described in the foregoing embodiments of this document can also be similarly applied to the following knowledge distillation-based database testing systems for similar extensions. For simplicity, it has not been described in detail.

[0083] Figure 2 This is a database testing system based on knowledge distillation provided in an exemplary embodiment of the present invention. (Refer to...) Figure 2 The system includes: The multimodal feature extraction module is configured to build a multimodal feature extractor, perform multi-dimensional feature extraction on the input structured query statement and its execution context, and convert the extraction results into feature vectors; The teacher model training module is configured to train the first network model based on multimodal feature samples generated by executing historical test cases from the benchmark database and their corresponding execution behavior data, thereby obtaining a teacher model that represents the execution behavior of the benchmark database. The student model training module is configured to train the second network model based on the output probability distribution of the teacher model and the intermediate layer features, so as to obtain a student model for predicting the execution behavior of the database under test. The anomaly detection module is configured to process the structured query statement of the database under test through a multimodal feature extractor, and then input it into the trained teacher model and student model respectively, and determine whether there is a functional anomaly in the current query based on the difference in the output prediction results. The self-learning update module is configured to feed back query samples judged as abnormal and their execution information to the training sample set, incrementally update the teacher model, and synchronously update the student model through knowledge distillation.

[0084] Example 8 In addition, embodiments of the present invention also provide an electronic device, including: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, which, when executed, enable the at least one processor to perform the knowledge distillation-based database testing method as described in the first aspect of the present invention.

[0085] Figure 3 This is a schematic diagram of the structure of an application embodiment of the electronic device of the present invention. Below, refer to... Figure 3 This describes an electronic device according to embodiments of the present invention. The electronic device may be either or both of a first device and a second device, or a standalone device independent of them, which may communicate with the first device and the second device to receive acquired input signals from them.

[0086] like Figure 3 As shown, the electronic device includes one or more processors and memory. The processor may be a central processing unit (CPU) or other processing unit with data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions. The memory may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may, for example, include random access memory (RAM) and / or cache memory. The non-volatile memory may, for example, include read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor may execute the program instructions to implement the knowledge distillation-based database testing method of the various embodiments of the present invention described above, and / or other desired functions.

[0087] In one example, the electronic device may further include input and output devices, which are interconnected via a bus system and / or other forms of connection mechanisms (not shown). Furthermore, the input device may include, for example, a keyboard, a mouse, etc. The output device can output various information to the outside, including determined distance information, direction information, etc. The output device may include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, etc.

[0088] Of course, for the sake of simplicity, Figure 3 Only some of the components of the electronic device relevant to the present invention are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device may include any other suitable components depending on the specific application.

[0089] In addition to the methods and devices described above, embodiments of the present invention may also be computer program products, wherein a computer-readable storage medium stores a program implementing a knowledge distillation-based database testing method, and the program implementing the knowledge distillation-based database testing method is executed by a processor to implement the steps of the knowledge distillation-based database testing method described in various embodiments of the present invention.

[0090] The computer program product can be written in any combination of one or more programming languages ​​to perform the operations of the embodiments of the present invention. The programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0091] Furthermore, embodiments of the present invention may also be computer-readable storage media storing computer program instructions thereon, which, when executed by a processor, cause the processor to perform the steps in the knowledge distillation-based database testing method according to various embodiments of the present invention described in the foregoing portion of this specification.

[0092] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable 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.

[0093] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as ROM, RAM, magnetic disk, or optical disk.

[0094] The basic principles of the present invention have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in the present invention are merely examples and not limitations, and should not be considered as essential features of each embodiment of the present invention. Furthermore, the specific details of the invention described above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the present invention to the necessity of employing the specific details described above.

[0095] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system embodiments, since they largely correspond to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0096] The block diagrams of devices, apparatuses, devices, and systems involved in this invention are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, apparatuses, devices, and systems can be connected, arranged, and configured in any manner. Words such as “comprising,” “including,” “having,” etc., are open-ended terms meaning “including but not limited to,” and are used interchangeably with them. The terms “or” and “and” as used herein refer to the terms “and / or,” and are used interchangeably with them unless the context clearly indicates otherwise. The term “such as” as used herein refers to the phrase “such as but not limited to,” and is used interchangeably with it.

[0097] The methods and apparatus of the present invention may be implemented in many ways. For example, they may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above-described order of steps for the methods is for illustrative purposes only, and the steps of the methods of the present invention are not limited to the order specifically described above unless otherwise specifically stated. Furthermore, in some embodiments, the present invention may also be implemented as a program recorded on a recording medium, the program comprising machine-readable instructions for implementing the methods according to the present invention. Thus, the present invention also covers recording media storing programs for performing the methods according to the present invention.

[0098] It should also be noted that in the apparatus, device, and method of the present invention, the components or steps can be disassembled and / or recombined. These disassemblies and / or recombinations should be considered as equivalent solutions of the present invention.

[0099] The above description of aspects of the invention is provided to enable any person skilled in the art to make or use the invention. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein can be applied to other aspects without departing from the scope of the invention. Therefore, the invention is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features of the invention herein.

[0100] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of the invention to the forms described herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations therein.

[0101] It should be noted that the order of the above embodiments of the present invention is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. The processes depicted in the accompanying drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0102] The various embodiments in this specification are described in a progressive manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.

Claims

1. A database testing method based on knowledge distillation, characterized in that, The method includes: Construct a multimodal feature extractor to extract multi-dimensional features from the input structured query statement and its execution context, and convert the extraction results into feature vectors; Based on the multimodal feature samples generated from historical test cases executed on the benchmark database and their corresponding execution behavior data, the first network model is trained to obtain a teacher model used to characterize the execution behavior of the benchmark database. Based on the output probability distribution of the teacher model and the features of the intermediate layer, the second network model is trained to obtain the student model used to predict the execution behavior of the database under test. The structured query statement of the database under test is processed by the multimodal feature extractor and then input into the trained teacher model and student model respectively. The difference in the output prediction results is used to determine whether there is a functional abnormality in the current query. The query samples identified as abnormal and their execution information are fed back to the training sample set to incrementally update the teacher model, and the student model is updated synchronously through knowledge distillation.

2. The database testing method based on knowledge distillation as described in claim 1, characterized in that, Construct a multimodal feature extractor to extract multi-dimensional features from the input structured query statement and its execution context, and convert the extraction results into feature vectors, including: Lexical analysis and syntactic parsing are performed on the input structured query statement to generate an abstract syntax tree, and syntactic structural features containing operation types, table column dependencies and predicate distribution information are extracted. The execution plan of structured query statements in the database is parsed to extract execution plan features including operator sequence, operator estimated cost, actual number of rows executed, and index usage. Collect system status data during database operation and extract runtime status features including CPU utilization, memory usage, lock wait event sequences, and transaction log information; The result set returned after the execution of the structured query statement is hashed to generate a digital signature of the result set, and the cardinality and column value range distribution information of the result set are extracted as the result signature features; The grammatical structure features, execution plan features, runtime state features, and result signature features are vectorized, aligned, and fused to obtain feature vectors.

3. The database testing method based on knowledge distillation as described in claim 1, characterized in that, Based on the multimodal feature samples generated from historical test cases executed on the benchmark database and their corresponding execution behavior data, the first network model is trained to obtain a teacher model used to characterize the execution behavior on the benchmark database, including: Construct a first network model, which includes a first branch for processing syntactic structure features, a second branch for processing execution plan features, and a third branch for processing runtime state features. A hierarchical attention mechanism is set at the output of each branch to adaptively weight and fuse the features of the multi-branch outputs to generate a comprehensive behavioral representation vector. The first network model is trained using a multi-task learning framework. The training tasks include at least a result signature prediction task based on contrastive learning and an execution plan regression task based on mean squared error. Using verified correct execution behavior data from historical test cases as supervisory signals, and combining weight decay regularization strategies to optimize the parameters of the first network model, the teacher model learns the execution behavior mapping relationship of the benchmark database in the multi-dimensional feature space.

4. The database testing method based on knowledge distillation as described in claim 1, characterized in that, Based on the output probability distribution of the teacher model and the features of the intermediate layer, the second network model is trained to obtain the student model used to predict the execution behavior of the test database, including: Construct a second network model and calculate the KL divergence between the prediction results of the second network model and the soft label probability distribution output by the teacher model, which is used as the first distillation loss; The intermediate layer features of the second network model are mapped to the implicit feature space of the teacher model through a projection matrix. The mean square error between the mapped features and the corresponding layer features of the teacher model is calculated as the feature alignment loss. A comprehensive loss function is constructed based on the first distillation loss and feature alignment loss, and the parameters of the second network model are optimized.

5. The database testing method based on knowledge distillation as described in claim 4, characterized in that, Based on the output probability distribution of the teacher model and the features of the intermediate layer, the second network model is trained to obtain the student model used to predict the execution behavior of the test database, which also includes: An adversarial distillation loss function is constructed, which adjusts the hidden layer feature distribution of the student model by minimizing the probability that the discriminator network correctly identifies the features generated by the student model. The sample weight coefficients are calculated based on the predicted entropy value output by the teacher model, and an uncertainty-aware sample weighted loss function is constructed. The sample weighted loss function adjusts the contribution of different samples in training according to the sample weight coefficients. The adversarial distillation loss function and the uncertainty-aware sample weighted loss function are added to the comprehensive loss function, which together with the first distillation loss and the feature alignment loss function constitute a multi-objective optimization framework. The student model is jointly optimized through a dynamic weight allocation mechanism.

6. The database testing method based on knowledge distillation as described in claim 1, characterized in that, The structured query statements from the database under test are processed by a multimodal feature extractor and then input into the trained teacher and student models respectively. The differences in the output prediction results are used to determine whether the current query exhibits functional abnormalities, including: Calculate the first sub-score in the result signature channel, the second sub-score in the execution plan channel, the third sub-score in the transaction log channel, and the fourth sub-score in the system status channel for the first prediction result output by the teacher model and the second prediction result output by the student model. The comprehensive anomaly score is calculated by weighting and fusing the first sub-score, the second sub-score, the third sub-score, and the fourth sub-score together with preset weighting coefficients. The comprehensive anomaly score is compared with a preset decision threshold. If the comprehensive anomaly score exceeds the preset decision threshold, it is determined that the current query has a functional anomaly.

7. The database testing method based on knowledge distillation as described in claim 1, characterized in that, The query samples identified as abnormal and their execution information are fed back to the training sample set to incrementally update the teacher model, and the student model is updated synchronously through knowledge distillation, including: Based on the updated training sample set, the teacher model is retrained using an incremental learning strategy to fit the boundary data distribution contained in the newly added abnormal samples. Based on the joint analysis of the prediction confidence of the student model and the difference between the output of the teacher model and the student model, samples with confidence scores below the first threshold and differences greater than the second threshold are selected from the newly added abnormal samples as priority labeled samples and included in the next round of training sample set. The updated teacher model is used as a knowledge source, and the student model is then adjusted or retrained using knowledge distillation techniques.

8. A database testing system based on knowledge distillation, characterized in that, The system is used to perform the database testing method based on knowledge distillation as described in any one of claims 1 to 7, the system comprising: The multimodal feature extraction module is configured to build a multimodal feature extractor, perform multi-dimensional feature extraction on the input structured query statement and its execution context, and convert the extraction results into feature vectors; The teacher model training module is configured to train the first network model based on multimodal feature samples generated by executing historical test cases from the benchmark database and their corresponding execution behavior data, thereby obtaining a teacher model that represents the execution behavior of the benchmark database. The student model training module is configured to train the second network model based on the output probability distribution of the teacher model and the intermediate layer features, so as to obtain a student model for predicting the execution behavior of the database under test. The anomaly detection module is configured to process the structured query statement of the database under test through a multimodal feature extractor, and then input it into the trained teacher model and student model respectively, and determine whether there is a functional anomaly in the current query based on the difference in the output prediction results. The self-learning update module is configured to feed back query samples judged as abnormal and their execution information to the training sample set, incrementally update the teacher model, and synchronously update the student model through knowledge distillation.

9. An electronic device, characterized in that, include: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the knowledge distillation-based database testing method as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the database testing method based on knowledge distillation as described in any one of claims 1 to 7.