Dynamic query optimization method and system based on user SQL (Structured Query Language) statement analysis in database

Through in-depth analysis of user SQL statements and dynamic optimization strategy generation, the problem that traditional database query optimizers cannot adapt to changes in user behavior is solved, efficient query execution and resource management is achieved, and database performance and response speed are improved.

CN120407610APending Publication Date: 2025-08-01SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD

Patent Information

Application Number
CN202510528319.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-25
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

Traditional database query optimizers rely on static optimization methods and cannot adapt to changes in user query behavior in real time, ignore the structure and pattern characteristics of user SQL statements, resulting in insufficient performance in complex queries and high concurrency environments.

Method used

By conducting in-depth analysis of user SQL statements, an abstract syntax tree is generated, syntax and behavioral characteristics are extracted, and optimization strategies are dynamically generated, including index recommendation, connection order adjustment and execution plan adjustment, and real-time optimization of querying in combination with database status.

Benefits of technology

Significantly reduce query execution time, improve database response speed, allocate resources reasonably, avoid resource waste, ensure optimal performance under different loads, and improve user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407610A_ABST
    Figure CN120407610A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of relational databases, in particular to a dynamic query optimization method and system based on user SQL statement analysis in a database, and the method comprises the steps: receiving an SQL statement submitted by a user, carrying out the grammar analysis of the SQL statement, and carrying out the query of the SQL statement based on the grammar features and query historical data according to the behavior features and the database operation state; the optimization strategy is applied to the query execution plan, an efficient query execution path is generated, and query is executed; the method has the beneficial effects that the query execution plan can be dynamically generated or adjusted through deep analysis of the SQL statement of the user, and complex query operation can be executed in an optimal mode. For high-complexity SQL (Structured Query Language) such as multi-table connection and nested query, the query execution time can be remarkably shortened, and the overall response speed of a database is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of relational databases, and particularly to a dynamic query optimization method and system based on user SQL statement analysis in a database. Background Art

[0002] With the rapid development of information technology and the advent of the big data era, database systems play a crucial role in data storage, management, and query. Especially in relational databases, users perform operations such as inserting, updating, deleting, and querying data through SQL (Structured Query Language) statements.

[0003] However, with the expansion of data scale and the increase in query complexity, the efficient execution of SQL statements has become a key issue in database performance optimization.

[0004] Moreover, traditional database query optimizers rely on static optimization methods, usually generating query execution plans according to predefined rules or fixed cost models. However, this method has the following deficiencies:

[0005] 1) Fixedness: The optimization strategy is usually bound to the initial configuration of the database and cannot adapt to changes in user query behavior in real time.

[0006] 2) Lack of dynamics: For real-time user requests or complex queries (such as multi-table join queries), existing optimizers are difficult to quickly adjust to adapt to the dynamic environment.

[0007] 3) Ignoring user behavior characteristics: Traditional optimization methods mainly rely on statistical information, such as table sizes, index conditions, etc., while ignoring the structural, frequency, and pattern characteristics of user SQL statements. Summary of the Invention

[0008] The purpose of the present invention is to provide a dynamic query optimization method and system based on user SQL statement analysis in a database to solve the problems raised in the above background art.

[0009] To achieve the above purpose, the present invention provides the following technical solution: A dynamic query optimization method based on user SQL statement analysis in a database, including the following steps:

[0010] Step 1: Receive the SQL statement submitted by the user;

[0011] Step 2: Perform syntax parsing on the SQL statement to generate an abstract syntax tree, and extract syntax features from the abstract syntax tree, including query type, table name, number of conditions, and condition logic;

[0012] Step 3: Analyze the behavior characteristics of the query based on the syntactic features and query history data. The behavior characteristics include static features and dynamic features. The static features are the syntactic structure features of the SQL statement, and the dynamic features are the behavior characteristics during query execution;

[0013] Step 4: Generate optimization strategies according to the behavior characteristics and the database running state. The optimization strategies include index recommendation, connection order adjustment, and execution plan adjustment;

[0014] Step 5: Apply the optimization strategies to the query execution plan to generate an efficient query execution path and execute the query.

[0015] Preferably, the generation of the optimization strategies in Step 4 specifically includes:

[0016] Match the behavior characteristics with the predefined query pattern library to identify the query pattern; generate preliminary optimization suggestions according to the matching results. If it is identified as a high-frequency query and involves fields without indexes, generate index recommendations; if there are multi-table joins in the query conditions, select nested loop or hash join as the preliminary optimization suggestion based on the size of the tables; combine the current state of the database, such as the load situation, and dynamically adjust the preliminary optimization suggestions to generate the final optimization strategy.

[0017] Preferably, it further includes the following steps:

[0018] During the query execution process, monitor the query execution results, record the query execution time and the system resource occupancy; evaluate the effect of the optimization strategy according to the monitoring data; if the evaluation result shows that the optimization strategy does not meet the expected effect, re-analyze the query behavior characteristics, adjust the optimization strategy and apply it to the query execution plan again.

[0019] Preferably, the application of the optimization strategy to the query execution plan in Step 5 specifically includes:

[0020] Determine to use sequential scan or index scan according to the selection of the scan strategy in the optimization strategy; select connection algorithms such as nested loop and hash join based on the data distribution according to the selection of the connection algorithm in the optimization strategy; if the data volume is large, perform targeted partition optimization on the large-scale data according to the data partition suggestion in the optimization strategy to generate an efficient query execution path.

[0021] Preferably, when analyzing the behavior characteristics of the query in Step 3, the dynamic features are obtained through the following methods:

[0022] Statistical query execution time during historical execution; statistical query access frequency during historical execution; combine system resource monitoring data to obtain the system resource occupancy during query execution, including the usage rates of resources such as CPU and memory; obtain the user satisfaction index as part of the dynamic features according to user feedback or preset metrics.

[0023] A system for a dynamic query optimization method based on user SQL statement analysis in a database, comprising:

[0024] An SQL parsing module, configured to receive an SQL statement submitted by a user, perform syntax parsing on the SQL statement to generate an abstract syntax tree, and extract syntax features from the abstract syntax tree, including query type, table name, number of conditions, and condition logic;

[0025] A feature analysis module, configured to analyze the behavior features of a query based on the syntax features extracted by the SQL parsing module and query historical data. The behavior features include static features and dynamic features. The static features are the syntax structure features of the SQL statement, and the dynamic features are the behavior features during query execution;

[0026] An optimization strategy generation module, configured to generate an optimization strategy according to the behavior features obtained by the feature analysis module and the database running state. The optimization strategy includes index recommendation, connection order adjustment, and execution plan adjustment;

[0027] An execution plan adjustment module, configured to apply the optimization strategy generated by the optimization strategy generation module to the query execution plan to generate an efficient query execution path and execute the query;

[0028] A feedback mechanism module, configured to monitor the query execution result during query execution, record the query execution time and the system resource occupancy, evaluate the effect of the optimization strategy according to the monitoring data. If the evaluation result indicates that the optimization strategy fails to achieve the expected effect, it feeds back to the feature analysis module to re-analyze the query behavior features, adjust the optimization strategy and apply it to the query execution plan again.

[0029] Preferably, the optimization strategy generation module generating the optimization strategy specifically includes:

[0030] A query pattern matching unit, configured to match the behavior features with a predefined query pattern library to identify a query pattern;

[0031] A preliminary optimization suggestion generation unit, configured to generate a preliminary optimization suggestion according to the matching result. If it is identified as a high-frequency query and involves a field without an established index, an index recommendation is generated; if there are multi-table joins in the query conditions, nested loop or hash join is selected as a preliminary optimization suggestion according to the size of the tables;

[0032] A final optimization strategy generation unit, configured to dynamically adjust the preliminary optimization suggestion in combination with the current state of the database, such as the load condition, to generate a final optimization strategy.

[0033] Preferably, the execution plan adjustment module applying the optimization strategy to the query execution plan specifically includes:

[0034] A scan strategy selection unit for determining to adopt sequential scan or index scan according to the scan strategy selection in the optimization strategy;

[0035] A join algorithm selection unit for selecting a nested loop or hash join algorithm based on data distribution according to the join algorithm selection in the optimization strategy;

[0036] A data partitioning optimization unit for, if the data volume is large, performing targeted partitioning optimization on large-scale data according to the data partitioning suggestions in the optimization strategy to generate an efficient query execution path.

[0037] Preferably, when the feature analysis module analyzes the behavior characteristics of a query, the dynamic features are obtained in the following manner:

[0038] Statistical query execution time during historical execution;

[0039] Statistical query access frequency during historical execution;

[0040] Combined with system resource monitoring data, obtain the occupancy of system resources during query execution, including the usage rates of CPU and memory resources;

[0041] According to user feedback or preset metrics, obtain user satisfaction metrics as part of the dynamic features.

[0042] Preferably, it further includes a core algorithm module, and the core algorithm module includes:

[0043] An SQL statement feature extraction algorithm unit for performing syntax parsing on the input SQL statement, generating an abstract syntax tree, extracting static features, and combining query historical data to statistically analyze dynamic features and output an SQL feature vector;

[0044] A dynamic optimization strategy generation algorithm unit for matching the input SQL feature vector with a predefined query pattern library, generating preliminary optimization suggestions according to the matching results, and dynamically adjusting the optimization strategy in combination with the database state and outputting it.

[0045] Compared with the prior art, the beneficial effects of the present invention are:

[0046] The dynamic query optimization method and system based on user SQL statement analysis in the database proposed by the present invention can dynamically generate or adjust a query execution plan through in-depth analysis of the user SQL statement, and execute complex query operations in an optimized manner. For high-complexity SQL such as multi-table joins and nested queries, it can significantly reduce the query execution time and improve the overall response speed of the database.

[0047] Real-time analysis based on SQL statements can effectively identify performance bottlenecks such as redundant calculations and repeated index accesses in queries, and then adjust the execution strategy to reduce unnecessary resource consumption. Especially in high-concurrency access and large-scale data processing environments, the present invention can help the system reasonably allocate computing and storage resources and avoid resource waste.

[0048] Dynamically adjust the query optimization strategy according to the real-time query load and database status to ensure optimal performance under different system loads. This adaptive mechanism avoids the static limitations of traditional optimization methods and can automatically adjust the optimization strategy in changing application scenarios.

[0049] Dynamically optimize according to the user's query habits and frequent query patterns, which can effectively reduce the query response time and thus improve the overall user experience of database applications. In a high-concurrency environment, the system can quickly respond to user requests and reduce query latency.

[0050] By continuously tracking the changes in the user's SQL statements and the database status, the present invention can achieve long-term performance optimization. Especially for database systems with frequent changes and diverse query requirements, the present invention can ensure that the database system always maintains high query performance during long-term operation by continuously optimizing the execution plan. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 It is a block diagram of the system of the present invention;

[0052] Figure 2 It is a flowchart of the method of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0053] In order to clearly and completely describe the objectives, technical solutions of the present invention and make the advantages more clear, the following further details the embodiments of the present invention in conjunction with the accompanying drawings. It should be understood that the specific embodiments described herein are part of the embodiments of the present invention, rather than all of the embodiments, and are only used to explain the embodiments of the present invention and are not used to limit the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present invention.

[0054] Please refer to Figures 1 to 2 , the present invention provides a technical solution: a dynamic query optimization method and system based on user SQL statement analysis in a database, which includes the following core components:

[0055] SQL parsing module: Parse the user's SQL statement and extract its syntactic and semantic features.

[0056] Feature analysis module: Analyze the features and behaviors of the SQL statement and generate a feature vector for optimization.

[0057] Optimization Strategy Generation Module: Generates dynamic optimization strategies by combining user SQL characteristics and system status, such as adjusting indexes, execution plans, etc.

[0058] Execution Plan Adjustment Module: Applies the optimization strategy to the query execution plan to generate an efficient query execution path.

[0059] Feedback Mechanism Module: Monitors the query execution results and dynamically adjusts the optimization strategy according to the execution performance.

[0060] The main modules are described in detail as follows:

[0061] 1) SQL Parsing Module

[0062] Function: Parses the SQL statement submitted by the user into an Abstract Syntax Tree (AST) and extracts the syntax features therein (such as query type, conditional structure).

[0063] Input: User SQL statement

[0064] Output: SQL Abstract Syntax Tree and feature vector

[0065] Example: For the SQL statement:

[0066] SELECT name, age FROM users WHERE age > 30 AND city = 'NewYork';

[0067] Parsing result:

[0068] Query type: SELECT

[0069] Table name: users

[0070] Number of conditions: 2

[0071] Condition logic: AND

[0072] Function: Provides input for feature analysis.

[0073] 2) Feature Analysis Module

[0074] Function: Extracts the behavioral features of the query based on the SQL parsing result, including dynamic indicators such as query frequency and average execution time.

[0075] Static features: Syntax structure features of the SQL statement, such as table name, field name, connection method, etc.

[0076] Dynamic features: Behavioral features during query execution, such as access frequency, response time, etc.

[0077] 3) Optimization Strategy Generation Module

[0078] Function: Generate an optimization strategy suitable for the current query based on the characteristics of SQL statements and the running status of the database.

[0079] Key steps:

[0080] Query pattern matching: Identify high-frequency query or complex query patterns.

[0081] Optimization suggestion generation: Include strategies such as index recommendation and join order adjustment.

[0082] Execution plan adjustment: Dynamically generate the optimal execution plan in combination with the database status.

[0083] Example:

[0084] If it is found that a high-frequency query involves a field without an established index, then generate an index recommendation.

[0085] If there are multi-table joins in the query conditions, choose nested loop or hash join based on the size of the tables.

[0086] 4) Execution plan adjustment module

[0087] Function: Dynamically adjust the execution plan of the query according to the optimization strategy.

[0088] Optimization direction:

[0089] Scan strategy: Select sequential scan or index scan.

[0090] Join algorithm: Based on data distribution, choose nested loop, hash join, etc.

[0091] Data partitioning: In large-scale data scenarios, perform targeted partitioning optimization.

[0092] 5) Feedback mechanism module Function: Monitor the query execution effect and continuously improve the optimization strategy through feedback data. Feedback content:

[0093] Query execution time

[0094] System resource occupancy (CPU, memory, etc.)

[0095] User satisfaction index Role: Achieve closed-loop optimization and continuously improve the performance of the system during long-term operation.

[0096] 4.4 Core algorithms

[0097] 1) SQL statement feature extraction algorithm

[0098] Input: SQL statement

[0099] Output: SQL feature vector

[0100] Steps:

[0101] Parse the SQL statement and generate an abstract syntax tree (AST).

[0102] Extract static features (such as query type, number of conditions, table name, etc.).

[0103] Combined with query history data, dynamic features (such as execution time and frequency) are counted.

[0104] 2) Dynamic optimization strategy generation algorithm

[0105] Input: SQL feature vector, database operation status

[0106] Output: Optimization strategy

[0107] step:

[0108] Matches SQL feature vectors with a library of predefined query patterns.

[0109] Generate preliminary optimization suggestions (such as index recommendations) based on the matching results.

[0110] Dynamically adjust the optimization strategy based on the database status (such as current load).

[0111] The flowchart of the entire execution process is as follows Figure 2 As shown:

[0112] 1) The user submits an SQL statement.

[0113] 2) The SQL parsing module extracts grammatical and semantic features.

[0114] 3) The feature analysis module analyzes query behavior features.

[0115] 4) The optimization strategy generation module generates execution plan optimization suggestions.

[0116] 5) The execution plan adjustment module applies the optimization strategy and executes the query.

[0117] 6) The feedback mechanism records the execution results and updates the optimization strategy.

[0118] The implementation details are as follows:

[0119] 1) Environment Configuration

[0120] Database: PostgreSQL

[0121] System environment: Distributed environment that supports high concurrent processing

[0122] 2) Test scenario

[0123] Dataset: E-commerce transaction data containing hundreds of millions of records

[0124] Query types: include simple queries, multi-table joins, and nested queries

[0125] 3) Performance verification

[0126] Compare the differences between traditional optimization and the method of the present invention in terms of execution time and resource utilization.

[0127] The expected advantages are as follows:

[0128] 1) Strong dynamic adaptability: Analyze user behavior in real time and generate targeted optimization strategies.

[0129] 2) Significant performance improvement: Reduce query response time and improve resource utilization.

[0130] 3) Long-term stable optimization: Achieve self-improvement through a feedback mechanism.

[0131] To more intuitively illustrate the technical solution of the present invention, the working processes and implementation methods of each module are described in detail below through specific examples and algorithm expansions.

[0132] 1) Example of SQL statement feature extraction

[0133] Suppose the SQL statement submitted by the user is as follows:

[0134] SELECT customer_id, COUNT(order_id) AS order_count

[0135] FROM orders

[0136] WHERE order_date > '2024-01-01' AND status = 'completed'

[0137] GROUP BY customer_id

[0138] ORDER BY order_count DESC;

[0139] Step 1: Syntax parsing

[0140] The SQL parsing module converts the above statement into an abstract syntax tree (AST). The parsing results include the following main elements:

[0141] Query type: SELECT

[0142] Query fields: customer_id, order_id

[0143] Table name: orders

[0144] Condition: order_date > '2024-01-01' and status = 'completed'

[0145] Aggregation operation: COUNT(order_id)

[0146] Grouping field: customer_id

[0147] Sorting field: order_count

[0148] Step 2: Feature extraction

[0149] The feature analysis module extracts the following static and dynamic features based on the AST:

[0150] Static features:

[0151] Query complexity: Medium (including conditional filtering, aggregation, grouping, and sorting). Data access pattern: High possibility of full table scan

[0152] Dynamic features:

[0153] Historical query frequency: 50 times per day

[0154] Average response time: 250ms

[0155] Function: Generate feature vectors to provide a basis for subsequent optimization strategies.

[0156] 2) Generation and extension of dynamic optimization strategies

[0157] Based on the above SQL feature vectors, the optimization strategy generation module performs the following processing: Query pattern matching. Based on the query feature vectors, it is identified that this statement belongs to the high-frequency aggregation query pattern. Match the predefined optimization strategies:

[0158] Check if there is an index in the orders table to support the order_date field.

[0159] If there is no index, generate an index optimization suggestion:

[0160] CREATE INDEX idx_order_date ON orders(order_date);

[0161] Execution plan optimization

[0162] Current database state: High-concurrency environment, CPU load 80%.

[0163] According to the load situation, it is recommended to optimize to hash aggregation operation to reduce memory occupation.

[0164] Generate strategy output:

[0165] Optimization Suggestion 1: Create an index.

[0166] Optimization Suggestion 2: Adjust the aggregation operation method.

[0167] 3) Example of Execution Plan Adjustment

[0168] After the optimization strategy is applied by the execution plan adjustment module, an example of the query execution path is as follows:

[0169] a) Use the index idx_order_date to perform conditional filtering on the orders table to avoid full table scans.

[0170] b) Adopt a parallel processing method to perform the aggregation operation and utilize multi-core resources.

[0171] c) Give priority to using the in-memory sorting algorithm in the sorting stage to reduce disk I / O.

[0172] The application scenarios are described as follows:

[0173] 1) E-commerce platform

[0174] Background: The platform needs to process a large number of user order queries, and some of the queries involve complex aggregation and multi-table join operations.

[0175] Application effect: Through the dynamic optimization method of the present invention, the response time of high-frequency queries is shortened, and the database load is reduced.

[0176] 2) Financial real-time trading system

[0177] Background: Financial institutions need to process complex queries of real-time trading data in a high-concurrency environment.

[0178] Application effect: The optimized execution plan reduces resource contention and ensures the high availability and low latency of the system.

[0179] 3) Cloud database environment

[0180] Background: Due to its dynamic scalability, cloud databases need to maintain high-performance queries in an environment where resources change frequently.

[0181] Application effect: Combining the feedback mechanism of the present invention, dynamically adjust the index and query plan to adapt to resource fluctuations.

[0182] Although the embodiments of the present invention have been shown and described, those of ordinary skill in the art can understand that various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principle and spirit of the present invention. The scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A dynamic query optimization method based on user SQL statement analysis in a database, characterized in that: It includes the following steps: Step 1: Receive the SQL statement submitted by the user; Step 2: Parse the syntax of the SQL statement to generate an abstract syntax tree, and extract syntax features from the abstract syntax tree, including query type, table name, number of conditions, and condition logic; Step 3: Analyze the behavior features of the query based on the syntax features and query historical data. The behavior features include static features and dynamic features. The static features are the syntax structure features of the SQL statement, and the dynamic features are the behavior features during query execution; Step 4: Generate an optimization strategy according to the behavior features and the database running status. The optimization strategy includes index recommendation, connection order adjustment, and execution plan adjustment; Step 5: Apply the optimization strategy to the query execution plan to generate an efficient query execution path and execute the query.

2. The dynamic query optimization method based on user SQL statement analysis in a database according to claim 1, characterized in that: The specific generation of the optimization strategy in Step 4 includes: Match the behavior features with a predefined query pattern library to identify the query pattern; generate preliminary optimization suggestions according to the matching result. If it is identified as a high-frequency query and involves fields without an established index, generate an index recommendation; if there are multi-table joins in the query conditions, select nested loop or hash join as a preliminary optimization suggestion based on the size of the tables; combine the current state of the database, such as the load situation, and dynamically adjust the preliminary optimization suggestions to generate the final optimization strategy.

3. The dynamic query optimization method based on user SQL statement analysis in a database according to claim 2, characterized in that: It also includes the following steps: During the query execution process, monitor the query execution result, record the query execution time and the system resource occupancy; evaluate the effect of the optimization strategy according to the monitoring data; if the evaluation result shows that the optimization strategy does not meet the expected effect, re-analyze the query behavior features, adjust the optimization strategy and apply it to the query execution plan again.

4. A dynamic query optimization method based on user SQL statement analysis in a database according to claim 3, characterized in that: The specific application of the optimization strategy to the query execution plan in Step 5 includes: Determine to use sequential scan or index scan according to the scan strategy selection in the optimization strategy; select connection algorithms such as nested loop and hash join based on the data distribution according to the connection algorithm selection in the optimization strategy; if the data volume is large, perform targeted partition optimization on the large-scale data according to the data partition suggestion in the optimization strategy to generate an efficient query execution path.

5. A dynamic query optimization method based on user SQL statement analysis in a database according to claim 4, characterized in that: When analyzing the behavior features of the query in Step 3, the dynamic features are obtained through the following methods: Statistical query execution time during historical execution; statistical query access frequency during historical execution; combine system resource monitoring data to obtain the system resource occupancy during query execution, including the usage rate of resources such as CPU and memory; obtain the user satisfaction index as part of the dynamic features according to user feedback or preset metrics.

6. A system for a dynamic query optimization method based on user SQL statement analysis in the database according to claim 5, characterized in that: It includes: An SQL parsing module for receiving the SQL statement submitted by the user, parsing the syntax of the SQL statement to generate an abstract syntax tree, and extracting syntax features from the abstract syntax tree, including query type, table name, number of conditions, and condition logic; A feature analysis module for analyzing the behavior features of the query based on the syntax features extracted by the SQL parsing module and the query historical data. The behavior features include static features and dynamic features. The static features are the syntax structure features of the SQL statement, and the dynamic features are the behavior features during query execution; An optimization strategy generation module, which is used to generate optimization strategies according to the behavior characteristics obtained by the feature analysis module and the database running status. The optimization strategies include index recommendations, join order adjustments, and execution plan adjustments; An execution plan adjustment module, which is used to apply the optimization strategies generated by the optimization strategy generation module to the query execution plan, generate an efficient query execution path, and execute the query; A feedback mechanism module, which is used to monitor the query execution result during the query execution process, record the query execution time and the system resource occupancy, evaluate the effect of the optimization strategy according to the monitoring data. If the evaluation result shows that the optimization strategy does not meet the expected effect, it will feedback to the feature analysis module to re-analyze the query behavior characteristics, adjust the optimization strategy and apply it to the query execution plan again.

7. A system according to claim 6, wherein: The specific process of the optimization strategy generation module generating optimization strategies includes: A query pattern matching unit, which is used to match the behavior characteristics with a predefined query pattern library to identify query patterns; A preliminary optimization suggestion generation unit, which is used to generate preliminary optimization suggestions according to the matching result. If it is identified as a high-frequency query and involves fields without indexes, it will generate index recommendations. If there are multi-table joins in the query conditions, it will select nested loop or hash join as a preliminary optimization suggestion based on the size of the tables; A final optimization strategy generation unit, which is used to dynamically adjust the preliminary optimization suggestions in combination with the current state of the database, such as the load situation, to generate final optimization strategies.

8. A system according to claim 7, wherein: The specific process of the execution plan adjustment module applying the optimization strategy to the query execution plan includes: A scan strategy selection unit, which is used to determine whether to use sequential scan or index scan according to the scan strategy selection in the optimization strategy; A join algorithm selection unit, which is used to select nested loop or hash join algorithms based on the data distribution according to the join algorithm selection in the optimization strategy; A data partitioning optimization unit, which is used to perform targeted partitioning optimization on large-scale data according to the data partitioning suggestions in the optimization strategy if the data volume is large, so as to generate an efficient query execution path.

9. A system according to claim 8, wherein: When the feature analysis module analyzes the behavior characteristics of the query, the dynamic characteristics are obtained through the following methods: Statistical query execution time during historical execution; Statistical query access frequency during historical execution; Combined with system resource monitoring data, obtain the system resource occupancy during query execution, including the usage rates of CPU and memory resources; According to user feedback or preset metrics, obtain user satisfaction metrics as part of the dynamic characteristics.

10. A system according to claim 9, wherein: It also includes a core algorithm module, and the core algorithm module includes: An SQL statement feature extraction algorithm unit, which is used to perform syntax parsing on the input SQL statement, generate an abstract syntax tree, extract static features, and combine query historical data to count dynamic features, and output an SQL feature vector; A dynamic optimization strategy generation algorithm unit, which is used to match the input SQL feature vector with a predefined query pattern library, generate preliminary optimization suggestions according to the matching result, and dynamically adjust the optimization strategy in combination with the database state and output.

Citation Information

Patent Citations

  • Query optimization method and device for relational data

    CN115617842A

  • Database SQL query optimization method, terminal and storage medium

    CN118410068A

  • Self-adaptive query optimizer of time sequence database

    CN119179708A

  • Query method and system for generating SQL statement based on natural language

    CN119377241A

Cited By

  • Data query method and device, electronic equipment and computer readable storage medium

    CN121350312A