Power grid database query statement optimization method and device based on large model

By using a large model-based approach to filter and identify abnormal query statements in the power grid database, generating optimized query statements and verifying replacements, the problem of low optimization efficiency for fixed query statements in the power grid database is solved, achieving efficient and stable query optimization and improved business system response speed.

CN121722787APending Publication Date: 2026-03-24GUANGDONG POWER GRID CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-27
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing technologies for optimizing large batches of fixed query statements in power grid databases are inefficient, cannot maintain optimization results for a long time, and are prone to errors and omissions, resulting in bottlenecks in query efficiency and business system response speed, and affecting the efficiency of intelligent operation and maintenance.

Method used

A large-model-based approach is adopted to identify abnormal query statements, abnormal types and operations, generate optimized query statements based on the database table structure and optimization requirements, and verify and replace them on the database backup to ensure the rationality and stability of the optimization.

Benefits of technology

This improved the efficiency and rationality of power grid database query statements, ensured the stable operation of the optimized database, and enhanced the response speed and intelligent operation and maintenance efficiency of the power grid business system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121722787A_ABST
    Figure CN121722787A_ABST
Patent Text Reader

Abstract

The invention discloses a power grid database query statement optimization method and device based on a large model, and relates to the field of database performance optimizing.The power grid database query statement optimization method comprises the steps that according to all query statements and operation logs, multiple abnormal query statements are screened in combination with optimization requirements; on the basis of the first large model, in combination with the running log of each abnormal query statement, allocating an abnormal type for each abnormal query statement, and further identifying an abnormal operation; based on the first large model, according to the abnormal operation of each abnormal query statement, generating an optimized query statement for each abnormal query statement in combination with a library table structure and optimization requirements of the power grid database; and loading and verifying all the optimized query statements on the backup of the power grid database at the same time, and replacing the verified optimized query statements with the corresponding abnormal query statements to complete the optimization of the query statements. According to the method, a large batch of fixed query statements in the power grid database can be reasonably optimized, so that the intelligent operation and maintenance efficiency of the power grid database is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database performance optimization, and in particular to a method and apparatus for optimizing query statements in a power grid database based on a large model. Background Technology

[0002] With the continuous development of smart grids, their data scale is gradually expanding, and the amount of power grid operation data stored in dedicated databases is also increasing. This is reflected in the continuous increase in data fields, data tables, and corresponding database table structures, which poses new challenges to the intelligent operation and maintenance of power grid databases. As the amount of data in power grid databases increases and the complexity of database table structures improves, the number of fixed query statements corresponding to the power grid database in power grid business systems also increases. However, the optimization of these fixed query statements is lacking, resulting in bottlenecks in the query efficiency of power grid databases and the response speed of power grid business systems.

[0003] Currently, optimization of these fixed query statements typically involves either using the database's built-in optimizer or manually specifying rules and iteratively optimizing inefficient queries. However, the former requires optimization only before query execution and necessitates restarting the optimization process after each execution, making it difficult to maintain results long-term. Furthermore, in complex scenarios, it can only generate fixed optimization schemes, failing to meet practical needs. The latter approach can maintain optimization results long-term, but manual optimization is inefficient, and the need to manually apply optimization rules makes it prone to errors, resulting in insufficient optimization of query efficiency. Therefore, how to improve the query efficiency of the power grid database and the response speed of the power grid business system through reasonable optimization of the large number of fixed query statements associated with business systems in the power grid database, thereby improving the intelligent operation and maintenance efficiency of the power grid database, remains a pressing technical problem that needs to be solved by existing technologies. Summary of the Invention

[0004] This application provides a method and apparatus for optimizing query statements in a power grid database based on a large model, in order to solve the technical problem that existing optimization methods for large batches of fixed query statements in power grid databases are unreasonable.

[0005] According to a first aspect of the embodiments of this application, a method for optimizing power grid database query statements based on a large model is provided, comprising: Based on the query statements and corresponding operation logs in the power grid database to be optimized, and in conjunction with the optimization requirements, several abnormal query statements were selected. Based on the preset first major model, combined with the execution log of each abnormal query statement, a corresponding abnormal type is assigned to each abnormal query statement, and abnormal operations in each abnormal query statement are identified according to the execution log and abnormal type of each abnormal query statement. Based on the first major model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements, a corresponding optimized query statement is generated for each abnormal query statement. All optimized query statements are loaded and verified simultaneously on the backup of the power grid database. Several optimized query statements that pass verification are replaced with the corresponding abnormal query statements in the power grid database to complete the optimization of the query statements in the power grid database.

[0006] This application first identifies multiple abnormal query statements based on the query statements and corresponding operation logs of the power grid database to be optimized, combined with optimization requirements. Then, it assigns corresponding abnormal types according to a large model, thereby identifying the abnormal operations of each abnormal query statement. Compared with the existing scheme of manually identifying and optimizing each query statement one by one, this method improves optimization efficiency and thus enhances the rationality of optimization by using a large model to batch assign abnormal types and identify abnormal operations for multiple abnormal query statements. Next, the large model, combined with the database table structure and optimization requirements, generates optimized query statements for each abnormal query statement. This ensures that the optimized query statements meet the database table structure and optimization requirements, further enhancing the rationality of optimization. Finally, by simultaneously loading and verifying the power grid database backup and replacing the verified optimized query statements, it ensures that there are no logical or execution conflicts between the verified optimized query statements, ensuring the stable operation of the optimized power grid database and improving the rationality of large-scale optimization of fixed query statements in the power grid database.

[0007] In some embodiments of this application, the step of filtering out multiple abnormal query statements based on the query statements and corresponding operation logs in the power grid database to be optimized, combined with optimization requirements, specifically includes: Based on the execution logs of each query statement in the power grid database, multiple query statements to be identified are selected based on the statement execution time, and entity recognition is performed on the multiple query statements to be identified to obtain the data entity of each query statement to be identified. Based on a pre-defined abnormal entity association knowledge graph, and combined with the operation log of each query statement, the data entities of each query statement to be identified are identified, and multiple abnormal query statements are determined based on the identification results; wherein, the abnormal entity association knowledge graph is obtained by performing association analysis on historical abnormal operation logs and all data entities in the power grid database.

[0008] This application first filters multiple query statements to be identified based on the execution time of the query statements in the power grid database. The query statements with possible anomalies are identified by their execution time, which is convenient and fast. After identifying their data entities, the application performs identification based on a pre-set abnormal entity association knowledge graph. By analyzing the historical anomalies of each identified data entity, it can quickly determine whether the corresponding query statement may be abnormal. This, combined with the operation log, improves the accuracy of identification and provides a foundation for subsequent optimization of abnormal query statements.

[0009] In some embodiments of this application, the step of assigning a corresponding exception type to each exception query statement based on a preset first large model and the execution log of each exception query statement, and identifying the exception operation in each exception query statement according to the execution log and exception type, specifically includes: Each abnormal query statement is parsed into a corresponding abstract syntax tree. Based on the first large model and combined with the execution log of each abnormal query statement, the abstract syntax tree of each abnormal query statement is identified, and a corresponding abnormal type is assigned to each abnormal query statement. Based on the first model, according to the execution log and exception type of each exception query statement, the multiple query operations corresponding to the abstract syntax tree of each exception query statement are identified to obtain the exception operations in each exception query statement.

[0010] This application first parses each abnormal query statement into an abstract syntax tree (AST). Based on a large model and combined with runtime logs, it identifies the AST of each abnormal query statement and assigns an exception type. The combination of the AST and runtime logs improves the accuracy of identification and makes the assignment of exception types more accurate, thereby improving the accuracy of subsequent abnormal operation identification. Then, based on the large model, it identifies multiple query operations corresponding to the AST of each abnormal query statement to obtain the abnormal operation of each abnormal query statement, further improving the accuracy of identification and providing a foundation for subsequent optimization of abnormal query statements.

[0011] In some embodiments of this application, the step of generating corresponding optimized query statements for each abnormal query statement based on the first large model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements, specifically includes: Based on the first major model and combined with the optimization requirements, the abnormal operation of each abnormal query statement is optimized, and multiple first query statements are generated for each abnormal query statement. Based on the cost estimator, determine the execution cost of each first query statement for each abnormal query statement; Based on the database table structure and preset optimization semantic equivalence rules, the semantically equivalent query statement with the lowest execution cost among the multiple first query statements corresponding to each abnormal query statement is selected as the corresponding optimized query statement.

[0012] This application first optimizes the abnormal operations of each abnormal query statement based on a large model and in conjunction with optimization requirements, generating multiple first query statements. By focusing on optimizing abnormal operations, it can provide corresponding attention for the large model to optimize query statements, thereby improving the accuracy of the large model's query statement optimization. Then, based on a cost estimator, it determines the execution cost of each first query statement of each abnormal query statement, and combines the database table structure and optimization semantic equivalence rules to determine the optimized query statement for each abnormal query statement. By constraining the optimization through three aspects—execution cost, database table structure, and optimization semantic equivalence rules—the determinism, feasibility, and semantic equivalence of the optimization are guaranteed, thereby improving the accuracy of the optimization.

[0013] In some embodiments of this application, it further includes: Based on the first large model, conflict analysis is performed on several unvalidated optimized query statements. Based on the conflict analysis results, each unvalidated optimized query statement is iteratively optimized. During the iteration process, the optimized query statement is regenerated and simultaneously loaded and validated on the backup of the power grid database. After validation, the validated optimized query statement and the corresponding abnormal query statement are replaced and the validated optimized query statement is removed until all optimized query statements are validated.

[0014] This application performs conflict analysis on unvalidated optimized query statements based on a large model, and then iteratively optimizes them until all optimized query statements pass validation. This ensures that there are no logical or execution conflicts between the corresponding optimized query statements of all abnormal query statements, and ensures that each abnormal query statement is optimized accordingly. This guarantees the stable operation of the optimized power grid database and improves the rationality of large-scale optimization of fixed query statements in the power grid database.

[0015] According to a second aspect of the embodiments of this application, a power grid database query statement optimization device based on a large model is provided, including an abnormal statement filtering module, an abnormal operation identification module, an optimized query generation module, and an optimized query verification module; The abnormal statement filtering module is used to filter out multiple abnormal query statements based on each query statement and corresponding operation log in the power grid database to be optimized, combined with optimization requirements. The abnormal operation identification module is used to assign a corresponding abnormal type to each abnormal query statement based on a preset first model and the execution log of each abnormal query statement, and to identify the abnormal operation in each abnormal query statement according to the execution log and abnormal type of each abnormal query statement. The optimized query generation module is used to generate corresponding optimized query statements for each abnormal query statement based on the first large model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements. The optimized query verification module is used to simultaneously load and verify all optimized query statements on the backup of the power grid database, and replace the verified optimized query statements with the corresponding abnormal query statements in the power grid database to complete the optimization of the query statements in the power grid database.

[0016] In some embodiments of this application, the abnormal statement filtering module includes a statement filtering and identification unit and an abnormal statement identification unit; The statement filtering and identification unit is used to filter out multiple query statements to be identified based on the execution time of each query statement in the power grid database, and to perform entity identification on the multiple query statements to be identified to obtain the data entity of each query statement to be identified. The abnormal statement identification unit is used to identify the data entities of each query statement based on a preset abnormal entity association knowledge graph and the running log of each query statement, and to determine multiple abnormal query statements based on the identification results; wherein, the abnormal entity association knowledge graph is obtained by association analysis of historical abnormal running logs and all data entities in the power grid database.

[0017] In some embodiments of this application, the abnormal operation identification module includes an abnormal type identification unit and an abnormal operation identification unit; The exception type identification unit is used to parse each exception query statement into a corresponding abstract syntax tree, and based on the first large model and combined with the running log of each exception query statement, identify the abstract syntax tree of each exception query statement and assign a corresponding exception type to each exception query statement. The abnormal operation identification unit is used to identify multiple query operations corresponding to the abstract syntax tree of each abnormal query statement based on the first large model, according to the running log and abnormal type of each abnormal query statement, so as to obtain the abnormal operation in each abnormal query statement.

[0018] In some embodiments of this application, the optimized query generation module includes an optimized statement generation unit, an execution cost determination unit, and an optimized statement determination unit; The optimized statement generation unit is used to optimize the abnormal operation of each abnormal query statement based on the first large model and in combination with the optimization requirements, and generate multiple first query statements for each abnormal query statement. The execution cost determination unit is used to determine the execution cost of each first query statement of each abnormal query statement based on the cost estimator. The optimized query statement determination unit is used to determine the semantically equivalent and least costly first query statement among multiple first query statements corresponding to each abnormal query statement, based on the database table structure of the power grid database and preset optimization semantic equivalence rules.

[0019] In some embodiments of this application, a query optimization iteration module is also included; The query optimization iteration module is used to perform conflict analysis on several unverified optimized query statements based on the first large model, and to iteratively optimize each unverified optimized query statement according to the conflict analysis results. During the iteration process, the optimized query statement is regenerated and simultaneously loaded and verified on the backup of the power grid database. After verification, the verified optimized query statement and the corresponding abnormal query statement are replaced and the verified optimized query statement is removed until all optimized query statements are verified.

[0020] This application first identifies multiple abnormal query statements based on the query statements and corresponding operation logs of the power grid database to be optimized, combined with optimization requirements. Then, it assigns corresponding abnormal types according to a large model, thereby identifying the abnormal operations of each abnormal query statement. Compared with the existing scheme of manually identifying and optimizing each query statement one by one, this method improves optimization efficiency and thus enhances the rationality of optimization by using a large model to batch assign abnormal types and identify abnormal operations for multiple abnormal query statements. Next, the large model, combined with the database table structure and optimization requirements, generates optimized query statements for each abnormal query statement. This ensures that the optimized query statements meet the database table structure and optimization requirements, further enhancing the rationality of optimization. Finally, by simultaneously loading and verifying the power grid database backup and replacing the verified optimized query statements, it ensures that there are no logical or execution conflicts between the verified optimized query statements, ensuring the stable operation of the optimized power grid database and improving the rationality of large-scale optimization of fixed query statements in the power grid database. Attached Figure Description

[0021] Figure 1 This is a flowchart illustrating a method for optimizing power grid database query statements based on a large model, as shown in some embodiments of this application. Figure 2This is a module structure diagram of a power grid database query statement optimization device based on a large model, as shown in some embodiments of this application. Detailed Implementation

[0022] The embodiments of this application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below in conjunction with the accompanying drawings are exemplary and are only used to explain some embodiments of this application, and should not be construed as limiting the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments shown in this application without inventive effort are within the protection scope of this application.

[0023] In the description of this application, it should be understood that 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 indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, unless otherwise explicitly specified, "a plurality of" or "several" means two or more.

[0024] Currently, optimizing large batches of fixed query statements in power grid databases typically involves either using the database's built-in optimizer or manually specifying rules and iteratively optimizing inefficient queries. However, the former requires optimization only before query execution and necessitates restarting the optimization process after each execution, making it difficult to maintain long-term results. Furthermore, in complex scenarios, it can only generate fixed optimization schemes, failing to meet practical needs. The latter method can maintain optimization results long-term, but manual optimization is inefficient, and the need to manually apply optimization rules makes it prone to errors, resulting in insufficient optimization of query efficiency. Therefore, how to improve the query efficiency of power grid databases and the response speed of power grid business systems through reasonable optimization of large batches of fixed query statements associated with business systems in power grid databases, thereby improving the intelligent operation and maintenance efficiency of power grid databases, remains a pressing technical problem that needs to be solved.

[0025] Based on the above technical background, please refer to Figure 1 This application provides a method for optimizing power grid database query statements based on a large model, including steps S101 to S104, each step as follows: Step S101: Based on the query statements and corresponding operation logs in the power grid database to be optimized, and in conjunction with the optimization requirements, select multiple abnormal query statements.

[0026] In some embodiments of this application, the step of filtering out multiple abnormal query statements based on the query statements and corresponding operation logs in the power grid database to be optimized, combined with optimization requirements, specifically includes: Based on the execution logs of each query statement in the power grid database, multiple query statements to be identified are selected based on the statement execution time, and entity recognition is performed on the multiple query statements to be identified to obtain the data entity of each query statement to be identified. Based on a pre-defined abnormal entity association knowledge graph, and combined with the operation log of each query statement, the data entities of each query statement to be identified are identified, and multiple abnormal query statements are determined based on the identification results; wherein, the abnormal entity association knowledge graph is obtained by performing association analysis on historical abnormal operation logs and all data entities in the power grid database.

[0027] The reason for considering filtering query statements by execution time is that the execution time of query statements can most intuitively reflect the execution speed and overhead of the power grid database for query statements, thereby identifying query statements that may be abnormal with the greatest efficiency and accuracy.

[0028] Specifically, the data entities in the power grid database include, but are not limited to, the names of databases, data tables, and indexes, as well as the specific values ​​of each column of each specific data item in each data table. When determining whether a query statement to be identified is an abnormal query statement based on the identification results of the data entities, if the threshold of the identification result is higher than a preset value, the corresponding query statement to be identified is determined to be an abnormal query statement. Through the correlation analysis of historical abnormal operation logs and all data entities in the power grid database, the probability of each data entity causing an anomaly or having an anomaly can be determined. Furthermore, through the abnormal entity association knowledge graph obtained by the correlation analysis, query statements that may have an anomaly and whose probability is higher than the threshold can be identified as abnormal query statements.

[0029] This application first filters multiple query statements to be identified based on the execution time of the query statements in the power grid database. The query statements with possible anomalies are identified by their execution time, which is convenient and fast. After identifying their data entities, the application performs identification based on a pre-set abnormal entity association knowledge graph. By analyzing the historical anomalies of each identified data entity, it can quickly determine whether the corresponding query statement may be abnormal. This, combined with the operation log, improves the accuracy of identification and provides a foundation for subsequent optimization of abnormal query statements.

[0030] Step S102: Based on the preset first large model, combined with the execution log of each abnormal query statement, assign a corresponding exception type to each abnormal query statement, and identify the abnormal operation in each abnormal query statement according to the execution log and exception type of each abnormal query statement.

[0031] In some embodiments of this application, the step of assigning a corresponding exception type to each exception query statement based on a preset first large model and the execution log of each exception query statement, and identifying the exception operation in each exception query statement according to the execution log and exception type, specifically includes: Each abnormal query statement is parsed into a corresponding abstract syntax tree. Based on the first large model and combined with the execution log of each abnormal query statement, the abstract syntax tree of each abnormal query statement is identified, and a corresponding abnormal type is assigned to each abnormal query statement. Based on the first model, according to the execution log and exception type of each exception query statement, the multiple query operations corresponding to the abstract syntax tree of each exception query statement are identified to obtain the exception operations in each exception query statement.

[0032] In some embodiments of this application, when parsing an abnormal query statement into a corresponding abstract syntax tree, it can be parsed using the lexical analyzer and syntax analyzer built into the power grid database, or it can be parsed using the lexical analyzer and syntax analyzer provided by an external interface or server, or it can be parsed using the first major model combined with prompt words.

[0033] Specifically, the abstract syntax tree of a query statement includes multiple levels. The level above the level where the leaf node of the abstract syntax tree is located is usually associated with a query operation of the query statement. Therefore, multiple query operations of the query statement can be determined through the abstract syntax tree.

[0034] This application first parses each abnormal query statement into an abstract syntax tree (AST). Based on a large model and combined with runtime logs, it identifies the AST of each abnormal query statement and assigns an exception type. The combination of the AST and runtime logs improves the accuracy of identification and makes the assignment of exception types more accurate, thereby improving the accuracy of subsequent abnormal operation identification. Then, based on the large model, it identifies multiple query operations corresponding to the AST of each abnormal query statement to obtain the abnormal operation of each abnormal query statement, further improving the accuracy of identification and providing a foundation for subsequent optimization of abnormal query statements.

[0035] Step S103: Based on the first large model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements, generate a corresponding optimized query statement for each abnormal query statement.

[0036] In some embodiments of this application, the step of generating corresponding optimized query statements for each abnormal query statement based on the first large model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements, specifically includes: Based on the first major model and combined with the optimization requirements, the abnormal operation of each abnormal query statement is optimized, and multiple first query statements are generated for each abnormal query statement. Based on the cost estimator, determine the execution cost of each first query statement for each abnormal query statement; Based on the database table structure and preset optimization semantic equivalence rules, the semantically equivalent query statement with the lowest execution cost among the multiple first query statements corresponding to each abnormal query statement is selected as the corresponding optimized query statement.

[0037] Specifically, the cost estimator can be built into the power grid database, or it can be provided by an external interface or server.

[0038] Specifically, the optimized semantic equivalence rule includes the equivalence of relational algebra expressions, that is, the relational algebra expression of the abnormal query statement and the relational algebra expression of the first query statement yield the same result.

[0039] This application first optimizes the abnormal operations of each abnormal query statement based on a large model and in conjunction with optimization requirements, generating multiple first query statements. By focusing on optimizing abnormal operations, it can provide corresponding attention for the large model to optimize query statements, thereby improving the accuracy of the large model's query statement optimization. Then, based on a cost estimator, it determines the execution cost of each first query statement of each abnormal query statement, and combines the database table structure and optimization semantic equivalence rules to determine the optimized query statement for each abnormal query statement. By constraining the optimization through three aspects—execution cost, database table structure, and optimization semantic equivalence rules—the determinism, feasibility, and semantic equivalence of the optimization are guaranteed, thereby improving the accuracy of the optimization.

[0040] Step S104: Simultaneously load and verify all optimized query statements on the backup of the power grid database, and replace the verified optimized query statements with the corresponding abnormal query statements in the power grid database to complete the optimization of the query statements in the power grid database.

[0041] In some embodiments of this application, it further includes: Based on the first large model, conflict analysis is performed on several unvalidated optimized query statements. Based on the conflict analysis results, each unvalidated optimized query statement is iteratively optimized. During the iteration process, the optimized query statement is regenerated and simultaneously loaded and validated on the backup of the power grid database. After validation, the validated optimized query statement and the corresponding abnormal query statement are replaced and the validated optimized query statement is removed until all optimized query statements are validated.

[0042] This application performs conflict analysis on unvalidated optimized query statements based on a large model, and then iteratively optimizes them until all optimized query statements pass validation. This ensures that there are no logical or execution conflicts between the corresponding optimized query statements of all abnormal query statements, and ensures that each abnormal query statement is optimized accordingly. This guarantees the stable operation of the optimized power grid database and improves the rationality of large-scale optimization of fixed query statements in the power grid database.

[0043] Compared to existing technologies, this application first selects multiple abnormal query statements based on the query statements and corresponding operation logs of the power grid database to be optimized, combined with optimization requirements. Then, it assigns corresponding abnormal types according to a large model, thereby identifying the abnormal operations of each abnormal query statement. Compared to existing solutions that manually identify and optimize each query statement one by one, this application improves optimization efficiency and thus enhances the rationality of optimization by using a large model to batch assign abnormal types and identify abnormal operations for multiple abnormal query statements. Next, the large model, combined with the database structure and optimization requirements, generates optimized query statements for each abnormal query statement. This ensures that the optimized query statements meet the database structure and optimization requirements, further enhancing the rationality of optimization. Finally, by simultaneously loading and verifying the power grid database backup and replacing the verified optimized query statements, it ensures that there are no logical or execution conflicts between the verified optimized query statements, ensuring the stable operation of the optimized power grid database and improving the rationality of large-scale optimization of fixed query statements in the power grid database.

[0044] For a method corresponding to the one described above, please refer to [link to relevant documentation]. Figure 2 The present application provides a power grid database query statement optimization device based on a large model, including an abnormal statement filtering module 210, an abnormal operation identification module 220, an optimized query generation module 230 and an optimized query verification module 240. The abnormal statement filtering module 210 is used to filter out multiple abnormal query statements based on each query statement and corresponding operation log in the power grid database to be optimized, combined with optimization requirements. The abnormal operation identification module 220 is used to assign a corresponding abnormal type to each abnormal query statement based on a preset first model and the running log of each abnormal query statement, and to identify the abnormal operation in each abnormal query statement according to the running log and abnormal type of each abnormal query statement. The optimized query generation module 230 is used to generate corresponding optimized query statements for each abnormal query statement based on the first large model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements. The optimized query verification module 240 is used to simultaneously load and verify all optimized query statements on the backup of the power grid database, and replace the verified optimized query statements with the corresponding abnormal query statements in the power grid database to complete the optimization of the query statements in the power grid database.

[0045] In some embodiments of this application, the abnormal statement filtering module 210 includes a statement filtering and identification unit and an abnormal statement identification unit; The statement filtering and identification unit is used to filter out multiple query statements to be identified based on the execution time of each query statement in the power grid database, and to perform entity identification on the multiple query statements to be identified to obtain the data entity of each query statement to be identified. The abnormal statement identification unit is used to identify the data entities of each query statement based on a preset abnormal entity association knowledge graph and the running log of each query statement, and to determine multiple abnormal query statements based on the identification results; wherein, the abnormal entity association knowledge graph is obtained by association analysis of historical abnormal running logs and all data entities in the power grid database.

[0046] In some embodiments of this application, the abnormal operation identification module 220 includes an abnormal type identification unit and an abnormal operation identification unit; The exception type identification unit is used to parse each exception query statement into a corresponding abstract syntax tree, and based on the first large model and combined with the running log of each exception query statement, identify the abstract syntax tree of each exception query statement and assign a corresponding exception type to each exception query statement. The abnormal operation identification unit is used to identify multiple query operations corresponding to the abstract syntax tree of each abnormal query statement based on the first large model, according to the running log and abnormal type of each abnormal query statement, so as to obtain the abnormal operation in each abnormal query statement.

[0047] In some embodiments of this application, the optimized query generation module 230 includes an optimized statement generation unit, an execution cost determination unit, and an optimized statement determination unit; The optimized statement generation unit is used to optimize the abnormal operation of each abnormal query statement based on the first large model and in combination with the optimization requirements, and generate multiple first query statements for each abnormal query statement. The execution cost determination unit is used to determine the execution cost of each first query statement of each abnormal query statement based on the cost estimator. The optimized query statement determination unit is used to determine the semantically equivalent and least costly first query statement among multiple first query statements corresponding to each abnormal query statement, based on the database table structure of the power grid database and preset optimization semantic equivalence rules.

[0048] In some embodiments of this application, a query optimization iteration module is also included; The query optimization iteration module is used to perform conflict analysis on several unverified optimized query statements based on the first large model, and to iteratively optimize each unverified optimized query statement according to the conflict analysis results. During the iteration process, the optimized query statement is regenerated and simultaneously loaded and verified on the backup of the power grid database. After verification, the verified optimized query statement and the corresponding abnormal query statement are replaced and the verified optimized query statement is removed until all optimized query statements are verified.

[0049] This application first identifies multiple abnormal query statements based on the query statements and corresponding operation logs of the power grid database to be optimized, combined with optimization requirements. Then, it assigns corresponding abnormal types according to a large model, thereby identifying the abnormal operations of each abnormal query statement. Compared with the existing scheme of manually identifying and optimizing each query statement one by one, this method improves optimization efficiency and thus enhances the rationality of optimization by using a large model to batch assign abnormal types and identify abnormal operations for multiple abnormal query statements. Next, the large model, combined with the database table structure and optimization requirements, generates optimized query statements for each abnormal query statement. This ensures that the optimized query statements meet the database table structure and optimization requirements, further enhancing the rationality of optimization. Finally, by simultaneously loading and verifying the power grid database backup and replacing the verified optimized query statements, it ensures that there are no logical or execution conflicts between the verified optimized query statements, ensuring the stable operation of the optimized power grid database and improving the rationality of large-scale optimization of fixed query statements in the power grid database.

[0050] It should be understood that the apparatus provided in this application corresponds to the aforementioned method. The power grid database query statement optimization apparatus based on a large model provided in this application can implement the power grid database query statement optimization method based on a large model provided in any embodiment of this application.

[0051] Adaptively, embodiments of this application also provide a computer device and a computer-readable storage medium.

[0052] The computer device includes: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor; The processor, when executing the computer program, implements a method for optimizing power grid database query statements based on a large model, as described in this application.

[0053] The computer-readable storage medium stores multiple instructions adapted for loading by a processor to execute a method for optimizing power grid database query statements based on a large model, as described in this application.

[0054] The above description represents some embodiments of this application, providing a further detailed explanation of the purpose, technical solution, and beneficial effects of this application. It should be understood that the above-described embodiments of this application should not be construed as limiting this application. In particular, any changes, modifications, equivalent substitutions, and variations made by those skilled in the art within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A method for optimizing query statements in a power grid database based on a large model, characterized in that, include: Based on the query statements and corresponding operation logs in the power grid database to be optimized, and in conjunction with the optimization requirements, several abnormal query statements were selected. Based on the preset first major model, combined with the execution log of each abnormal query statement, a corresponding abnormal type is assigned to each abnormal query statement, and abnormal operations in each abnormal query statement are identified according to the execution log and abnormal type of each abnormal query statement. Based on the first major model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements, a corresponding optimized query statement is generated for each abnormal query statement. All optimized query statements are loaded and verified simultaneously on the backup of the power grid database. Several optimized query statements that pass verification are replaced with the corresponding abnormal query statements in the power grid database to complete the optimization of the query statements in the power grid database.

2. The method for optimizing power grid database query statements based on a large model according to claim 1, characterized in that, Based on the query statements and corresponding operation logs in the power grid database to be optimized, and in conjunction with the optimization requirements, several abnormal query statements are selected, specifically including: Based on the execution logs of each query statement in the power grid database, multiple query statements to be identified are selected based on the statement execution time, and entity recognition is performed on the multiple query statements to be identified to obtain the data entity of each query statement to be identified. Based on a pre-defined abnormal entity association knowledge graph, and combined with the operation log of each query statement, the data entities of each query statement to be identified are identified, and multiple abnormal query statements are determined based on the identification results; wherein, the abnormal entity association knowledge graph is obtained by performing association analysis on historical abnormal operation logs and all data entities in the power grid database.

3. The method for optimizing power grid database query statements based on a large model according to claim 1, characterized in that, Based on a preset first major model, and combined with the execution log of each abnormal query statement, a corresponding exception type is assigned to each abnormal query statement. Then, based on the execution log and exception type of each abnormal query statement, the abnormal operations within each abnormal query statement are identified, specifically including: Each abnormal query statement is parsed into a corresponding abstract syntax tree. Based on the first large model and combined with the execution log of each abnormal query statement, the abstract syntax tree of each abnormal query statement is identified, and a corresponding abnormal type is assigned to each abnormal query statement. Based on the first model, according to the execution log and exception type of each exception query statement, the multiple query operations corresponding to the abstract syntax tree of each exception query statement are identified to obtain the exception operations in each exception query statement.

4. The method for optimizing power grid database query statements based on a large model according to claim 1, characterized in that, Based on the first large model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements, a corresponding optimized query statement is generated for each abnormal query statement, specifically including: Based on the first major model and combined with the optimization requirements, the abnormal operation of each abnormal query statement is optimized, and multiple first query statements are generated for each abnormal query statement. Based on the cost estimator, determine the execution cost of each first query statement for each abnormal query statement; Based on the database table structure and preset optimization semantic equivalence rules, the semantically equivalent query statement with the lowest execution cost among the multiple first query statements corresponding to each abnormal query statement is selected as the corresponding optimized query statement.

5. The method for optimizing power grid database query statements based on a large model according to claim 1, characterized in that, Also includes: Based on the first large model, conflict analysis is performed on several unvalidated optimized query statements. Based on the conflict analysis results, each unvalidated optimized query statement is iteratively optimized. During the iteration process, the optimized query statement is regenerated and simultaneously loaded and validated on the backup of the power grid database. After validation, the validated optimized query statement and the corresponding abnormal query statement are replaced and the validated optimized query statement is removed until all optimized query statements are validated.

6. A device for optimizing query statements in a power grid database based on a large model, characterized in that, It includes an abnormal statement filtering module, an abnormal operation identification module, an optimized query generation module, and an optimized query verification module; The abnormal statement filtering module is used to filter out multiple abnormal query statements based on each query statement and corresponding operation log in the power grid database to be optimized, combined with optimization requirements. The abnormal operation identification module is used to assign a corresponding abnormal type to each abnormal query statement based on a preset first model and the execution log of each abnormal query statement, and to identify the abnormal operation in each abnormal query statement according to the execution log and abnormal type of each abnormal query statement. The optimized query generation module is used to generate corresponding optimized query statements for each abnormal query statement based on the first large model, according to the abnormal operation of each abnormal query statement, combined with the database table structure of the power grid database and the optimization requirements. The optimized query verification module is used to simultaneously load and verify all optimized query statements on the backup of the power grid database, and replace the verified optimized query statements with the corresponding abnormal query statements in the power grid database to complete the optimization of the query statements in the power grid database.

7. The power grid database query statement optimization device based on a large model according to claim 6, characterized in that, The abnormal statement filtering module includes a statement filtering and identification unit and an abnormal statement identification unit; The statement filtering and identification unit is used to filter out multiple query statements to be identified based on the execution time of each query statement in the power grid database, and to perform entity identification on the multiple query statements to be identified to obtain the data entity of each query statement to be identified. The abnormal statement identification unit is used to identify the data entities of each query statement based on a preset abnormal entity association knowledge graph and the running log of each query statement, and to determine multiple abnormal query statements based on the identification results; wherein, the abnormal entity association knowledge graph is obtained by association analysis of historical abnormal running logs and all data entities in the power grid database.

8. The power grid database query statement optimization device based on a large model according to claim 6, characterized in that, The abnormal operation identification module includes an abnormal type identification unit and an abnormal operation identification unit; The exception type identification unit is used to parse each exception query statement into a corresponding abstract syntax tree, and based on the first large model and combined with the running log of each exception query statement, identify the abstract syntax tree of each exception query statement and assign a corresponding exception type to each exception query statement. The abnormal operation identification unit is used to identify multiple query operations corresponding to the abstract syntax tree of each abnormal query statement based on the first large model, according to the running log and abnormal type of each abnormal query statement, so as to obtain the abnormal operation in each abnormal query statement.

9. The power grid database query statement optimization device based on a large model according to claim 6, characterized in that, The optimized query generation module includes an optimized statement generation unit, an execution cost determination unit, and an optimized statement determination unit; The optimized statement generation unit is used to optimize the abnormal operation of each abnormal query statement based on the first large model and in combination with the optimization requirements, and generate multiple first query statements for each abnormal query statement. The execution cost determination unit is used to determine the execution cost of each first query statement of each abnormal query statement based on the cost estimator. The optimized query statement determination unit is used to determine the semantically equivalent and least costly first query statement among multiple first query statements corresponding to each abnormal query statement, based on the database table structure of the power grid database and preset optimization semantic equivalence rules.

10. The power grid database query statement optimization device based on a large model according to claim 6, characterized in that, It also includes a query optimization iteration module; The query optimization iteration module is used to perform conflict analysis on several unverified optimized query statements based on the first large model, and to iteratively optimize each unverified optimized query statement according to the conflict analysis results. During the iteration process, the optimized query statement is regenerated and simultaneously loaded and verified on the backup of the power grid database. After verification, the verified optimized query statement and the corresponding abnormal query statement are replaced and the verified optimized query statement is removed until all optimized query statements are verified.