Database management system testing method and testing system based on differential fuzzy testing

By modifying the source code of the database management system to support multiple query plans and comparing the differences in query results, the problem of difficulty in finding logical defects in the existing technology is solved, a comprehensive test of the database management system is achieved, and system stability and security are improved. sex.

CN115129600BActive Publication Date: 2024-09-06ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210785758.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-04
Publication Date
2024-09-06
Estimated Expiration
2042-07-04

AI Technical Summary

Technical Problem

The existing technology is difficult to discover logical flaws in the database management system that lead to erroneous query results through automated testing, and cannot effectively test the characteristics of different database management systems.

Method used

Modify the source code of the database management system to support multiple query plans, and generate and execute multiple query plans to compare the difference in results and determine whether there are unexpected logical flaws. Specific methods include changing the order of multi-table connections, single-table access methods, turning on and off query optimization, generating test cases, executing and monitoring results, performing result comparisons, use case simplification and whitelist filtering.

Benefits of technology

Effectively identify and trigger logical flaws in the database management system, improve system stability and availability, avoid upper-layer software security issues, and have wider applicability and low-relevance test case generation rules.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115129600B
    Figure CN115129600B
Patent Text Reader

Abstract

The present invention discloses a database management system testing method and testing system based on differential fuzzy testing, which aims to modify the source code of the database management system so that the database management system can generate multiple different query plans, thereby judging whether the database management system has defects by comparing the results obtained by executing different query plans. The method mainly includes two parts: a method for modifying the database management system and a criterion for judging whether the database management system has defects. The present invention can provide support for the development and testing process of the database management system to reduce the defects in the database management system, thereby reducing the defects of the upper-level software developed by relying on the database management system, and improving the security and availability of the software.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of software testing, and in particular relates to a database management system testing method and a testing system based on differential fuzzy testing. Background Art

[0002] Currently, relational databases are widely used. They are managed by a database management system (DBMS), a type of software that uses the Structured Query Language (SQL) to manipulate and manage databases. They are widely used to create, use, and maintain databases, enabling efficient data storage and retrieval.

[0003] Database management systems involve numerous database management functions and inevitably contain some errors. These errors potentially threaten the security of the software that uses these database management systems. Therefore, testing the DBMS and finding undiscovered errors can provide safer and more reliable services for the many upper-layer software, thereby ensuring the availability and reliability of the software.

[0004] Currently, there is a wealth of testing work targeting DBMSs. However, most of this work focuses on identifying assertion errors, crashes, and undefined behavior within the database engine. These errors are relatively easy to identify because they typically trigger exceptions that cause the software to run abnormally. However, errors that cause the database to produce incorrect query results—logical errors such as missing rows in the query results—are more difficult to detect through automated testing because such anomalies typically involve the DBMS's query processor, and currently there is no method for determining the correctness of DBMS query results.

[0005] In 1998, Don Slutzti proposed a method for finding such logical flaws through differential fuzz testing. This method compares the results of executing the same query across different database management systems to determine whether anomalies have occurred. While this method does find some errors, it has significant limitations. While all DBMSs support the SQL language, they each have their own unique idiosyncrasies. This method can only test the common aspects of different DBMS implementations, but cannot test the specific features of each DBMS. Furthermore, this method cannot detect underlying errors common to multiple DBMSs that can cause incorrect execution results.

[0006] In 2019, Manuel Rigger's team proposed a series of effective and universal methods for identifying logical defects in the same database management system, including "baseline query generation" and "deoptimization." They also developed corresponding testing tools based on these methods. The theoretical basis of this series of methods remains the same: "difference comparison." For example, in the "baseline query generation" method, the testing tool first selects a row and generates a query statement that is expected to contain that row. By checking whether the result set contains that row, it determines whether the database engine has encountered an unexpected logical defect. In the "deoptimization" method, the testing tool generates two logically equivalent queries with different optimizations. By comparing the number of rows in the result sets obtained by executing the two queries on the database management system, it determines whether an unexpected logical defect has occurred.

[0007] The series of methods proposed by Manuel Rigger are strongly related to test case generation methods. Each method corresponds to a different test criterion and a different test case generation rule. Therefore, this method has high requirements for test case generation rules. When testing continuously using test cases generated by a fixed type of construction method, it becomes increasingly difficult to find new errors, and it still has significant limitations.

[0008] In the currently published invention patents, such as "Coverage Analysis Method and System Based on Fuzz Testing of Database Management Systems" (CN202111486228.2), the invention can only find defects that cause database management systems to crash, but cannot find defects that cause the database to produce erroneous results. In other inventions, such as "A Design Method and Testing Method for a Database System Application Benchmark Test Specification" (CN202011164926.6), the database is tested for specific application scenarios and requirements, and has nothing to do with testing the database management system itself. Summary of the Invention

[0009] To address the shortcomings of existing technologies, the present invention provides a database management system testing method and system based on differential fuzz testing. This method modifies the DBMS source code to generate and execute multiple query plans for a single query statement. Subsequently, by comparing the results obtained from different query plans to determine if unexpected logical defects have occurred, the system can determine whether these plans are consistent.

[0010] The purpose of the present invention is achieved through the following technical solutions:

[0011] A database management system testing method based on differential fuzz testing, the method comprising:

[0012] Modify the source code of the database management system to enable the database management system to support multiple query plans;

[0013] Perform differential fuzz testing on database management systems, including:

[0014] (1) Generate test cases;

[0015] (2) Execute test cases;

[0016] (3) Differences in comparison results;

[0017] (4) Test case simplification;

[0018] (5) Whitelist filtering.

[0019] Furthermore, the source code of the database management system is modified to enable the database management system to support multiple query plans. There are three ways to do this: changing the order of multi-table connections, changing the access method of a single table, and turning query optimization on and off.

[0020] Furthermore, the order of changing the multi-table connection is specifically as follows:

[0021] The function that processes the nested order of multi-table queries in the source code of the database management system is located, and the part that is pruned due to query cost is deleted, so that the query plan can adopt multiple orders when querying multiple tables.

[0022] Furthermore, the access mode of changing a single table is specifically as follows:

[0023] Locate the functions in the database management system source code that process and determine the single-table access method, and delete the parts that abandon the plan due to query cost, so that it can support different single-table scanning methods when executing query statements.

[0024] Furthermore, the query optimization is enabled or disabled as follows:

[0025] Locate the parts of the database management system source code that perform structural optimization (such as equivalent value transfer optimization) and scan optimization (such as Covering-Index optimization, Skip-Scan optimization, etc.) on query statements, and add switches for them by adding conditional judgment statements to enable them to support both turning on and off optimization execution paths.

[0026] Furthermore, the generating of the test case specifically includes: generating a test case that meets the DBMS input standard through a preset statement generation rule, wherein the test case includes a state creation statement and a query statement;

[0027] The execution of the test case specifically includes: inputting the generated test case into the data management system after the source code is modified, monitoring the state of the database management system, and saving the result set of the query statement executed by the database management system.

[0028] Furthermore, the differences in the comparison results are specifically:

[0029] By comparing the results obtained from different query plans, if the results are inconsistent, it is considered that a defect may have been triggered.

[0030] Furthermore, the test case is simplified as follows:

[0031] Select a part of the test cases with inconsistent results according to different granularities, delete it and execute it again. If the exception still occurs, it means that the deleted part is not the key to the exception and it will be permanently deleted; if the exception no longer occurs, it means that the deleted part is the key to the exception and it will be retained; in this way, the parts that are not related to the exception are removed.

[0032] Furthermore, the whitelist filtering is specifically as follows: test cases whose results are different due to common non-defect factors are distinguished through preset filtering standards. If they are caused by non-defect factors, they are stored in a low-priority queue; otherwise, they are stored in a normal-priority queue; finally, test cases caused by defect factors are further checked manually, anomalies caused by non-error factors are selected, these features are summarized, and added to the whitelist. In subsequent tests, such situations will be confirmed with a lower priority; otherwise, the use cases are deeply simplified manually and reported to the developer.

[0033] A test system for implementing the above-mentioned test method, the system comprising a test case generator, a runtime monitor, a difference comparator, a case simplifier and a filter;

[0034] The test case generator is used to randomly generate test cases that comply with SQL specifications and database management system characteristics according to preset statement generation rules, including state creation statements (CREATE statements, INSERT statements, etc.) and query statements (SELECT statements, etc.);

[0035] The runtime monitor is used to input the test cases generated by the test case generator into the database management system, monitor the status of the database management system (such as whether the process has crashed, whether the memory usage is abnormal, DBMS code coverage), etc., and record the query results output by the database management system; the source code of the database management system has been modified to enable the database management system to support multiple query plans;

[0036] The difference comparator compares the query results output by the database management system, and when the query results are consistent, it is determined that no abnormality has occurred; otherwise, when they are inconsistent, it is determined that an abnormality may have occurred;

[0037] The use case simplifier cleans the test cases where the exceptions occur, that is, it selects a portion of the test cases where the exceptions occur according to different granularities, temporarily deletes the portion, and then inputs it into a database management system that supports multiple query plans to determine whether the exceptions occur. If the exceptions still occur, it means that the deleted portion is not the key to the exceptions and is permanently deleted. If the exceptions no longer occur, it means that the deleted portion is the key to the exceptions and is retained. In this way, the portions that are not related to the exceptions are removed.

[0038] The filter determines whether the current abnormal test case may be caused by non-defect factors based on the preset white list. If it is caused by non-defect factors, it will be allocated to the low priority queue for storage; otherwise, it will be allocated to the normal priority queue for storage.

[0039] The beneficial effects of the present invention are as follows:

[0040] The present invention provides a novel method and system for testing database management systems. This method effectively identifies software defects within the database management system and provides developers with test cases that trigger the defects, helping them fix them. This improves the stability and usability of the database management system, thereby preventing security issues in upper-level software (such as browsers and web applications) that rely on the database management system. Compared to existing methods, the present method is less dependent on test case generation rules and can test any rule-generated test case without knowing the expected results, thus offering broader applicability. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 FIG. 1 is a flow chart showing a method of the present invention according to one exemplary embodiment.

[0042] Figure 2 The figure is a schematic diagram showing the effect of modification of the DBMS front end and interface according to one of the exemplary embodiments.

[0043] Figure 3 The figure is a flowchart of test case simplification and whitelist filtering steps according to one exemplary embodiment.

[0044] Figure 4 The figure is a flowchart of the step of comparing the difference in comparison results according to one exemplary embodiment.

[0045] Figure 5 The figure is a simplified flowchart of a test case according to one exemplary embodiment.

[0046] Figure 6 FIG. 1 is a schematic diagram of a whitelist filtering stage according to one exemplary embodiment.

[0047] Figure 7 FIG. 1 is a schematic diagram of a testing system of the present invention according to one exemplary embodiment. DETAILED DESCRIPTION

[0048] The present invention will be described in detail below with reference to the accompanying drawings and preferred embodiments, and the purpose and effects of the present invention will become more apparent. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0049] The key problem to be solved by the present invention is to effectively detect logical defects in a database management system and trigger potential memory defects in the database management system by means of differential fuzz testing, and to design a corresponding database management system test system by using this method.

[0050] like Figure 1 As shown, the database management system testing method based on differential fuzz testing of the present invention is divided into two stages: modifying the database management system and performing differential fuzz testing on the database management system.

[0051] (1) Modification of the database management system

[0052] The main purpose of modifying the database management system is to modify the source code of the database management system, specifically to receive a query statement, generate several different query plans and execute them separately, and obtain several corresponding query results. Among them, the modification of the source code of the database management system includes:

[0053] 1. Modify the DBMS front-end and interface to enable it to accept file input and output, and execute different query plans multiple times for one input. The effect of this modification is as follows: Figure 2 shown.

[0054] 2. For the part of the DBMS backend involving query plan generation, this mainly involves modifying the DBMS query optimizer module. This step may include but is not limited to: changing the order of multi-table connections, changing the access method of a single table, and turning query optimization on and off.

[0055] (1) Change the order of multi-table connections

[0056] Typically, when a DBMS processes a query involving multiple tables, the query optimizer uses a "nested loop" approach, with the following structure:

[0057]

[0058] Different nesting orders for multiple tables affect the query order, cost, and scanning method for each table. Typically, the DBMS query optimizer determines the nesting order of multiple tables using a greedy search approach that gradually expands a partial plan and appends a table. The pseudo code is as follows:

[0059]

[0060]

[0061] Here, pplan represents the determined partial plan. best_extension recursively performs a depth-first exhaustive search within its own function to find the optimal query plan for the remaining tables. This includes some cost-based pruning. When the exhaustive search determines a complete query sequence, the cost is also compared with the plan cost corresponding to the known optimal query sequence.

[0062] The DBMS modifications in this step target the cost comparisons during the search process, including pruning and order determination. Plans discarded due to suboptimal cost when determining table nesting order are retained, generating two execution paths for each discarded suboptimal plan. Specifically, the functions that handle the nesting order of multi-table queries are located in the database management system's source code, and the portions that are pruned due to query cost are removed, allowing the query plan to adopt a variety of orderings for multi-table queries.

[0063] (2) Changing the access method of a single table

[0064] A DBMS offers a variety of single-table scan methods, including full table scans, index scans, secondary index scans, and table lookups. Based on the scan types supported by the DBMS, we need to find a function that determines the scan method. We then retain plans that discard suboptimal scan methods due to cost and statistical data, generating two execution paths for each discarded suboptimal plan.

[0065] (3) Enable or disable query optimization

[0066] The DBMS query optimizer has the ability to perform equivalent replacement optimizations on SQL structures, such as BETWEEN, LIKE, OR, and subquery flattening. The purpose is to enable the statement to use indexes during execution or to avoid repeated scans of referenced tables through equivalent replacement. This step requires finding the function that the DBMS query optimizer uses to perform this type of optimization and adding a switch to it through a conditional statement so that two execution paths, open and closed, can be generated during execution.

[0067] (2) Differential fuzz testing of database management systems

[0068] 1. Generate test cases

[0069] In this step, test cases that conform to SQL specifications and DBMS characteristics must be generated according to preset statement generation rules. These include state creation statements (CREATE statements, INSERT statements, etc.) and query statements (SELECT statements, etc.). During the test case generation phase, test cases generated by generation-based tools (such as SQLancer) or mutation-based tools (such as Squirrel) can be used as input for fuzz testing. Test cases that conform to DBMS input standards can also be obtained through other means.

[0070] 2. Execute test cases;

[0071] Input the test case obtained in step 1 into the modified DBMS for execution, monitor the status of the DBMS (such as whether the process crashes, whether the memory usage is abnormal, DBMS code coverage), etc., and record the query results output by the DBMS.

[0072] 3. Differences in comparison results

[0073] Compare the query results obtained in step 2. The algorithm flow chart of this step is shown in the attached figure. Figure 4 As shown in the figure, query statements that produce different results based on different query plans are marked as anomalies. The use case that causes the DBMS to crash or leak memory in step 2 is also marked as anomaly. By comparing the consistency of the results obtained by different query plans, we can use this as a criterion to determine whether the test case may have triggered a database management system defect. If the results of different query plans are inconsistent, a defect may have been triggered.

[0074] 4. Test case simplification (test case cleaning)

[0075] Test cases are randomly generated based on rules, and those that produce anomalies are difficult for humans to read. To facilitate subsequent manual review of test cases that cause anomalies and determine whether they are caused by faulty factors, these test cases must be initially simplified. This process is called case cleaning, or complexity reduction.

[0076] Clean the use cases marked as abnormal. The algorithm flow chart of this step is shown in the attached Figure 3 and 5As shown in the figure, the specific cleaning rule is: select a portion of the code at different granularities, such as "Statement," "Clause," "Expression," and "Term." Delete that portion and re-execute the code to determine if the exception still occurs. If the exception still occurs, that portion is not the key to the exception and can be permanently deleted. If the exception no longer occurs, that portion is essential and should be retained. This removes portions unrelated to the exception.

[0077] 5. Whitelist filtering

[0078] Filter the simplified test cases in step 4. The algorithm flow chart of this step is shown in the attached figure. Figure 3 and 6 As shown in the figure, test case filtering is implemented through a whitelist mechanism. The whitelist contains artificially defined filtering criteria (such as keywords and statement structures). Test cases corresponding to these patterns typically do not trigger actual DBMS defects. Test cases that match the existing patterns in the whitelist are assigned to a low-priority queue for storage. Otherwise, they are assigned to a normal-priority queue for storage, facilitating subsequent human judgment on whether they trigger database defects.

[0079] Furthermore, the test cases that cause the exceptions are manually checked to determine whether they are caused by error factors. If it is determined that the exceptions are not caused by error factors, their characteristics are summarized and added to the whitelist. In subsequent tests, such cases are confirmed with a lower priority; otherwise, the use cases need to be manually simplified in depth and reported to the developer.

[0080] like Figure 7 As shown, a test system for implementing the above test method is provided, which includes a test case generator, a runtime monitor, a difference comparator, a case simplifier and a filter;

[0081] The test case generator is used to randomly generate test cases that comply with SQL specifications and database management system characteristics according to preset statement generation rules, including state creation statements and query statements;

[0082] The runtime monitor is used to input the test cases generated by the test case generator into the database management system, monitor the status of the database management system, and record the query results output by the database management system; the source code of the database management system has been modified to enable the database management system to support multiple query plans;

[0083] The difference comparator compares the query results output by the database management system. When the query results are consistent, it is determined that no abnormality has occurred; otherwise, when they are inconsistent, it is determined that an abnormality may have occurred.

[0084] The use case simplifier cleans test cases where exceptions occur. Specifically, it selects a portion of the test case where the exception occurs based on different granularities, temporarily deletes the portion, and then inputs it into a database management system that supports multiple query plans to determine whether the exception occurs. If the exception still occurs, it indicates that the deleted portion is not the key to the exception and is permanently deleted. If the exception no longer occurs, it indicates that the deleted portion was the key to the exception and is retained. In this way, parts irrelevant to the exception are removed.

[0085] The filter determines whether the current abnormal test case may be caused by non-defect factors based on the preset whitelist. If it is caused by non-defect factors, it will be stored in the low-priority queue; otherwise, it will be allocated to the normal priority queue for storage.

[0086] Those skilled in the art will understand that the foregoing descriptions are merely preferred embodiments of the invention and are not intended to limit the invention. Although the invention has been described in detail with reference to the foregoing examples, those skilled in the art will still be able to modify the technical solutions described in the foregoing examples or substitute equivalents for some of the technical features therein. Any modifications, equivalent substitutions, etc. made within the spirit and principles of the invention shall be included within the scope of protection of the invention.

Claims

1. A database management system testing method based on differential fuzzy testing, characterized in that: The method includes: Modify the source code of the database management system so that the database management system can support multiple query plans; Perform differential fuzz testing on database management systems, including: (1) Generate test cases; (2) Execute test cases; (3) Differences in comparison results; (4) Test case simplification; (5) Whitelist filtering; Modify the source code of the database management system to enable it to support multiple query plans. There are three ways: change the order of multi-table connections, change the access method of a single table, and turn query optimization on and off. The specific order of changing the multi-table connection is: Locate the function in the source code of the database management system that processes the nested order of multi-table queries, and delete the part that is pruned due to query cost, so that the query plan can adopt multiple orders when querying multiple tables; The specific method of changing the access mode of a single table is as follows: Locate the functions in the source code of the database management system that process and determine the single-table access method, and delete the parts that discard the plan due to query cost, so that it can support different single-table scanning methods when executing query statements; The specific steps of turning query optimization on and off are as follows: Locate the part of the source code of the database management system that performs structural optimization and scanning optimization on query statements, and add switches to it by adding conditional judgment statements so that it can support two execution paths: opening and closing the optimization. The differences in the comparison results are specifically as follows: By comparing the results obtained from different query plans, when the results are inconsistent, it is considered that a defect may have been triggered.

2. The database management system testing method based on differential fuzzy testing according to claim 1 is characterized in that: The generating of the test case specifically comprises: generating a test case that meets the DBMS input standard by using a preset statement generating rule, wherein the test case comprises a state creation statement and a query statement; The execution of the test case specifically includes: inputting the generated test case into the data management system after the source code is modified, monitoring the state of the database management system, and saving the result set of the query statement executed by the database management system.

3. The database management system testing method based on differential fuzzy testing according to claim 1 is characterized in that: The test case is simplified as follows: Select a part of the test cases with inconsistent results according to different granularities, delete it and execute it again. If the exception still occurs, it means that the deleted part is not the key to the exception, and it is permanently deleted; If the exception no longer occurs, it means that the deleted part is the key to the exception, so keep it; This removes the parts that are not related to the abnormality.

4. The database management system testing method based on differential fuzzy testing according to claim 3 is characterized in that: The whitelist filtering is specifically as follows: the test cases whose results are different due to common non-defect factors are distinguished by preset filtering standards. If they are caused by non-defect factors, they are stored in a low priority queue, otherwise, they are stored in a normal priority queue; finally, the test cases caused by defect factors are further checked manually, the anomalies caused by non-error factors are selected, these features are summarized, and added to the whitelist, and such situations are confirmed with a lower priority in subsequent tests; otherwise, the use cases are deeply simplified manually and reported to the developer.

5. A test system for implementing the test method of any one of claims 1 to 4, characterized in that: The system includes a test case generator, a runtime monitor, a difference comparator, a case simplifier, and filters; The test case generator is used to randomly generate test cases that comply with SQL specifications and database management system characteristics according to preset statement generation rules, including state creation statements and query statements; The runtime monitor is used to input the test cases generated by the test case generator into a database management system, monitor the status of the database management system, and record the query results output by the database management system; The source code of the database management system has been modified so that the database management system can support multiple query plans; The difference comparator compares the query results output by the database management system, and when the query results are consistent, it is determined that no abnormality has occurred; Otherwise, when there is inconsistency, the judgment may be abnormal; The test case simplifier cleans the test cases where the exception occurs, that is, selects a part of the test cases where the exception occurs according to different granularities, temporarily deletes the part, and then inputs it into the database management system supporting multiple query plans to determine whether the exception occurs. If the exception still occurs, it means that the deleted part is not the key to causing the exception, and it is permanently deleted; If the exception no longer occurs, it means that the deleted part is the key to the exception, so keep it; This removes the parts that are not related to the abnormality; The filter determines whether the current abnormal test case may be caused by non-defect factors based on the preset white list. If it is caused by non-defect factors, it is allocated to the low priority queue for storage; otherwise, it is allocated to the normal priority queue for storage.