Sql statement optimization method and device, storage medium and computer device
By combining SQL statement execution plan analysis with sharded execution time analysis, and using a target rule base to identify abnormal information and generate optimization suggestions, the problems of SQL statement errors and poor performance are solved, thereby improving database query efficiency and development efficiency.
Patent Information
- Application Number
- CN202311790097.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-22
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-12-22
AI Technical Summary
In a database environment, SQL statements are prone to errors or poor performance, resulting in low data query efficiency and low efficiency in manual troubleshooting.
By obtaining the execution plan analysis results of the SQL statement, the target data table is determined and a temporary data table is generated. The SQL statement is executed and the shard execution time is counted. The target rule base is used to perform rule matching to identify abnormal information. Optimization suggestions are generated based on the shard execution time.
Quickly identify problems with SQL statements, optimize performance, improve development efficiency, reduce resource consumption, and provide comprehensive optimization suggestions.
Smart Images

Figure CN117762937B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, storage medium and computer equipment for optimizing SQL statements. Background Technology
[0002] In database environments, SQL (Structured Query Language) statements are frequently used. Furthermore, as database applications become more numerous and the volume of data processed increases, the processing logic becomes increasingly complex. Developers inevitably make statement errors or write inefficient SQL statements during development, impacting data query efficiency. Manually troubleshooting subsequent anomalies is also less efficient. Summary of the Invention
[0003] This application provides an SQL statement optimization method, apparatus, storage medium, and computer device, which can provide more comprehensive optimization suggestions, help optimize SQL statement performance, and improve development efficiency.
[0004] Firstly, this application provides a method for optimizing SQL statements, the method comprising:
[0005] Obtain the execution plan analysis results of the SQL statement;
[0006] The target data table is determined based on the execution plan analysis results;
[0007] A temporary data table is generated by sampling data from the target data table.
[0008] The SQL statement is executed on the temporary data table, and the corresponding sharding execution time is calculated according to the preset sharding stage.
[0009] The target rule base is determined based on the database corresponding to the SQL statement;
[0010] Based on the target rule base, the execution plan analysis results are matched using rules to identify abnormal information;
[0011] Optimization suggestions are generated based on the identified anomaly information and the sharding execution time of the SQL statement.
[0012] In one embodiment, the method further includes:
[0013] Obtain the execution result of the SQL statement executed on the temporary data table;
[0014] Based on the execution results, obtain the index hit data;
[0015] The index optimization suggestions in the execution plan analysis results are verified based on the index hit data.
[0016] The index optimization recommendations are updated based on the verification results.
[0017] In one embodiment, when the target rule base includes multiple rule bases, the step of performing rule matching based on the execution plan analysis results of the target rule base to identify abnormal information includes:
[0018] Obtain the priority of each rule base;
[0019] The execution plan analysis results are matched against rules in descending order of priority to identify the abnormal information.
[0020] In one embodiment, the step of performing rule matching on the execution plan analysis results in descending order of priority to identify the abnormal information includes:
[0021] Abnormal results are identified by traversing each rule base in descending order of priority.
[0022] Does the identification of abnormal results corresponding to different priority rule bases involve conflicts?
[0023] If a conflict exists, compare the priority of the rule base corresponding to the conflicting abnormal results;
[0024] Retain the abnormal results corresponding to the rule base with higher priority, and delete the abnormal results corresponding to the rule base with lower priority.
[0025] The remaining abnormal results are summarized to generate the abnormal information.
[0026] In one embodiment, the method further includes:
[0027] The preset time threshold for each sharding stage is obtained based on the SQL statement;
[0028] Identify whether the execution time of each shard of the SQL statement exceeds the time threshold of the corresponding shard stage;
[0029] If the execution time of any shard exceeds the time threshold of the corresponding shard stage, an alarm message will be generated based on the SQL statement and the shard stage whose execution time exceeds the time threshold.
[0030] In one embodiment, before performing the execution plan analysis of the obtained SQL statement, the method further includes:
[0031] The SQL statement is parsed to identify any syntax errors.
[0032] If it exists, generate syntax optimization suggestions.
[0033] Secondly, this application provides an SQL statement optimization apparatus, comprising:
[0034] The first acquisition module is used to obtain the execution plan analysis results of SQL statements;
[0035] The data table determination module is used to determine the target data table based on the execution plan analysis results;
[0036] The data table generation module is used to sample data from the target data table to generate a temporary data table;
[0037] The execution test module is used to execute the SQL statement on the temporary data table and to calculate the corresponding shard execution time according to the preset sharding stage.
[0038] The rule base determination module is used to determine the target rule base based on the database corresponding to the SQL statement;
[0039] The rule matching module is used to perform rule matching on the execution plan analysis results based on the target rule base and identify abnormal information;
[0040] The first suggestion generation module is used to generate optimization suggestions based on the identified anomaly information and the sharding execution time of the SQL statement.
[0041] In one embodiment, the device further includes:
[0042] The second acquisition module is used to acquire the execution result of the SQL statement executed on the temporary data table;
[0043] The third acquisition module is used to acquire index hit data based on the execution result;
[0044] The verification module is used to verify the index optimization suggestions in the execution plan analysis results based on the index hit data;
[0045] It is recommended to update the module to update the index optimization recommendations based on the verification results.
[0046] Thirdly, this application provides a storage medium storing computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of any of the SQL statement optimization methods described above.
[0047] Fourthly, this application provides a computer device, including: one or more processors, and a memory;
[0048] The memory stores computer-readable instructions, and when the one or more processors execute the computer-readable instructions, they perform the steps of any of the SQL statement optimization methods described above.
[0049] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0050] The SQL statement optimization method, apparatus, storage medium, and computer equipment provided in this application parse the execution plan analysis results of SQL statements, determine the target data table, generate a temporary data table based on sampling from the target data table, perform execution tests using the temporary data table and statistically analyze the sharding execution time, determine the target rule base based on the database used by the SQL statement, perform rule matching on the execution plan analysis results to identify anomalies, generate optimization suggestions based on the anomalies and sharding execution time, perform test execution using sampled data to quickly test sharding execution time, and then generate optimization suggestions by combining the actual test execution time with the anomalies identified by matching the execution plan analysis results using the target rule base. This approach provides optimization suggestions from both plan analysis and test results perspectives, helping developers quickly locate SQL statement problems and optimize performance. Attached Figure Description
[0051] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0052] Figure 1 This is a flowchart illustrating an SQL statement optimization method in one embodiment.
[0053] Figure 2 As one embodiment, the SQL statement optimization method also includes a flowchart;
[0054] Figure 3 This is a block diagram of the SQL statement optimization device in one embodiment;
[0055] Figure 4 This is a diagram of the internal structure of a computer device in one embodiment;
[0056] Figure 5 This is a diagram of the internal structure of a computer device in another embodiment. Detailed Implementation
[0057] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0058] like Figure 1 As shown, in one embodiment, this application provides an SQL statement optimization method, the method comprising:
[0059] Step S101: Obtain the execution plan analysis results of the SQL statement.
[0060] The execution plan analysis result (explain) is the execution plan derived from query analysis of the SQL statement to be optimized. From the execution plan analysis result, we can understand how each step of a SQL statement is executed, what steps it goes through, whether indexes are used, which fields use what type of indexes, and whether there are any areas for optimization. Existing SQL query optimizers can generate execution plan analysis results. This application's embodiment is based on the execution plan analysis result to further analyze and generate more comprehensive optimization suggestions.
[0061] Step S102: Determine the target data table based on the execution plan analysis results.
[0062] The target data table is the data source for the SQL statement, which can be determined from the execution plan analysis results.
[0063] Step S103: Sample data from the target data table to generate a temporary data table.
[0064] Since the target data table may contain a large amount of data, directly executing SQL statements on the target data table would consume significant resources and potentially be time-consuming. Therefore, existing optimization methods typically rely on predictive analysis of the statements to obtain optimization suggestions. In this embodiment, data is sampled from the target data table to obtain a small portion of the data, which is then used to create a temporary data table for execution testing.
[0065] Step S104: Execute SQL statements on the temporary data table and calculate the corresponding sharding execution time according to the preset sharding stage.
[0066] The preset sharding stages are pre-configured stages that may be included in the execution of various SQL statements. When executing SQL statements on temporary data tables, the execution time of each corresponding sharding stage is statistically analyzed to obtain the sharding execution time for each stage. For sharding stages that are not executed, the sharding execution time is 0. Since different SQL statements may not execute all sharding stages, and the execution time in different sharding stages may also have different rules, anomalies can be identified from execution tests based on the sharding execution time, allowing for optimization suggestions.
[0067] Step S105: Determine the target rule base based on the database corresponding to the SQL statement.
[0068] When SQL statements are applied to different databases, the rules they need to satisfy may differ. Therefore, different target rule bases can be associated with different databases. A database may be associated with one or more target rule bases.
[0069] Step S106: Based on the target rule base, perform rule matching on the execution plan analysis results to identify abnormal information.
[0070] Anomalies are those that do not match the rules, as identified by matching against the target rule base.
[0071] Step S107: Generate optimization suggestions based on the identified anomaly information and the sharding execution time of the SQL statement.
[0072] The anomalies identified by the execution plan analysis results are the optimization points discovered through predictive analysis at the planning level, while the anomalies identified based on the shard execution time are the optimization points discovered at the actual execution level. This approach can comprehensively consider different levels to propose optimization suggestions, and can obtain relatively comprehensive SQL statement optimization suggestions without consuming a lot of resources, which can effectively help developers improve development efficiency and results.
[0073] The SQL statement optimization method provided in this application parses the execution plan analysis results of the SQL statement to determine the target data table. Based on the target data table, a temporary data table is generated through sampling. The temporary data table is used for execution testing, and the sharding execution time is statistically analyzed. A target rule base is determined based on the database used by the SQL statement to perform rule matching on the execution plan analysis results, identifying anomalies. Optimization suggestions are generated based on the anomalies and sharding execution time. The sampled data is used for test execution to quickly test the sharding execution time. Furthermore, by combining the actual test execution time with the anomalies identified through matching the execution plan analysis results using the target rule base, optimization suggestions are jointly generated. Compared to simply providing the execution plan analysis results for developers' reference, this method provides optimization suggestions from both plan analysis and test results, enabling a more comprehensive identification of SQL statement problems and prompting developers to quickly locate SQL statement issues and optimize performance.
[0074] like Figure 2 As shown, in one embodiment, the SQL statement optimization method further includes:
[0075] Step S201: Obtain the execution result of the SQL statement executed on the temporary data table.
[0076] Step S202: Obtain index hit data based on the execution result.
[0077] Step S203: Verify the index optimization suggestions in the execution plan analysis results based on the index hit data.
[0078] Step S204: Update index optimization suggestions based on verification results.
[0079] In this embodiment, the index hit data obtained from the execution results of the execution test is used to verify the index optimization suggestions in the execution plan analysis results. This verifies whether the index problems judged by the predictive analysis in the execution plan analysis results are correct, and then makes corrections. If there are errors in the verification, the execution results shall prevail, and the index optimization suggestions shall be updated.
[0080] In one embodiment, when the target rule base includes multiple rule bases, the step of performing rule matching based on the execution plan analysis results and identifying abnormal information based on the target rule base includes:
[0081] Obtain the priority of each rule base;
[0082] The execution plan analysis results are matched against rules in descending order of priority to identify abnormal information.
[0083] In this embodiment, when there are multiple rule bases, in order to avoid the problem of abnormal optimization suggestions caused by rule conflicts, priority is set in advance for multiple target rule bases associated with different databases. When performing rule matching, the rules are matched in order of priority to identify abnormal information.
[0084] In one embodiment, the step of performing rule matching on the execution plan analysis results in descending order of priority to identify abnormal information includes:
[0085] Abnormal results are identified by traversing each rule base in descending order of priority.
[0086] Does the identification of abnormal results corresponding to different priority rule bases involve conflicts?
[0087] If a conflict exists, compare the priority of the rule base corresponding to the conflicting abnormal results;
[0088] Retain the abnormal results corresponding to the rule base with higher priority, and delete the abnormal results corresponding to the rule base with lower priority.
[0089] The remaining abnormal results are summarized to generate abnormal information.
[0090] In this embodiment, abnormal results refer to identification results that do not match the rule base. First, the rule bases are traversed in descending order of priority to obtain the abnormal results identified by each rule base. Then, conflict detection is performed between the abnormal results corresponding to different rule bases. If a conflict exists, the abnormal results are filtered according to the rule base priority. The abnormal results corresponding to the rule base with higher priority are retained, and the abnormal results corresponding to the rule base with lower priority are deleted. Finally, the remaining abnormal results are summarized to obtain abnormal information. Optimization suggestions can be generated based on the rules corresponding to the abnormal information.
[0091] In one embodiment, the SQL statement optimization method further includes:
[0092] Retrieve the preset time threshold for each sharding stage based on the SQL statement;
[0093] Identify whether the execution time of each SQL statement in each shard exceeds the time threshold of the corresponding shard stage;
[0094] If the execution time of any shard exceeds the time threshold of the corresponding shard stage, an alarm message will be generated based on the SQL statement and the shard stage whose execution time exceeds the time threshold.
[0095] In this embodiment, the execution time of different SQL statements may vary in different sharding stages. By obtaining the corresponding preset time threshold, alarm detection is performed on the sharding execution time obtained from the test execution. If the time threshold of the corresponding sharding stage is exceeded, it indicates that an anomaly has occurred in that sharding stage. Generating an alarm prompt can help developers quickly locate the anomaly.
[0096] In one embodiment, before performing the execution plan analysis to obtain the SQL statement, the method further includes:
[0097] The SQL statement is parsed to identify any syntax errors.
[0098] If it exists, generate syntax optimization suggestions.
[0099] In this embodiment, in order to further optimize the SQL statement, before executing the SQL statement execution plan analysis results, the SQL statement is first parsed to identify syntax errors and provide optimization suggestions, thereby improving the optimization effect and helping to improve development efficiency.
[0100] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0101] The SQL statement optimization apparatus provided in the embodiments of this application is described below. The SQL statement optimization apparatus described below can be referred to in correspondence with the SQL statement optimization method described above.
[0102] like Figure 3 As shown, this application provides an SQL statement optimization device 300, including:
[0103] The first acquisition module 301 is used to acquire the execution plan analysis results of SQL statements;
[0104] Data table determination module 302 is used to determine the target data table based on the execution plan analysis results;
[0105] Data table generation module 303 is used to sample data from the target data table to generate a temporary data table;
[0106] The execution test module 304 is used to execute the SQL statement on the temporary data table and to calculate the corresponding shard execution time according to the preset sharding stage.
[0107] Rule base determination module 305 is used to determine the target rule base based on the database corresponding to the SQL statement;
[0108] The rule matching module 306 is used to perform rule matching on the execution plan analysis results based on the target rule base and identify abnormal information;
[0109] The first suggestion generation module 307 is used to generate optimization suggestions based on the identified anomaly information and the sharding execution time of the SQL statement.
[0110] In one embodiment, the device further includes:
[0111] The second acquisition module is used to acquire the execution result of the SQL statement executed on the temporary data table;
[0112] The third acquisition module is used to acquire index hit data based on the execution result;
[0113] The verification module is used to verify the index optimization suggestions in the execution plan analysis results based on the index hit data;
[0114] It is recommended to update the module to update the index optimization recommendations based on the verification results.
[0115] In one embodiment, the rule matching module is configured to perform the following steps when the target rule base includes multiple rule bases:
[0116] Obtain the priority of each rule base;
[0117] The execution plan analysis results are matched against rules in descending order of priority to identify the abnormal information.
[0118] In one embodiment, the rule matching module is configured to perform the following steps when the target rule base includes multiple rule bases:
[0119] Abnormal results are identified by traversing each rule base in descending order of priority.
[0120] Does the identification of abnormal results corresponding to different priority rule bases involve conflicts?
[0121] If a conflict exists, compare the priority of the rule base corresponding to the conflicting abnormal results;
[0122] Retain the abnormal results corresponding to the rule base with higher priority, and delete the abnormal results corresponding to the rule base with lower priority.
[0123] The remaining abnormal results are summarized to generate the abnormal information.
[0124] In one embodiment, the SQL statement optimization apparatus further includes:
[0125] The time threshold acquisition module is used to obtain the preset time threshold for each segmentation stage according to the SQL statement.
[0126] The time determination module is used to identify whether the execution time of each shard of the SQL statement exceeds the time threshold of the corresponding shard stage.
[0127] The alert generation module is used to generate an alarm alert based on the SQL statement and the shard stage in which the execution time of any shard exceeds the time threshold of the corresponding shard stage.
[0128] In one embodiment, the SQL statement optimization apparatus further includes
[0129] The syntax parsing module is used to parse the SQL statement and identify whether there are any syntax errors.
[0130] The second suggestion generation module is used to generate syntax optimization suggestions when a syntax error is identified in an SQL statement.
[0131] The division of modules in the above-described SQL statement optimization device is merely illustrative. In other embodiments, the SQL statement optimization device can be divided into different modules as needed to complete all or part of its functions. Each module in the above-described SQL statement optimization device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0132] In one embodiment, this application also provides a storage medium storing computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the SQL statement optimization method as described in any of the above embodiments.
[0133] In one embodiment, this application also provides a computer device storing computer-readable instructions, wherein when the one or more processors execute the computer-readable instructions, they perform the steps of the SQL statement optimization method as described in any of the above embodiments.
[0134] In one embodiment, schematically, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data. The network interface communicates with external terminals via a network connection. When executed by the processor, the computer program implements an SQL statement optimization method.
[0135] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 5 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements an SQL statement optimization method. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.
[0136] Those skilled in the art will understand that Figure 4 , Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0137] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0138] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0139] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0140] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.
[0141] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for optimizing SQL statements, characterized in that, The method includes: Obtain the execution plan analysis results of the SQL statement; The target data table is determined based on the execution plan analysis results; A temporary data table is generated by sampling data from the target data table. The SQL statement is executed on the temporary data table, and the corresponding sharding execution time is calculated according to the preset sharding stage. The target rule base is determined based on the database corresponding to the SQL statement; Based on the target rule base, rule matching is performed on the execution plan analysis results to identify abnormal information; Optimization suggestions are generated based on the identified anomaly information and the sharding execution time of the SQL statement; The method further includes: Obtain the execution result of the SQL statement executed on the temporary data table; Based on the execution results, obtain the index hit data; The index optimization suggestions in the execution plan analysis results are verified based on the index hit data. The index optimization recommendations are updated based on the verification results.
2. The SQL statement optimization method according to claim 1, characterized in that, When the target rule base includes multiple rule bases, the step of performing rule matching based on the execution plan analysis results of the target rule base to identify abnormal information includes: Obtain the priority of each rule base; The execution plan analysis results are matched against rules in descending order of priority to identify the abnormal information.
3. The SQL statement optimization method according to claim 2, characterized in that, The step of performing rule matching on the execution plan analysis results in descending order of priority to identify the abnormal information includes: Abnormal results are identified by traversing each rule base in descending order of priority. Does the identification of abnormal results corresponding to different priority rule bases involve conflicts? If a conflict exists, compare the priority of the rule base corresponding to the conflicting abnormal results; Retain the abnormal results corresponding to the rule base with higher priority, and delete the abnormal results corresponding to the rule base with lower priority. The remaining abnormal results are summarized to generate the abnormal information.
4. The SQL statement optimization method according to claim 1, characterized in that, The method further includes: The preset time threshold for each sharding stage is obtained based on the SQL statement; Identify whether the execution time of each shard of the SQL statement exceeds the time threshold of the corresponding shard stage; If the execution time of any shard exceeds the time threshold of the corresponding shard stage, an alarm message will be generated based on the SQL statement and the shard stage whose execution time exceeds the time threshold.
5. The SQL statement optimization method according to claim 1, characterized in that, Before executing the SQL statement execution plan analysis results, the following steps are also included: The SQL statement is parsed to identify any syntax errors. If it exists, generate syntax optimization suggestions.
6. An SQL statement optimization device, characterized in that, include: The first acquisition module is used to obtain the execution plan analysis results of SQL statements; The data table determination module is used to determine the target data table based on the execution plan analysis results; The data table generation module is used to sample data from the target data table to generate a temporary data table; The execution test module is used to execute the SQL statement on the temporary data table and to calculate the corresponding shard execution time according to the preset sharding stage. The rule base determination module is used to determine the target rule base based on the database corresponding to the SQL statement; The rule matching module is used to perform rule matching on the execution plan analysis results based on the target rule base and identify abnormal information; The first suggestion generation module is used to generate optimization suggestions based on the identified anomaly information and the sharding execution time of the SQL statement; The device further includes: The second acquisition module is used to acquire the execution result of the SQL statement executed on the temporary data table; The third acquisition module is used to acquire index hit data based on the execution result; The verification module is used to verify the index optimization suggestions in the execution plan analysis results based on the index hit data; It is recommended to update the module to update the index optimization recommendations based on the verification results.
7. A storage medium, characterized in that: The storage medium stores computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the SQL statement optimization method as described in any one of claims 1 to 5.
8. A computer device, characterized in that, include: One or more processors, and memory; The memory stores computer-readable instructions, and when the one or more processors execute the computer-readable instructions, they perform the steps of the SQL statement optimization method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Device and method for optimizing execution plan and based on practice testing
CN102436494A
Data testing method and device, electronic equipment and storage medium
CN113868141A
Auxiliary optimization method and device for structured query language
CN115481141A
