Database time model construction method and related product

The database time model is constructed by collecting information on the execution process of SQL statements, which solves the problems of database management and large storage space occupation in the existing technology, improves database performance and accuracy, and avoids view conversion errors.

CN118733563APending Publication Date: 2024-10-01CETC JINCANG (BEIJING) TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410822345.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-24
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

When generating a database time model, the existing technology needs to manage and store a large number of performance snapshots, which results in long database management operations and large storage space usage, which may cause performance problems, and information inconsistency is prone to occur during the view conversion process.

Method used

By collecting information on the execution process of the target SQL statement, calculating its total execution time, waiting time and stage execution time, building a database time model and generating a dynamic performance view, avoiding the need to obtain and store performance snapshots, directly display the proportion information, and reduce the database cost burden and avoid view conversion errors.

Benefits of technology

Reduce the impact of database management operations and storage space, improve the accuracy and performance of database time models, reduce the probability of new performance issues, and avoid information inconsistencies through dynamic performance views.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure BDA0004910753290000051
    Figure BDA0004910753290000051
  • Figure HDA0004910753440000011
    Figure HDA0004910753440000011
  • Figure HDA0004910753440000012
    Figure HDA0004910753440000012
Patent Text Reader

Abstract

The invention provides a database model construction method and a related product. The method comprises the steps that the total execution time of a target SQL statement, the waiting time of all waiting events in the execution process and the stage execution time of all execution stages are obtained; calculating non-idle waiting time and database CPU time of the target SQL statement according to the total execution time, each waiting time and each stage execution time; a database time model of the target SQL statement is constructed, a dynamic performance view of the database time model is generated, and the dynamic performance view comprises a performance view used for displaying non-idle waiting time and the proportion of database CPU time in total execution time and a performance view used for displaying the proportion of all waiting time in the non-idle waiting time; and / or a performance view for displaying the proportion of the execution time of each stage in the total execution time. According to the scheme, construction of the database time model is achieved, and the purpose of improving the database performance is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a method for constructing a database model and related products. Background Art

[0002] Database time is the total time spent on database-level calls, including the CPU (Central Processing Unit) time and non-idle waiting time generated by the client session process. Database time is a key indicator of database performance and has important reference value for database performance tuning.

[0003] In the prior art, the method for generating a database time model is to use two performance view images as a difference to periodically generate a database performance snapshot, and generate a database time model based on the performance snapshot. When the number of performance statistics of a database is relatively large, the management operations involved may take a long time, and the more performance snapshots are stored, the more storage space of the database is used, which may cause new performance problems in the database. Summary of the invention

[0004] One purpose of the present invention is to reduce the impact of building a database time model on database management operations and storage space, thereby improving database performance.

[0005] A further object of the present invention is to improve the accuracy of the output of the database time model.

[0006] Another further object of the present invention is to obtain a database optimization strategy based on a database time model to improve database performance.

[0007] In particular, the present invention provides a method for constructing a database time model, comprising:

[0008] Obtain a target SQL statement, and collect information about the execution process of the target SQL statement to obtain the total execution time of the target SQL statement, as well as the waiting time of each waiting event and the stage execution time of each execution stage during the execution process;

[0009] Calculate the non-idle waiting time and database CPU time of the target SQL statement according to the total execution time, each waiting time and each stage execution time;

[0010] A database time model of the target SQL statement is constructed, and a dynamic performance view of the database time model is generated, wherein the dynamic performance view includes a performance view for displaying the proportion of the non-idle waiting time and the database CPU time in the total execution time, a performance view for displaying the proportion of each waiting time in the non-idle waiting time, and / or a performance view for displaying the proportion of each stage execution time in the total execution time.

[0011] Furthermore, the calculation of the non-idle waiting time and the database CPU time of the target SQL statement according to the total execution time, each waiting time and each stage execution time includes:

[0012] Calculate the non-idle waiting time according to each of the waiting times;

[0013] The database CPU time is calculated according to the total execution time and the non-idle waiting time.

[0014] Furthermore, after constructing the database time model of the target SQL statement, the method further includes:

[0015] Determine whether the proportion of the non-idle waiting time in the total execution time is greater than a set proportion threshold;

[0016] If so, an optimization strategy for the database is obtained according to at least one waiting event whose waiting time accounts for the largest proportion of the non-idle waiting time.

[0017] Furthermore, the obtaining of the optimization strategy of the database according to at least one waiting event whose waiting time accounts for the largest proportion of the non-idle waiting time includes:

[0018] If the waiting events whose waiting time accounts for the largest proportion of the non-idle waiting time include a data block read event and / or a data block write event, the optimization strategy includes expanding the data page buffer of the database.

[0019] Further, after the database time model of the target SQL statement is constructed, the following steps are included:

[0020] An execution stage in which a proportion of the stage execution time in the total execution time is greater than a corresponding proportion threshold is acquired, and the optimization strategy is acquired according to the execution stage.

[0021] Furthermore, the obtaining of the optimization strategy according to the execution stage includes:

[0022] If the proportion of the phase execution time of the network write phase in the total execution time is greater than the corresponding proportion threshold, the optimization strategy at least includes controlling the number of result set rows sent each time.

[0023] Furthermore, the obtaining of the target SQL statement includes:

[0024] The resource consumption of preset items during the execution of multiple SQL statements is obtained, and one or more SQL statements with the largest resource consumption of the preset items are used as the target SQL statements.

[0025] Furthermore, after obtaining the resource consumption of the preset items during the execution of the multiple SQL statements, the method further includes:

[0026] A dynamic performance view is generated for displaying the resource consumption of each of the preset items.

[0027] On the other hand, the present invention further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the method for constructing a database time model described in any one of the above items are implemented.

[0028] On the other hand, the present invention also provides a computer program product, including a computer program, characterized in that when the computer program is executed by a processor, the steps of constructing a database time model as described in any one of the above are implemented.

[0029] The technical solution of the present invention collects information about the execution process of the target SQL statement, and builds a database time model of the target SQL statement based on the collected information. The total execution time and non-idle waiting time of the target SQL statement, as well as the proportion of the stage execution time of each execution stage in the total execution time, and the proportion of the waiting time of each waiting event in the non-idle waiting time are provided in the data time model. Since the technical solution of the present invention only needs to collect information about the execution process of the target SQL statement in the process of building the database time model, and does not need to obtain and store the performance snapshot of the database, it can reduce the burden on the database and reduce the probability of new performance problems in the database.

[0030] In addition, the technical solution of the present invention displays the database time model of the target SQL statement through a dynamic performance view. Compared with the view format using TEXT, HTML, JSON, etc. in the prior art, it does not need to go through view conversion, so it can avoid the phenomenon that the information displayed by the view is inconsistent with the actual information due to errors in the view conversion process.

[0031] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:

[0033] Figure 1 It is a schematic flow chart of a method for generating a database time model in the prior art;

[0034] Figure 2 is a flowchart of a method for constructing a database time model according to an embodiment of the present invention;

[0035] Figure 3 It is a performance view for displaying the proportion of non-idle waiting time and database CPU time of a target SQL statement in the total execution time according to an embodiment of the present invention;

[0036] Figure 4 A performance view for displaying the proportion of each waiting time of a target SQL statement in the non-idle waiting time according to an embodiment of the present invention;

[0037] Figure 5 is a performance view for displaying the proportion of each stage execution time of a target SQL statement in the total execution time according to an embodiment of the present invention;

[0038] Figure 6 is a schematic flow chart of a method for constructing a database time model according to another embodiment of the present invention;

[0039] Figure 7 A dynamic performance view for displaying resource consumption of preset items during the execution of each SQL statement according to an embodiment of the present invention;

[0040] Figure 8 is a flowchart of a method for constructing a database time model according to another embodiment of one embodiment of the present invention;

[0041] Fig. 9 is a schematic diagram of a computer program product according to an embodiment of the present invention;

[0042] Fig.10 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention. DETAILED DESCRIPTION

[0043] In the prior art, the method of generating a database time model is as follows: Figure 1As shown, first, the first performance snapshot of the database is obtained at the first moment, and the performance view image last1 corresponding to the first performance snapshot is generated; then, the second performance snapshot of the database is obtained at the second moment, and the performance view image last2 corresponding to the second performance snapshot is generated; then, the performance view image last2 is associated with the performance view image last1, and the difference of each statistical item is calculated to obtain the result of this snapshot and store it in the snapshot table, and the performance view image last1 is deleted, and the first performance snapshot, the second performance snapshot and the performance view image last2 are retained. In the process of displaying the database time model, the performance snapshot of the database needs to be output in TEXT, HTML, JSON and other formats.

[0044] According to the above content, Figure 1 The method for generating the database time model shown, on the one hand, when the number of performance statistics of the database is large, the time required for the associated operations involved in generating the database time model is longer. On the other hand, as the number of performance snapshots increases, the amount of storage space occupied by the database will also increase, and the occupied database space may cause other performance problems. In addition, in the process of displaying the database time model, the database time model processing, text or web page typesetting output and other work are involved, which may cause errors in the displayed database time model view.

[0045] Figure 2 FIG. 4 is a schematic flow chart of a method for constructing a database time model according to an embodiment of the present invention. The method may generally include:

[0046] Step S102: Obtain a target SQL (Structured Query Language) statement, and collect information about the execution process of the target SQL statement to obtain a total execution time of the target SQL statement, a waiting time of each waiting event during the execution of the target SQL statement, and a stage execution time of each execution stage;

[0047] Step S104: Calculate the non-idle waiting time of the target SQL statement and the database CPU time according to the total execution time of the target SQL statement, the waiting time of each waiting event during the execution of the target SQL statement, and the stage execution time of each execution stage;

[0048] Step S106: construct a database time model of the target SQL statement, and generate a dynamic performance view of the database time model.

[0049] In the above step S102, the total execution time of the target SQL statement refers to the total time consumed from the start of executing the target SQL statement to the end of executing the target SQL statement. The total execution time can reflect the resource consumption of the target SQL statement on the database. Therefore, the total execution time of the target SQL statement can be used as the database time of the target SQL statement.

[0050] The wait event of the target SQL statement is a blocking point in the execution process of the target SQL statement, which is related to the IO operation, lightweight lock, conventional lock and remote procedure call of the database. In this embodiment, the wait event of the target SQL statement may include but is not limited to waiting for reading client requests, writing WAL logs, reading data block files, writing data block files and data file extensions. One or more.

[0051] The execution phase of the target SQL statement is an important process of the execution of the target SQL statement. The execution phases of the target SQL statement can be counted separately to obtain the time occupied by each execution phase, which is the phase execution time of the corresponding execution phase. In this embodiment, the execution phase of the target SQL statement includes but is not limited to the syntax parsing phase, the semantic analysis phase, the SQL rewriting phase, the plan generation phase, the execution phase, the PLSQL statement compilation phase, the PLSQL statement execution phase, and the network reading and writing phase. The time occupied by each execution phase in the execution process of the target SQL statement is the phase execution time of each execution phase of the target SQL statement.

[0052] In this embodiment, the information of the execution process of the target SQL statement collected includes the unique identifier sql_id of the target SQL statement, the text sql_text of the target SQL statement, the database ID number database_id, the user ID number user_id, the total number of executions of the target SQL statement calls, the total execution time of the target SQL statement times, the number of returned tuples rows, the number of parsing phases parse_calls, the parsing phase time parse_times, the number of planning phases plan_calls, the planning phase time plan_times, the number of execution phases exec_calls, the execution phase time exec_times, the data block reading time blocks_read_times and the data block writing time blocks_write_times. The units of the execution process information, the field names and data types in the database are shown in Table 1. For example, the field name of the unique identifier of the target SQL statement is sql_id, and the data type is bigint.

[0053]

[0054]

[0055] Table 1

[0056] In this embodiment, the following query statement can be used to obtain the total execution time of the target SQL statement:

[0057] select sum(times)from stat_statements;

[0058] In the above query statement, stat_statements represents the collection of statistical information during the execution of the target SQL statement, and sum(times) represents the total execution time of the target SQL statement.

[0059] The collected information about waiting events during the execution of the target SQL statement includes the waiting type wait_type, the waiting event name wait_event, the number of waiting calls wait_calls and the waiting time wait_times of the waiting event. The field names and data types of the information of each waiting event in the database are shown in Table 2. For example, the field name of the waiting type is wait_type and the data type is text.

[0060] Field Name Data Types illustrate wait_type text Waiting Type wait_event text Waiting event name wait_calls bigint Waiting times wait_times bigint Waiting time (in microseconds)

[0061] Table 2

[0062] In this embodiment, the non-idle waiting time of the database can be queried through the following query statement:

[0063] select sum(times)from stat_waits where wait_event! ='ClientRead'andwait_event! ='Sleep';

[0064] In the above query statement, stat_waits represents a collection of waiting events, ClientRead represents a client read event, ClientRead represents a foreground client read event, and Sleep represents a pause event. The waiting time of these two waiting events is not a non-idle waiting time. In the above query statement, wait_event! = 'ClientRead' and wait_event! = 'Sleep' means excluding the ClientRead event and the Sleep event to obtain the non-idle waiting event.

[0065] In this embodiment, the collected information of each execution phase of the target SQL statement includes the name phase_name, execution number calls and execution time times of each execution phase. The field name and data type of the information of each execution phase are shown in Table 3.

[0066] Field Name Data Types illustrate phase_name text Execution phase name calls bigint Execution times times bigint Execution time (in microseconds)

[0067] Table 3

[0068] In the above step S104, the waiting events of the target SQL statement include idle waiting events and non-idle waiting events, and the idle waiting events include ClientRead events and Sleep events, wherein the ClientRead event is a client read event, and the Sleep event represents a pause event. Except for the ClientRead event and the Sleep event, the rest of the waiting events are non-idle waiting events, and the time consumed by each non-idle waiting event is the non-idle waiting time.

[0069] In this embodiment, the database CPU time of the target SQL statement refers to the time consumed in the process of the database executing the SQL statement, that is, the time spent in the process of the database CPU executing the program related to the target SQL statement. Therefore, the database CPU time of the target SQL statement is directly related to the performance of the database CPU. The stronger the performance of the database CPU, the smaller the database CPU time of the target SQL statement.

[0070] In the above step S106, the database time model of the target SQL statement constructed includes the database time, database CPU time and non-idle waiting time during the execution of the target SQL statement. The dynamic performance view of the database time model of the target SQL statement constructed includes a performance view for displaying the proportion of the non-idle waiting time and database CPU time of the target SQL statement in the total execution time, a performance view for displaying the proportion of each waiting time of the target SQL statement in the non-idle waiting time, and a performance view for displaying the proportion of each stage execution time of the target SQL statement in the total execution time.

[0071] In this embodiment, the performance view used to display the non-idle waiting time of the target SQL statement and the proportion of the database CPU time in the total execution time is as follows: Figure 3As shown, the information displayed in the performance view includes the statistical item metric, the number of execution calls, the total execution time times, the average execution time avg_times of each execution stage, and the database time percentage dbtime_pct, and the field name and data type of each information are shown in Table 4, where metric is the field name of the statistical item. In this embodiment, the statistical items include the database time DB Time, the database CPU time DB CPU, and the non-idle waiting time FG Wait of the target SQL statement.

[0072] Field Name Data Types illustrate metric text Statistics calls bigint Execution times times bigint Total execution time (microseconds) avg_times numeric Average execution time of each execution stage (microseconds) dbtime_pct numeric Database Time Percent

[0073] Table 4

[0074] In this embodiment, the performance view used to display the proportion of each waiting time of the target SQL statement in the non-idle waiting time is as follows: Figure 4 As shown, the wait events in this performance view include DataFileRead events (data block read events), DataFileWrite events (data block write events), transactionid events (transaction lock events), WALWriteLock events (write-ahead log write lock events), and wal_insert events (write-ahead log insert lock events). The information of each wait event includes the wait type wait_type, wait event name wait_event, wait times wait_calls, wait time wait_times, average wait time avg_times of each wait event, and the proportion of non-idle wait time in database time. Figure 4 The field names and data type descriptions of each information in the performance view are shown in Table 5.

[0075] Field Name Data Types illustrate wait_type text Waiting Type wait_event text Waiting event name wait_calls bigint Waiting times wait_times bigint Waiting time (microseconds) avg_times numeric Average waiting time for each wait event (microseconds) dbtime_pct numeric Percentage of time in database

[0076] Table 5

[0077] In this embodiment, the performance view used to display the proportion of each stage execution time of the target SQL statement in the total execution time is as follows: Figure 5As shown in the figure, the execution phases in this performance view include the Execute Event phase (transaction execution phase), Net Write phase (network write phase), CommitTransaction phase, InitializePlan phase (plan initialization phase), Plan Event phase (plan execution phase), Net Read phase (network read phase), Analyze Event phase (transaction analysis phase), Parse Event phase (transaction parsing phase) and Rewrtie Event phase (statement rewriting phase). The information of each phase includes the execution phase name phase_name, execution times calls, execution time times, average execution time avg_times and its proportion in database time. Figure 5 The field names and data types of each information in the performance view are shown in Table 6.

[0078] Field Name Data Types illustrate phase_name text Execution phase name calls bigint Execution times times bigint Execution time (microseconds) avg_times numeric Average waiting time (microseconds) dbtime_pct numeric Percentage of time in database

[0079] Table 6

[0080] In this embodiment, the user can use query instructions to obtain a dynamic performance view of the database time model. For example, if the user needs to view the non-idle waiting time of the target SQL statement and the proportion of the database CPU time in the total execution time, the user can enter the following instructions into the database:

[0081] select*from dbtime_overview;

[0082] dbtime_overview is a performance view showing the proportion of the non-idle wait time of the target SQL statement and the database CPU time in the total execution time.

[0083] If the user needs to view the proportion of each waiting time of the target SQL statement in the non-idle waiting time, the user can enter the following command into the database:

[0084] select * from dbtime_wait;

[0085] Among them, dbtime_wait indicates a performance view that displays the proportion of each waiting time of the target SQL statement in the non-idle waiting time.

[0086] If the user needs to view the proportion of each stage execution time of the target SQL statement in the total execution time, the user can enter the following command into the database:

[0087] select * from dbtime_phase;

[0088] Among them, dbtime_phase indicates a performance view that displays the proportion of each phase execution time of the target SQL statement in the total execution time.

[0089] According to the above content, the technical solution of this embodiment collects information about the execution process of the target SQL statement, and builds a database time model of the target SQL statement based on the collected information. The total execution time and non-idle waiting time of the target SQL statement, as well as the proportion of the stage execution time of each execution stage in the total execution time, and the proportion of the waiting time of each waiting event in the non-idle waiting time are provided in the data time model. Since this embodiment only needs to collect information about the execution process of the target SQL statement in the process of building the database time model, and does not need to obtain and store the performance snapshot of the database, it can reduce the burden on the database and reduce the probability of new performance problems in the database.

[0090] In addition, in this embodiment, the database time model of the target SQL statement is displayed through a dynamic performance view. Compared with the view in the format of TEXT, HTML, JSON, etc. used in the prior art, no view conversion is required. Therefore, the phenomenon that the information displayed by the view is inconsistent with the actual information due to errors in the view conversion process can be avoided.

[0091] In some embodiments of the present invention, the method for calculating the non-idle waiting time of the target SQL statement and the database CPU time in step S104 includes:

[0092] Calculate the non-idle waiting time of the target SQL statement according to the waiting time of each waiting event of the target SQL statement;

[0093] The database CPU time of the target SQL statement is calculated based on the total execution time and non-idle waiting time of the target SQL statement.

[0094] In this embodiment, the sum of the waiting time occupied by each non-idle waiting event of the target SQL statement is used as the non-idle waiting time of the target SQL statement. The database time of the target SQL statement includes the CPU time and the non-idle waiting time of the target SQL statement. Since the database CPU time of the target SQL statement cannot be directly obtained from the statistical data, the difference between the database time of the target SQL statement and the non-idle waiting time is used as the database CPU time of the target SQL statement in this embodiment.

[0095] Through the technical solution of this embodiment, the non-idle waiting time and database CPU time of the target SQL statement can be calculated quickly and accurately.

[0096] The database time model construction method provided by the present invention can reflect the occupation of database resources during the execution of the target SQL statement, so as to formulate a database performance optimization strategy. The following is a detailed introduction to the method of specifying the database optimization strategy based on the database time model in combination with specific application scenarios.

[0097] In some embodiments of the present invention, the method for constructing the database time model of the present invention is as follows: Figure 6 As shown, after the above step S106, it also includes:

[0098] Step S112: determining whether the proportion of the non-idle waiting time of the target SQL statement in the total execution time is greater than a set proportion threshold;

[0099] If yes, execute step S114;

[0100] Step S114: Obtain an optimization strategy for the database according to one or more wait events whose wait time in the target SQL statement accounts for the largest proportion of the non-idle wait time.

[0101] In the above step S112, if the proportion of the non-idle waiting time of the target SQL statement in the total execution time is greater than the set proportion threshold, it can be considered that the non-idle waiting time process of the target SQL statement causes the total execution time to increase, so the waiting events of the target SQL statement can be optimized to improve the performance of the database.

[0102] by Figure 3 The performance view shown is used as an example. Figure 3 In the performance view shown, the proportion of non-idle waiting time in the target SQL statement in the total execution time is 42.99%. It can be determined that the proportion of non-idle waiting time in the target SQL statement in the total execution time is greater than the set proportion threshold.

[0103] In the above step S114, one or more waiting events whose waiting time accounts for the largest proportion of the non-idle waiting time have the greatest impact on the non-idle waiting time of the target SQL statement. Therefore, obtaining the database optimization strategy based on these times can improve the optimization effect on database performance.

[0104] by Figure 4 The performance view is shown as an example. Figure 4In the performance view shown, the waiting time of DataFileRead events (i.e., data block read events) and DataFileWrite events (data block write events) account for the largest proportion of non-idle waiting time, which are 23.34% and 8.70% respectively. Therefore, an optimization strategy for database performance is obtained for DataFileRead events and DataFileWrite events.

[0105] Through the technical solution of this embodiment, when the proportion of non-idle waiting time in the total execution time is greater than the set proportion threshold, an optimization strategy can be formulated according to the waiting event whose waiting time accounts for the largest proportion of the non-idle waiting time to reduce the non-idle waiting time of the target SQL statement, thereby achieving the purpose of improving the performance of the database.

[0106] In some embodiments of the present invention, the method for obtaining the optimization strategy of the database in the above step S114 includes:

[0107] If among the waiting events, the waiting time of the data block read event and / or the data block write event (ie, DataFileRead event and / or DataFileWrite event) accounts for the largest proportion of the non-idle waiting time, the obtained database optimization strategy includes expanding the data page buffer of the database.

[0108] The data page buffer is an area in memory that is used to store data pages or index pages read from the database file on disk. The database buffer manager is responsible for reading data pages or index pages from the database disk file into the data page buffer and writing the modified pages back to disk. Data can be modified multiple times before being written back to disk, thereby reducing the number of disk I / O operations and improving database performance. If the data page buffer is too small, it may cause frequent disk I / O operations, resulting in long wait times for database read block events and / or write block events.

[0109] Therefore, in this embodiment, after determining that the waiting time of the read data block event and / or the write data block event accounts for the largest proportion of the non-idle waiting time, the number of data input and output operations can be reduced by expanding the database's data page buffer to reduce the non-idle waiting time and improve the database performance.

[0110] In some embodiments of the present invention, the method for constructing the database time model of the present invention is as follows: Figure 6 As shown, after the above step S106, it also includes:

[0111] Step S122: obtaining the proportion of the stage execution time of each execution stage in the total execution time, and determining whether each proportion is greater than a corresponding threshold;

[0112] Step S124: Obtaining a database optimization strategy according to the execution stage whose proportion of the stage execution time in the total execution time is greater than the corresponding proportion threshold.

[0113] by Figure 5 The performance view shown is used as an example. Figure 5 In the performance view shown, the execution time of the Execute Event stage and the Net Write stage account for the largest proportion of the total execution time, which are 47.17% and 10.64% respectively. The Execute Event stage is executed by the SQL executor, and its proportion is not greater than the corresponding proportion threshold, but the execution time of the NetWrite execution stage accounts for more than the corresponding proportion threshold in the total execution time. Therefore, in this embodiment, the optimization strategy of the database is obtained according to the Net Write execution stage.

[0114] During the execution of the target SQL statement, each execution stage is a necessary stage. Different execution stages require different times. Therefore, a corresponding proportion threshold is set for each execution stage. If the proportion of the stage execution time of an execution stage in the total execution time is greater than the corresponding proportion threshold, it can be determined that the execution stage occupies too many resources and the performance of the database needs to be optimized for the execution stage. Therefore, the database optimization strategy is obtained according to the execution stage to optimize the database performance and improve the work efficiency of the database.

[0115] In some embodiments of the present invention, in the above step S124, according to the execution stage whose proportion of the stage execution time in the total execution time is greater than the corresponding proportion threshold, the method for obtaining the optimization strategy of the database includes:

[0116] In each execution phase of the target SQL statement, if the proportion of the phase execution time of the network write phase (i.e., the Net Write phase) in the total execution time is greater than the corresponding proportion threshold, the obtained database optimization strategy is to control the number of result set rows sent each time.

[0117] In this embodiment, if the proportion of the stage execution time of the network write stage in the total execution time is greater than the corresponding proportion threshold, it can be determined that the input and output network data sent by the server to the client is too high. Therefore, the number of result set rows sent each time can be controlled to reduce the number of network data input and output, thereby reducing the proportion of the network write stage in the total execution time and improving the performance of the database.

[0118] In some embodiments of the present invention, the method for obtaining the target SQL statement in step S102 includes:

[0119] The resource consumption of preset items during the execution of multiple SQL statements is obtained, and one or more SQL statements with the largest resource consumption are used as target SQL statements.

[0120] In this embodiment, the preset item can be the total execution process of the SQL statement, or it can be a certain execution stage or a waiting event in the execution process of the SQL statement. The resource consumption refers to the time taken to execute the preset item. For example, the resource consumption of the total execution process of the SQL statement refers to the total execution time of the SQL statement, the resource consumption of a certain execution stage refers to the stage execution time of the execution stage, and the resource consumption of a waiting event refers to the waiting time of the waiting event.

[0121] In this embodiment, the user can set preset items according to the performance analysis requirements of the database. If the preset item is the total execution process of the SQL statement, the SQL statement with the largest total execution time is used as the target SQL statement, which can provide a reliable reference for database performance optimization.

[0122] Through the technical solution of this embodiment, the target SQL statement can be selected according to the resource consumption of the preset items during the execution of each SQL statement, so that the user can set the preset items according to the performance analysis requirements of the database to improve the flexibility of optimizing the performance analysis of the database.

[0123] In some embodiments of the present invention, after obtaining the resource consumption of preset items during the execution of multiple SQL statements, the method further includes: generating a dynamic performance view for displaying the resource consumption of preset items during the execution of each SQL statement.

[0124] Taking the total execution process of SQL statements as an example, the dynamic performance view of the resource consumption of the preset items during the execution of each SQL statement is as follows: Figure 7 As shown, it includes the ID number sql_id, execution times calls, total execution time times, average time avg_times and proportion of database time dbtime_pct of each SQL statement, and the field name, data type and description of each information in this table view are shown in Table 7.

[0125] Field Name Data Types illustrate sql_id text SQL statement ID calls bigint Execution times times bigint Total execution time (microseconds) avg_times numeric Average time (microseconds) dbtime_pct numeric Percentage of database time

[0126] Table 7

[0127] In this embodiment, if the user needs to view the resource consumption of the preset items during the execution of each SQL statement, the user can enter the following command into the database:

[0128] select sql_id,calls,rows,times,round(avg_times,2)as avg_times,dbtime_pct from dbtime_sql limit 5;

[0129] In the above query instruction, limit 5 means querying five SQL statements. The query content includes the SQL statement ID number sql_id, the SQL statement execution times calls, the SQL statement return tuple number rows, the SQL statement total execution time times, the SQL statement average execution time avg_times, and the SQL statement database time percentage dbtime_pct, where round(avg_times,2) means that the average SQL statement execution time avg_times is rounded to two decimal places.

[0130] Through the technical solution of this embodiment, the resource consumption of preset items during the execution of each SQL statement can be displayed through a dynamic performance view, and no conversion is required during the display process, thereby avoiding errors in the displayed information.

[0131] In some embodiments of the present invention, the method for constructing the database time model is as follows: Figure 8 As shown, the following steps are included:

[0132] Step S202: obtaining resource consumption of preset items during the execution of multiple SQL statements, and generating a dynamic performance view for displaying the resource consumption of preset items during the execution of each SQL statement;

[0133] Step S204: taking one or more SQL statements with the largest preset item resource consumption during the execution of each SQL statement as target SQL statements;

[0134] Step S206: Collect information about the execution process of the target SQL statement to obtain the total execution time of the target SQL statement, as well as the waiting time occupied by each waiting event and the stage execution time occupied by each execution stage during the execution process of the target SQL statement;

[0135] Step S208: Calculate the non-idle waiting time of the target SQL statement according to the waiting time of each waiting event of the target SQL statement;

[0136] Step S210: Calculate the database CPU time of the target SQL statement according to the total execution time and the non-idle waiting time of the target SQL statement;

[0137] Step S212: constructing a database time model of the target SQL statement, and generating a dynamic performance view of the database time model;

[0138] Step S214: determining whether the proportion of the non-idle waiting time of the target SQL statement in the total execution time is greater than a set proportion threshold;

[0139] If yes, execute step S216;

[0140] Step S216: Obtaining a database optimization strategy according to one or more wait events whose wait time in the target SQL statement accounts for the largest proportion of the non-idle wait time;

[0141] Step S218: obtaining the proportion of the stage execution time of each execution stage in the total execution time, and determining whether each proportion is greater than a corresponding threshold;

[0142] If yes, execute step S220;

[0143] Step S220: Obtaining a database optimization strategy according to the execution stage whose proportion of the stage execution time in the total execution time is greater than the corresponding proportion threshold.

[0144] The technical solution of this embodiment only needs to collect information during the execution of the target SQL statement to build a database time model, and does not need to obtain and store database performance snapshots, thereby reducing the burden on the database and the probability of new performance problems in the database. In addition, this embodiment displays the database time model of the target SQL statement through a dynamic performance view, which does not require view conversion compared to the use of TEXT, HTML, JSON and other format views in the prior art, thereby avoiding the phenomenon that the information displayed in the view is inconsistent with the actual information due to errors in the view conversion process.

[0145] The flowchart provided by the present embodiment is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the above-mentioned methods may include additional operations. Within the scope of the technical ideas provided by the present embodiment method, additional changes may be made to the above-mentioned methods.

[0146] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.

[0147] This embodiment also provides a computer program product 10 and a computer readable storage medium 20 . Fig. 9 is a schematic diagram of a computer program product 10 according to an embodiment of the present invention, Fig.10is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which implements the steps of any of the above-mentioned methods for constructing a database time model when the computer program 11 is executed by the processor 32. The computer-readable storage medium 20 stores the above-mentioned computer program 11 thereon, and the computer program 11 implements the steps of any of the above-mentioned methods for constructing a database time model when the computer program 11 is executed by the processor 32.

[0148] The computer program 11 for performing the operation of the present invention may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-related instruction, a microcode, a firmware instruction, a state setting data, a configuration data of an integrated circuit, or a source code or an object code written in any combination of one or more programming languages ​​and process programming languages. The computer program 11 may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network (including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider via the Internet). In some embodiments, in order to perform various aspects of the present invention, an electronic circuit including, for example, a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA) may execute computer-readable program instructions by utilizing the state information of the computer-readable program instructions to personalize the electronic circuit.

[0149] In the description of this embodiment, the computer program product 10 is a related product including the computer program 11 .

[0150] For the purposes of the description of this embodiment, the computer-readable storage medium 20 is a tangible device capable of retaining and storing the computer program 11, which may be any device that can contain, store, communicate, propagate or transmit the program 11 for use with or in conjunction with an instruction execution system, device or apparatus. More specific examples (a non-exhaustive list) of the computer-readable storage medium 20 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the foregoing.

[0151] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.

Claims

1. A method for constructing a database time model, characterized in that: include: Obtain a target SQL statement, and collect information about the execution process of the target SQL statement to obtain the total execution time of the target SQL statement, as well as the waiting time of each waiting event and the stage execution time of each execution stage during the execution process; Calculate the non-idle waiting time and database CPU time of the target SQL statement according to the total execution time, each waiting time and each stage execution time; A database time model of the target SQL statement is constructed, and a dynamic performance view of the database time model is generated, wherein the dynamic performance view includes a performance view for displaying the proportion of the non-idle waiting time and the database CPU time in the total execution time, a performance view for displaying the proportion of each waiting time in the non-idle waiting time, and / or a performance view for displaying the proportion of each stage execution time in the total execution time.

2. The method for constructing a database time model according to claim 1, characterized in that: The calculating of the non-idle waiting time and the database CPU time of the target SQL statement according to the total execution time, each waiting time and each stage execution time comprises: Calculate the non-idle waiting time according to each of the waiting times; The database CPU time is calculated according to the total execution time and the non-idle waiting time.

3. The method for constructing a database time model according to claim 1, wherein: After the database time model of the target SQL statement is constructed, the following step is further included: Determine whether the proportion of the non-idle waiting time in the total execution time is greater than a set proportion threshold; If so, an optimization strategy for the database is obtained according to at least one waiting event whose waiting time accounts for the largest proportion of the non-idle waiting time.

4. The method for constructing a database time model according to claim 3, characterized in that: The step of obtaining a database optimization strategy according to at least one waiting event whose waiting time accounts for the largest proportion of the non-idle waiting time includes: If the waiting events whose waiting time accounts for the largest proportion of the non-idle waiting time include a data block read event and / or a data block write event, the optimization strategy includes expanding the data page buffer of the database.

5. The method for constructing a database time model according to claim 1, characterized in that: After the database time model of the target SQL statement is constructed, the following steps are included: An execution stage in which a proportion of the stage execution time in the total execution time is greater than a corresponding proportion threshold is acquired, and the optimization strategy is acquired according to the execution stage.

6. The method for constructing a database time model according to claim 5, characterized in that: The obtaining of the optimization strategy according to the execution stage includes: If the proportion of the phase execution time of the network write phase in the total execution time is greater than the corresponding proportion threshold, the optimization strategy at least includes controlling the number of result set rows sent each time.

7. The method for constructing a database time model according to claim 1, characterized in that: The target SQL statement is obtained, including: The resource consumption of preset items during the execution of multiple SQL statements is obtained, and one or more SQL statements with the largest resource consumption of the preset items are used as the target SQL statements.

8. The method for constructing a database time model according to claim 7, characterized in that: After obtaining the resource consumption of the preset items during the execution of the multiple SQL statements, the method further includes: A dynamic performance view is generated for displaying the resource consumption of each of the preset items.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for constructing a database time model according to any one of claims 1 to 8 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method for constructing a database time model according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • CN116303570A

  • CN117194185A

  • CN118035211A

  • US20200142802A1

  • US20230130738A1