Database index optimization method and system, database, electronic equipment and medium
By obtaining query logs from the Apache Doris database and using the pre-trained target prediction model to dynamically optimize the index structure, the problem of query performance degradation caused by static configuration of the index strategy is solved, and dynamic response to data access patterns and resource optimization are achieved, significantly improving improve system efficiency.
Patent Information
- Application Number
- CN202410848762.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-10-01
AI Technical Summary
The existing Apache Doris database's indexing strategy is statically configured, making it difficult to respond to dynamic changes in data access patterns in real time, resulting in reduced query performance and unreasonable resource allocation, affecting system operating efficiency.
By obtaining query logs from the database, predict the query execution time, and dynamically optimize the index structure based on the prediction results, generate and execute SQL statements to optimize the index, use pre-trained target prediction models and regular expressions to process historical query data, and optimize the index structure .
Significantly improves database query performance, reduces query response time, improves the overall operating efficiency of the system, and adapts to changes in data access patterns.
Smart Images

Figure CN118733698A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a method, system, database, electronic device and medium for optimizing a database index. Background Art
[0002] Currently, Apache Doris database, as a high-performance analytical database system, is widely used in scenarios that require fast data analysis, especially in the automotive manufacturing industry, where massive production data, supply chain management information, and sales records place higher demands on data processing speed and flexibility. However, the index strategy of Doris database is mainly static configuration, which makes it difficult to respond to dynamic changes in data access patterns in real time. With the development of business, the surge in data volume, and the diversification of query requirements, a fixed index structure may lead to a decline in query performance and unreasonable resource allocation, affecting the overall system operation efficiency.
[0003] Therefore, a new database index optimization method is urgently needed. Summary of the invention
[0004] In view of the above problems, an embodiment of the present application provides a nighttime intelligent farming monitoring system based on semantic coding and decoding, so as to overcome the above problems or at least partially solve the above problems.
[0005] In a first aspect of an embodiment of the present application, a method for optimizing a database index is provided, the method comprising:
[0006] Obtain a first query log from a database;
[0007] Determining a first predicted query text from the first query text in the first query log;
[0008] Inputting the first prediction query text into a pre-trained target prediction model to predict a first prediction query execution time corresponding to the first prediction query text;
[0009] The index of the database is optimized according to the execution time of the first predicted query.
[0010] Optionally, optimizing the index of the database according to the first predicted query execution time includes:
[0011] Determine whether the execution time of the first prediction query is greater than or equal to a preset time threshold;
[0012] When the execution time of the first prediction query is greater than or equal to the time threshold, extracting text information in the first prediction query text corresponding to the execution time of the first prediction query;
[0013] Based on the text information, an SQL statement for optimizing the index of the database is generated and executed to optimize the index of the database.
[0014] Optionally, generating and executing a SQL statement for optimizing the index of the database according to the text information to optimize the index of the database includes:
[0015] Determining a condition field of the first predicted query text according to the text information;
[0016] Generate an index name according to the condition field;
[0017] Generate an SQL statement for optimizing the index of the database according to the condition field and the index name;
[0018] Submit the SQL statement to the database so that the SQL statement is executed by the database to optimize the index of the database.
[0019] Optionally, the database is a Doris database, and before inputting the first prediction query text into a pre-trained target prediction model, the method further includes:
[0020] Obtaining from the Doris database the execution time, execution user, executed SQL statement, query type, and query frequency of multiple historical queries used for querying in the historical query log;
[0021] Preprocessing each of the executing users, the executed SQL statements, the query type and the query frequency to obtain a plurality of historical query texts;
[0022] The plurality of historical query texts and the plurality of historical query execution durations are matched one by one using a preset regular expression to obtain a plurality of historical query text pairs.
[0023] Optionally, the method further comprises:
[0024] Inputting the query text in any of the historical query text pairs as a feature variable into a preset prediction model to obtain a target predicted query execution time corresponding to the feature variable;
[0025] The mean square error between the target prediction query execution time and the historical query execution time corresponding to the feature variable is calculated, and the parameters of the prediction model are optimized according to the mean square error to obtain the target prediction model.
[0026] Optionally, after optimizing the index of the database, the method further includes:
[0027] Acquire a second query log from the database, where the second query log is a query log obtained after querying through the optimized index;
[0028] Determine, from the second query log, a second query text and a second query execution time corresponding to the second query text;
[0029] The target prediction model is updated by using the second query text and the second query execution duration as training data for updating the target prediction model.
[0030] In a second aspect of an embodiment of the present application, a database index optimization system is provided, the system comprising:
[0031] An acquisition module, used for acquiring a first query log from a database;
[0032] A determination module, configured to determine a first predicted query text from the first query text in the first query log;
[0033] A prediction module, configured to input the first prediction query text into a pre-trained target prediction model, and predict a first prediction query execution time corresponding to the first prediction query text;
[0034] An optimization module is used to optimize the index of the database according to the execution time of the first predicted query.
[0035] Optionally, the index of the database is optimized according to the execution time of the first predicted query, and the optimization module includes:
[0036] A judgment submodule, used to judge whether the execution time of the first prediction query is greater than or equal to a preset time threshold;
[0037] an extraction submodule, configured to extract text information in a first prediction query text corresponding to the execution time of the first prediction query when the execution time of the first prediction query is greater than or equal to the preset time threshold;
[0038] The generating submodule is used to generate and execute an SQL statement for optimizing the index of the database according to the text information, so as to optimize the index of the database.
[0039] Optionally, the step of generating and executing an SQL statement for optimizing the index of the database according to the text information to optimize the index of the database comprises:
[0040] A determination subunit, configured to determine a condition field of the first predicted query text according to the text information;
[0041] A first generating subunit, used for generating an index name according to the condition field;
[0042] A second generating subunit, used to generate an SQL statement for optimizing the index of the database according to the condition field and the index name;
[0043] The optimization subunit is used to submit the SQL statement to the database so as to execute the SQL statement through the database and optimize the index of the database.
[0044] Optionally, the database is a Doris database, and before inputting the first prediction query text into a pre-trained target prediction model, the method further includes:
[0045] The first acquisition submodule is used to obtain the execution time, execution user, executed SQL statement, query type and query frequency of multiple historical queries used for query in the historical query log from the Doris database;
[0046] A preprocessing submodule, used for preprocessing each of the executing users, the executed SQL statements, the query type and the query frequency to obtain a plurality of historical query texts;
[0047] The pairing submodule is used to pair the plurality of historical query texts with the plurality of historical query execution durations one by one through a preset regular expression to obtain a plurality of historical query text pairs.
[0048] Optionally, the method further comprises:
[0049] An input submodule, used to input a historical query text in any of the historical query text pairs as a feature variable into a preset prediction model to obtain a target predicted query execution time corresponding to the feature variable;
[0050] The calculation submodule is used to calculate the mean square error between the target prediction query execution time and the historical query execution time corresponding to the feature variable, and optimize the parameters of the prediction model according to the mean square error to obtain the target prediction model.
[0051] Optionally, the method further comprises:
[0052] A second acquisition submodule is used to acquire a second query log from the database, where the second query log is a query log obtained after querying through the optimized index;
[0053] A determination submodule is used to determine the second query text and the second query execution time corresponding to the second query text from the second query log by using language;
[0054] An updating submodule is used to update the target prediction model by using the second query text and the second query execution time as training data for updating the target prediction model.
[0055] In a third aspect of an embodiment of the present application, a database is provided, wherein the database includes an index optimization system for a database as described in the second aspect of the present application, and / or an index optimization method for a database as described in the first aspect of the present application.
[0056] In a fourth aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the database index optimization method as described in the first aspect of the present application.
[0057] In a fifth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the method for optimizing the database index as described in the first aspect of the present application is implemented.
[0058] Beneficial effects of this application:
[0059] The present application provides a method for optimizing the index of a database, the method comprising: obtaining a first query log from a database; determining a first predicted query text from a first query text in the first query log; inputting the first predicted query text into a pre-trained target prediction model to predict a first predicted query execution time corresponding to the first predicted query text; and optimizing the index of the database according to the first predicted query execution time. The present application obtains a query log from a database, and predicts different query execution times based on different query texts in the query log through a pre-trained target prediction model, and dynamically optimizes the index of the database based on the predicted different query execution times. The present application significantly improves the query performance of the database by dynamically optimizing the index structure, thereby reducing the query response time. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0061] Figure 1 It is a schematic diagram of the steps of a method for optimizing a database index provided in an embodiment of the present application;
[0062] Figure 2It is a flowchart of a database index dynamic adjustment provided by an embodiment of the present application;
[0063] Figure 3 is a schematic diagram of a database index optimization system provided in an embodiment of the present application;
[0064] Figure 4 It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0065] The exemplary embodiments of the present application will be described in more detail below in conjunction with the accompanying drawings in the embodiments of the present application. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to enable the scope of the present application to be fully communicated to those skilled in the art.
[0066] At present, the existing Doris database index management mechanism lacks the ability to adapt to the dynamic changes in data access patterns, which is specifically manifested in:
[0067] 1. Static index structure: It cannot be automatically adjusted according to the actual query mode, resulting in inefficiency of some frequently accessed data paths.
[0068] 2. Inflexible resource allocation: Resource allocation is fixed and cannot be dynamically optimized according to query load, affecting the overall system response speed.
[0069] 3. Lack of intelligent prediction: Failure to use historical query data for machine learning analysis results in missed opportunities to optimize the index structure in advance.
[0070] Based on the above problems, the first aspect of the embodiment of the present application provides a method for optimizing the index of a database, such as Figure 1 As shown, the method includes:
[0071] Step S101, obtaining a first query log from a database;
[0072] Step S102, determining a first predicted query text from the first query text in the first query log;
[0073] Specifically, a first query log is obtained from a database, and a first predicted query text is determined from a first query text in the first query log.
[0074] Exemplarily, the first query text in the first query log may include the query execution time, the executing user, and the executed SQL statement, for example, "2024-05-22 10:15:23" | User A executed SELECT * FROM table WHERE condition".
[0075] Optionally, the first query text in the first query log may further include data access mode information, such as query type and query frequency. For example, the data access mode information is shown in the following Table 1:
[0076] Query Type Query frequency SELECT * 500 SELECT COUNT(*) 300 INSERT INTO 100
[0077] Table 1
[0078] Further, the first predicted query text is determined from the first query text, such as data type, minimum value, maximum value, number of unique values and number of NULL values, etc. It should be noted that the first predicted query text is obtained by preprocessing the first query text. For example, the first predicted query text is shown in Table 2 below:
[0079] Table name Column Name Data Types Minimum Maximum Number of unique values Number of NULL values table Column1 INT 0 100 50 10 table Column2 VARCHAR 500 20
[0080] Table 2
[0081] Step S103, inputting the first prediction query text into a pre-trained target prediction model to predict a first prediction query execution time corresponding to the first prediction query text;
[0082] In this step, the first prediction query text is used as input, and the target prediction model is used to predict the execution time of the first prediction query. Specifically, the target prediction model needs to be loaded first. It should be noted that the target prediction model is obtained by model training in advance based on the historical query logs in the database. Then, the prediction query text is converted into an input format acceptable to the target prediction model. In practical applications, the prediction query text can be converted into a feature vector, and the feature vector can be converted into a data frame or array format. The converted data is input into the target prediction model to obtain the first prediction query execution time corresponding to the first prediction query text.
[0083] Step S104: optimizing the index of the database according to the execution time of the first prediction query.
[0084] Specifically, in this step, the index of the database is optimized according to the predicted first predicted query execution time, and the following steps may be followed:
[0085] Analyze the execution time of the first predicted query and identify queries with longer execution time. Further, determine the index optimization strategy. In practical applications, the optimization strategy can be determined based on the query analysis, where the optimization strategy can be to create, modify or delete an index. Further, apply index optimization and apply these index optimization measures in the database to optimize the index in the database. Finally, verify the optimization effect. Run the query again and verify whether the query execution time is improved.
[0086] The present application obtains query logs from a database, and predicts different query execution times based on different query texts in the query logs through a pre-trained target prediction model, and dynamically optimizes the database index based on the predicted different query execution times. The present application significantly improves database query performance by dynamically optimizing the index structure, thereby reducing query response time.
[0087] In a preferred embodiment, the optimizing the index of the database according to the first predicted query execution time includes:
[0088] Determine whether the execution time of the first prediction query is greater than or equal to a preset time threshold;
[0089] When the execution time of the first prediction query is greater than or equal to the preset time threshold, extracting text information in the first prediction query text corresponding to the execution time of the first prediction query;
[0090] Based on the text information, an SQL statement for optimizing the index of the database is generated and executed to optimize the index of the database.
[0091] Specifically, in this embodiment, after obtaining the execution time of the first predicted query, first, it is determined whether the execution time of the first predicted query is greater than or equal to a preset time threshold. If the execution time of the first predicted query is greater than or equal to the preset time threshold, it means that the structure of the index executing the query is not optimal and needs to be optimized.
[0092] Furthermore, when the predicted execution time of the first query is greater than or equal to a preset time threshold, text information in the corresponding predicted query text is extracted.
[0093] Further, based on the extracted text information, an SQL statement for optimizing the database index is generated. The generated SQL statement is usually a statement for creating an index, such as "CREATE INDEX idx_column ON table(column)". After the SQL statement for optimizing the database index is generated, the database index is optimized through these SQL statements.
[0094] In this embodiment, through the above method, the database index can be dynamically optimized according to the execution time of the first predicted query, ensuring the efficient operation of the database query and better improving the query performance.
[0095] In a preferred embodiment, generating and executing a SQL statement for optimizing the index of the database according to the text information to optimize the index of the database includes:
[0096] Determining a condition field of the first predicted query text according to the text information;
[0097] Generate an index name according to the condition field;
[0098] Generate an SQL statement for optimizing the index of the database according to the condition field and the index name;
[0099] Submit the SQL statement to the database so that the SQL statement is executed by the database to optimize the index of the database.
[0100] Specifically, in this embodiment, text information in the predicted query text corresponding to the predicted first query execution time is extracted, and a condition field of the first predicted query text is generated according to the text information, and then a corresponding index name is generated according to the condition field. Finally, an SQL statement for optimizing the index of the database is generated according to the condition field and the index name, and the generated SQL statement is executed by the database to optimize the index of the database. The specific steps are as follows:
[0101] First, extract the text information in the prediction query text corresponding to the execution time of the first prediction query, and determine the condition fields of the first prediction query text based on the text information. These condition fields are usually the columns involved in the WHERE clause in the query statement, such as the column in "SELECT * FROM table WHERE column = value".
[0102] Further, an index name is generated based on the extracted conditional fields. The index name should be unique and descriptive for easy maintenance and management. In practical applications, a common naming rule is to use a combination of table name and column name, such as "idx_table_column".
[0103] Further, according to the condition field and the generated index name, an SQL statement for optimizing the database index is constructed. In this embodiment, the generated SQL statement is usually a statement for creating an index, such as "CREATE INDEX idx_column ON table(column)".
[0104] Furthermore, the generated SQL statements are submitted to the database so that the database can execute these SQL statements to optimize the database index. In practical applications, this can be done by a DBA (Database Administrator) or an automated database management tool. Executing these index optimization operations can significantly reduce the execution time of queries and improve the overall performance of the database.
[0105] In a preferred embodiment, the database is a Doris database, and the method further comprises:
[0106] Obtaining from the Doris database multiple historical query execution times, execution users, executed SQL statements, query types, and query frequencies used for querying in the historical query logs;
[0107] Preprocessing each of the executing users, the executed SQL statements, the query type and the query frequency to obtain a plurality of historical query texts;
[0108] The plurality of historical query texts and the plurality of historical query execution durations are matched one by one using a preset regular expression to obtain a plurality of historical query text pairs.
[0109] The embodiment of the present application provides a method for training a target prediction model, wherein the data used to train the target prediction model is derived from the Doris database. Specifically, in the present embodiment, when the database is the Doris database, first, key information in the historical query log is obtained from the Doris database, including the execution time of multiple historical queries used for querying, the executing user, the executed SQL statement, the query type, and the query frequency. In practical applications, this information can be used as the initial query text for model training. Then, data preprocessing is performed on these initial query texts to obtain multiple historical query texts.
[0110] In order to further refine the analysis, the multiple historical query texts generated by pre-defined regular expressions are matched one by one with the historical query execution time to form multiple historical query text pairs, wherein each historical query text pair includes a historical query text and a historical query execution time.
[0111] Further, the historical query text in any of the historical query text pairs is input as a feature variable into a pre-prepared prediction model to obtain a target predicted query execution time corresponding to the feature variable;
[0112] The mean square error between the target prediction query execution time and the historical query execution time corresponding to the feature variable is calculated, and the parameters of the prediction model are optimized according to the mean square error to obtain the target prediction model.
[0113] Specifically, the historical query text in any of the historical query text pairs is input as a feature variable into a pre-prepared prediction model, wherein the prediction model may be a random forest model, to obtain the target predicted query execution time corresponding to the feature variable.
[0114] Furthermore, after obtaining the target prediction query execution time corresponding to the historical query text, the mean square error between the target prediction query execution time and the historical query execution time corresponding to the feature variable is calculated. The mean square error is an important indicator for evaluating the performance of the prediction model, which represents the average value of the sum of squares of the differences between the predicted value and the actual value. By calculating the mean square error, the error size of the prediction model can be quantified, thereby evaluating its accuracy.
[0115] Further, the parameters of the prediction model are optimized according to the mean square error to obtain the target prediction model. In practical applications, the optimization process is usually performed through an iterative method, such as using an optimization algorithm such as a gradient descent method to adjust the model parameters with the goal of minimizing the mean square error. Each iteration adjusts the parameters according to the prediction error of the current model, so that the model becomes more accurate in predicting the query execution time.
[0116] The optimized target prediction model will have higher prediction accuracy and can more accurately predict the query execution time. This is crucial for database index optimization, because accurate execution time prediction can help identify which queries need to be optimized and develop corresponding optimization strategies, thereby improving the overall performance and query efficiency of the database.
[0117] Through the above steps, we can systematically obtain data from historical query logs, use this data to train and optimize the prediction model, and finally build an efficient prediction system. This system can provide accurate execution time prediction for database index optimization, help database DBAs or automated database management tools make more informed decisions, and improve database query performance.
[0118] In a preferred embodiment, after optimizing the index of the database, the method further includes:
[0119] Obtaining a second query log from the database, and extracting a second query text of the second query log and a second query execution time corresponding to the second query text, wherein the second query log is a query log obtained after querying through the optimized index;
[0120] The target prediction model is updated by using the second query text and the second query execution duration of the second query log as training data for updating the target prediction model.
[0121] Specifically, in this embodiment, after optimizing the index of the database, a second query log is first obtained from the database. The second query log records query information obtained after querying through the optimized index, including the second query text and the second query execution time.
[0122] The second query text and the corresponding second query execution time in the second query log are used as training data for updating the target prediction model. The optimized query data is fed back to the target prediction model so that the model can learn and adapt to new query optimization situations.
[0123] The process of updating the target prediction model involves using new training data, namely the second query text and the second query execution time in the second query log, to adjust the parameters and weights of the model. This is done to enable the target prediction model to more accurately predict the query execution time after the optimized index, further improving the prediction ability and practicality of the model.
[0124] In this embodiment, a closed-loop optimization cycle can be implemented: starting from optimizing the database index, collecting and analyzing the optimized query logs, and then using these data to update the prediction model, ultimately achieving the purpose of optimizing database performance and improving query efficiency. In addition, through the closed-loop optimization cycle process, the automation and intelligence of index optimization are achieved, reducing manual intervention and operational complexity.
[0125] In a preferred implementation, a method is provided as follows Figure 2 The flowchart of the dynamic adjustment of the database index is as follows: Figure 2 As shown, the specific process includes:
[0126] Step S1: data collection;
[0127] The data collection in step S1 specifically includes: data access mode information (query type and frequency), data distribution information (data type, minimum value, maximum value, number of unique values and number of NULL values...), and the data is split into a training set and a test set, where the training set accounts for 80% and the test set accounts for 20%;
[0128] Step S2: target prediction model training;
[0129] Wherein, step S2 specifically includes:
[0130] Step S21: Data preprocessing: extract the query text in the query log as the input feature of the model training, and the query execution time as the output target feature;
[0131] Step S22: Feature extraction: use TF-IDF to vectorize the input features;
[0132] Step S23: training model: using random forest model to train data;
[0133] Step S24: Evaluate the model: use the trained target prediction model to predict the prediction execution time in the test set;
[0134] Step S25: Calculate the mean square error: Calculate the mean square error between the predicted result and the actual result;
[0135] Step S26: Model update: Update the target prediction model parameters according to the mean square error to obtain the optimal model.
[0136] Step S3: dynamic index optimization;
[0137] Acquire new query sample data in the future, which is the query sample data in the current query log, extract the query text therefrom, perform feature extraction, generate a feature vector, and predict the query execution time through the target prediction model, and determine whether the query execution time is greater than or equal to a pre-selected time threshold. If the query execution time is greater than or equal to the time threshold, perform the index optimization step through the Doris database. If the query execution time is less than the time threshold, there is no need to perform the index optimization step.
[0138] The present application provides a method for optimizing the index of a database, the method comprising: first obtaining a first query log from a database; and determining a first predicted query text from a first query text in the first query log; and then inputting the first predicted query text into a pre-trained target prediction model to predict a first predicted query execution time corresponding to the first predicted query text; and finally optimizing the index of the database according to the first predicted query execution time. The present application obtains a query log from a database, and predicts different query execution times based on different query texts in the query log through a pre-trained target prediction model, and dynamically optimizes the index of the database based on the predicted different query execution times. The present application significantly improves the query performance of the database by dynamically optimizing the index structure, thereby reducing the query response time.
[0139] Based on the same inventive concept, in a second aspect of the embodiment of the present application, a database index optimization system is provided. Figure 3 As shown, including:
[0140] An acquisition module 201 is used to acquire a first query log from a database;
[0141] A determination module 202, configured to determine a first predicted query text from the first query text in the first query log;
[0142] Prediction module 203, used for inputting the first prediction query text into a pre-trained target prediction model to predict the execution time of a first prediction query corresponding to the first prediction query text;
[0143] The optimization module 204 is used to optimize the index of the database according to the execution time of the first predicted query.
[0144] Optionally, the index of the database is optimized according to the first predicted query execution time, and the optimization module 204 includes:
[0145] A judgment submodule, used to judge whether the execution time of the first prediction query is greater than or equal to a preset time threshold;
[0146] an extraction submodule, configured to extract text information in a first prediction query text corresponding to the execution time of the first prediction query when the execution time of the first prediction query is greater than or equal to the preset time threshold;
[0147] The generating submodule is used to generate and execute an SQL statement for optimizing the index of the database according to the text information, so as to optimize the index of the database.
[0148] Optionally, the step of generating and executing an SQL statement for optimizing the index of the database according to the text information to optimize the index of the database comprises:
[0149] A determination subunit, configured to determine a condition field of the first predicted query text according to the text information;
[0150] A first generating subunit, used for generating an index name according to the condition field;
[0151] A second generating subunit, used to generate an SQL statement for optimizing the index of the database according to the condition field and the index name;
[0152] The optimization subunit is used to submit the SQL statement to the database so as to execute the SQL statement through the database and optimize the index of the database.
[0153] Optionally, the database is a Doris database, and before inputting the first prediction query text into a pre-trained target prediction model, the system further includes:
[0154] The first acquisition submodule is used to obtain the execution time, execution user, executed SQL statement, query type and query frequency of multiple historical queries used for query in the historical query log from the Doris database;
[0155] A preprocessing submodule, used for preprocessing each of the executing users, the executed SQL statements, the query type and the query frequency to obtain a plurality of historical query texts;
[0156] The pairing submodule is used to pair the plurality of historical query texts with the plurality of historical query execution durations one by one through a preset regular expression to obtain a plurality of historical query text pairs.
[0157] Optionally, the system further comprises:
[0158] An input submodule, used to input a historical query text in any of the historical query text pairs as a feature variable into a preset prediction model to obtain a target predicted query execution time corresponding to the feature variable;
[0159] The calculation submodule is used to calculate the mean square error between the target prediction query execution time and the historical query execution time corresponding to the feature variable, and optimize the parameters of the prediction model according to the mean square error to obtain the target prediction model.
[0160] Optionally, the system further comprises:
[0161] A second acquisition submodule is used to acquire a second query log from the database, where the second query log is a query log obtained after querying through the optimized index;
[0162] A determination submodule is used to determine the second query text and the second query execution time corresponding to the second query text from the second query log by using language;
[0163] An updating submodule is used to update the target prediction model by using the second query text and the second query execution time as training data for updating the target prediction model.
[0164] In a third aspect of an embodiment of the present application, a database is provided, wherein the database includes an index optimization system for a database as described in the second aspect of the present application, and / or an index optimization method for a database as described in the first aspect of the present application.
[0165] In a fourth aspect of the present application, there is provided a Figure 4 The electronic device 100 shown includes a memory 110, a processor 120, and a computer program stored in the memory 110. The processor 120 executes the computer program to implement the database index optimization method as described in the first aspect of the present application.
[0166] In a fifth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the method for optimizing the database index as described in the first aspect of the present application is implemented.
[0167] Each embodiment in this specification focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referenced to each other.
[0168] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0169] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0170] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0171] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0172] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0173] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0174] The above provides a detailed introduction to the provided database index optimization method, system, database, electronic device and medium. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for optimizing a database index, characterized in that: The method comprises: Obtain a first query log from a database; Determining a first predicted query text from the first query text in the first query log; Inputting the first prediction query text into a pre-trained target prediction model to predict a first prediction query execution time corresponding to the first prediction query text; The index of the database is optimized according to the execution time of the first predicted query.
2. The method for optimizing a database index according to claim 1, characterized in that: The optimizing the index of the database according to the first predicted query execution time includes: Determine whether the execution time of the first prediction query is greater than or equal to a preset time threshold; When the execution time of the first prediction query is greater than or equal to the preset time threshold, extracting text information in the first prediction query text corresponding to the execution time of the first prediction query; Based on the text information, an SQL statement for optimizing the index of the database is generated and executed to optimize the index of the database.
3. The method for optimizing a database index according to claim 2, characterized in that: The step of generating and executing a SQL statement for optimizing the index of the database according to the text information to optimize the index of the database includes: Determining a condition field of the first predicted query text according to the text information; Generate an index name according to the condition field; Generate an SQL statement for optimizing the index of the database according to the condition field and the index name; Submit the SQL statement to the database so that the SQL statement is executed by the database to optimize the index of the database.
4. The method for optimizing a database index according to claim 1, characterized in that: The database is a Doris database, and before inputting the first prediction query text into a pre-trained target prediction model, the method further includes: Obtaining from the Doris database multiple historical query execution times, execution users, executed SQL statements, query types, and query frequencies used for querying in the historical query logs; Preprocessing each of the executing users, the executed SQL statements, the query type and the query frequency to obtain a plurality of historical query texts; The plurality of historical query texts and the plurality of historical query execution durations are matched one by one using a preset regular expression to obtain a plurality of historical query text pairs.
5. The method for optimizing a database index according to claim 4, characterized in that: The method further comprises: Inputting the historical query text in any of the historical query text pairs as a feature variable into a preset prediction model to obtain a target predicted query execution time corresponding to the feature variable; The mean square error between the target prediction query execution time and the historical query execution time corresponding to the feature variable is calculated, and the parameters of the prediction model are optimized according to the mean square error to obtain the target prediction model.
6. The method for optimizing a database index according to claim 1, characterized in that: After optimizing the index of the database, the method further includes: Acquire a second query log from the database, where the second query log is a query log obtained after querying through the optimized index; Determining, from the second query log, a second query text and a second query execution time corresponding to the second query text; The target prediction model is updated by using the second query text and the second query execution duration as training data for updating the target prediction model.
7. A database index optimization system, characterized in that: The system comprises: An acquisition module, used for acquiring a first query log from a database; A determination module, configured to determine a first predicted query text from the first query text in the first query log; A prediction module, configured to input the first prediction query text into a pre-trained target prediction model, and predict a first prediction query execution time corresponding to the first prediction query text; An optimization module is used to optimize the index of the database according to the execution time of the first predicted query.
8. A database, characterized in that: The database includes the database index optimization system according to claim 7, and / or is used to execute the database index optimization method according to any one of claims 1-6.
9. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the database index optimization method according to any one of claims 1 to 6.
10. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instruction is executed by a processor, the method for optimizing the index of a database according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Method and system for database index optimization based on virtual index
CN113704246A
Intelligent index tuning method and system for relational database
CN115062011A
Cited By
NL2SQL method, device and equipment based on preset industry large model and medium
CN119917524A
Power test database management analysis method and system
CN120086208A
Database index table generation method, query method and electronic equipment
CN121560868A
