[go: up one dir, main page]

CN112035513A - SQL statement performance optimization method, device, terminal and storage medium - Google Patents

SQL statement performance optimization method, device, terminal and storage medium Download PDF

Info

Publication number
CN112035513A
CN112035513A CN202010910839.4A CN202010910839A CN112035513A CN 112035513 A CN112035513 A CN 112035513A CN 202010910839 A CN202010910839 A CN 202010910839A CN 112035513 A CN112035513 A CN 112035513A
Authority
CN
China
Prior art keywords
sql statement
performance
optimized
sql
execution plan
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010910839.4A
Other languages
Chinese (zh)
Inventor
张鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Life Insurance Company of China Ltd
Original Assignee
Ping An Life Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Life Insurance Company of China Ltd filed Critical Ping An Life Insurance Company of China Ltd
Priority to CN202010910839.4A priority Critical patent/CN112035513A/en
Publication of CN112035513A publication Critical patent/CN112035513A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种SQL语句性能优化方法、装置、终端及存储介质,其中方法包括:获取用户输入的SQL语句的执行计划;根据执行计划评价SQL语句的性能值;当性能值未达到第一预设性能阈值时,对SQL语句进行压力测试,确定SQL语句的待优化点;基于SQL语句和待优化点查询预先设置好的SQL性能优化参数表,以对SQL语句进行优化。本发明通过对SQL语句进行压力测试,从而暴露出SQL语句潜在存在的缺陷,从而针对性的进行优化,提高SQL语句的性能。

Figure 202010910839

The invention discloses a SQL statement performance optimization method, device, terminal and storage medium, wherein the method includes: obtaining an execution plan of an SQL statement input by a user; evaluating the performance value of the SQL statement according to the execution plan; When the performance threshold is preset, a stress test is performed on the SQL statement to determine the point to be optimized for the SQL statement; the preset SQL performance optimization parameter table is queried based on the SQL statement and the point to be optimized to optimize the SQL statement. The present invention exposes potential defects of the SQL statement by performing stress testing on the SQL statement, so as to carry out targeted optimization and improve the performance of the SQL statement.

Figure 202010910839

Description

SQL语句性能优化方法、装置、终端及存储介质SQL statement performance optimization method, device, terminal and storage medium

技术领域technical field

本申请涉及计算机技术领域,特别是涉及一种SQL语句性能优化方法、装置、终端及存储介质。The present application relates to the field of computer technology, and in particular, to a method, device, terminal and storage medium for optimizing the performance of SQL statements.

背景技术Background technique

随着大数据时代的到来,数据库经常需要在海量数据中,选出满足特定需求的数据来完成查询操作。结构化查询语言(Structured Query Language,简称SQL)是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统。在实际工作过程中,开发人员经常需要编写逻辑比较复杂的SQL语句,而部分开发人员由于不熟悉SQL的底层原理,可能会写出性能较差的SQL语句,因此,测试SQL语句的性能显得尤为重要。With the advent of the era of big data, the database often needs to select the data that meets the specific needs from the massive data to complete the query operation. Structured Query Language (SQL) is a database query and programming language used for accessing data and querying, updating and managing relational database systems. In the actual work process, developers often need to write SQL statements with complex logic. Some developers may write SQL statements with poor performance because they are not familiar with the underlying principles of SQL. Therefore, it is particularly important to test the performance of SQL statements. important.

现在许多管理和开发工具都提供了查看图形化执行计划的功能,例如MySQLWorkbench、Oracle SQL Developer、SQL Server Management Studio、DBeaver等,也可通过命令行的方式查看执行计划。但是,上述方式仅能告知开发人员SQL语句的性能好坏,而无法确定SQL语句中具体存在的缺陷,也无法进行优化。Many management and development tools now provide the function of viewing graphical execution plans, such as MySQL Workbench, Oracle SQL Developer, SQL Server Management Studio, DBeaver, etc., and execution plans can also be viewed through the command line. However, the above method can only inform the developer of the performance of the SQL statement, but cannot determine the specific defects in the SQL statement, nor can it be optimized.

发明内容SUMMARY OF THE INVENTION

本申请提供一种SQL语句性能优化方法、装置、终端及存储介质,以解决现有的开发工具无法直观地展示SQL语句中的缺陷并针对性进行优化的问题。The present application provides a method, device, terminal and storage medium for optimizing the performance of SQL statements, so as to solve the problem that existing development tools cannot visually display defects in SQL statements and perform targeted optimization.

为解决上述技术问题,本申请采用的一个技术方案是:提供一种SQL语句性能优化方法,包括:获取用户输入的SQL语句的执行计划;根据执行计划评价SQL语句的性能值;当性能值未达到第一预设性能阈值时,对SQL语句进行压力测试,确定SQL语句的待优化点;基于SQL语句和待优化点查询预先设置好的SQL性能优化参数表,以对SQL语句进行优化。In order to solve the above-mentioned technical problems, a technical solution adopted in the present application is to provide a method for optimizing the performance of an SQL statement, including: obtaining an execution plan of the SQL statement input by a user; evaluating the performance value of the SQL statement according to the execution plan; When the first preset performance threshold is reached, a stress test is performed on the SQL statement to determine the point to be optimized of the SQL statement; the preset SQL performance optimization parameter table is queried based on the SQL statement and the point to be optimized to optimize the SQL statement.

作为本申请的进一步改进,对SQL语句进行压力测试,确定SQL语句的待优化点包括:从SQL语句中获取表字段DDL相关信息,以确认目标表;通过预设的模拟数据生成器生成预设数量的目标表的模拟数据;根据模拟数据测试SQL语句,并输出SQL语句的待优化点。As a further improvement of the present application, performing a stress test on the SQL statement to determine the point to be optimized of the SQL statement includes: obtaining DDL-related information of the table field from the SQL statement to confirm the target table; generating a preset simulation data generator through a preset simulation data generator The simulation data of the target table; test the SQL statement according to the simulation data, and output the point to be optimized of the SQL statement.

作为本申请的进一步改进,根据执行计划评价SQL语句的性能值,包括:根据SQL语句执行时的消耗资源、访问表的方式以及表的连接顺序和连接方式评估SQL语句,得到性能值。As a further improvement of the present application, evaluating the performance value of the SQL statement according to the execution plan includes: evaluating the SQL statement according to the consumption resources when executing the SQL statement, the way of accessing the table, and the connection sequence and connection method of the table to obtain the performance value.

作为本申请的进一步改进,根据执行计划评价SQL语句的性能值之后,还包括:当性能值超过第二预设性能阈值时,获取开发人员输入的SQL语句的数据结构原理和原理解释说明;将数据结构原理和原理解释说明与SQL语句对应后,写入SQL性能优化参数表。As a further improvement of the present application, after evaluating the performance value of the SQL statement according to the execution plan, the method further includes: when the performance value exceeds the second preset performance threshold, obtaining the data structure principle and principle explanation of the SQL statement input by the developer; After the data structure principle and principle explanation correspond to the SQL statement, write it into the SQL performance optimization parameter table.

作为本申请的进一步改进,对SQL语句进行优化之后,还包括:记录SQL语句的优化记录,生成优化后的SQL语句的执行计划,并存储至高速缓存。As a further improvement of the present application, after the SQL statement is optimized, the method further includes: recording an optimization record of the SQL statement, generating an execution plan of the optimized SQL statement, and storing it in a cache.

作为本申请的进一步改进,对SQL语句进行优化之后,还包括:对优化后的SQL语句再次进行压力测试,以检测待优化点是否已被优化;若否,则记录SQL语句,并将SQL语句待优化点上报。As a further improvement of the present application, after optimizing the SQL statement, the method further includes: performing a stress test on the optimized SQL statement again to detect whether the point to be optimized has been optimized; if not, recording the SQL statement, and putting the SQL statement Report to be optimized.

作为本申请的进一步改进,对SQL语句进行优化之后,还包括:将优化后的所述SQL语句上传至区块链中。As a further improvement of the present application, after optimizing the SQL statement, the method further includes: uploading the optimized SQL statement to the blockchain.

为解决上述技术问题,本申请采用的另一个技术方案是:提供一种SQL语句性能优化装置,包括:获取模块,用于获取用户输入的SQL语句的执行计划;评价模块,用于根据执行计划评价SQL语句的性能值;测试模块,用于当性能值未达到第一预设性能阈值时,对SQL语句进行压力测试,确定SQL语句的待优化点;优化模块,用于基于SQL语句和待优化点查询预先设置好的SQL性能优化参数表,以对SQL语句进行优化。In order to solve the above-mentioned technical problem, another technical solution adopted in the present application is to provide a SQL statement performance optimization device, comprising: an acquisition module for acquiring an execution plan of the SQL statement input by a user; an evaluation module for obtaining an execution plan according to the execution plan Evaluate the performance value of the SQL statement; the test module is used to perform stress testing on the SQL statement when the performance value does not reach the first preset performance threshold to determine the point to be optimized of the SQL statement; the optimization module is used to perform a stress test on the SQL statement based on the The optimization point queries the preset SQL performance optimization parameter table to optimize the SQL statement.

为解决上述技术问题,本申请采用的再一个技术方案是:提供一种终端,该终端包括处理器、与处理器耦接的存储器,其中,存储器存储有用于实现上述SQL语句性能优化方法的程序指令;处理器用于执行存储器存储的程序指令以对SQL语句进行优化。In order to solve the above-mentioned technical problem, another technical solution adopted in the present application is to provide a terminal, the terminal includes a processor and a memory coupled to the processor, wherein the memory stores a program for implementing the above-mentioned SQL statement performance optimization method Instructions; used by the processor to execute program instructions stored in memory to optimize SQL statements.

为解决上述技术问题,本申请采用的再一个技术方案是:提供一种存储介质,存储有能够实现上述SQL语句性能优化方法的程序文件。In order to solve the above technical problem, another technical solution adopted in the present application is to provide a storage medium storing a program file capable of implementing the above-mentioned method for optimizing the performance of SQL statements.

本申请的有益效果是:本申请的SQL语句性能优化方法通过利用SQL语句的执行计划初步判断SQL语句是否存在缺陷,当通过执行计划确认SQL语句存在缺陷时,则对该SQL语句进行压力测试,从而暴露出该SQL语句存在的缺陷,并根据预先设置好的SQL性能优化参数表对SQL语句进行优化,其有效地帮助开发人员及时发现SQL中隐藏的问题,而且为开发人员直接给出了优化方案,提升了SQL语句的优化效率。The beneficial effects of the present application are as follows: the SQL statement performance optimization method of the present application preliminarily determines whether the SQL statement has defects by utilizing the execution plan of the SQL statement, and when it is confirmed that the SQL statement has defects through the execution plan, the SQL statement is subjected to a stress test, Thus, the defects of the SQL statement are exposed, and the SQL statement is optimized according to the pre-set SQL performance optimization parameter table, which effectively helps developers discover hidden problems in SQL in time, and directly provides optimization for developers. The solution improves the optimization efficiency of SQL statements.

附图说明Description of drawings

图1是本发明第一实施例的SQL语句性能优化方法的流程示意图;1 is a schematic flowchart of a method for optimizing SQL statement performance according to a first embodiment of the present invention;

图2是本发明第二实施例的SQL语句性能优化方法的流程示意图;Fig. 2 is the schematic flow chart of the SQL statement performance optimization method of the second embodiment of the present invention;

图3是本发明第三实施例的SQL语句性能优化方法的流程示意图;Fig. 3 is the schematic flow chart of the SQL statement performance optimization method of the third embodiment of the present invention;

图4是本发明实施例的SQL语句性能优化装置的功能模块示意图;Fig. 4 is the functional module schematic diagram of the SQL statement performance optimization device of the embodiment of the present invention;

图5是本发明实施例的终端的结构示意图;5 is a schematic structural diagram of a terminal according to an embodiment of the present invention;

图6是本发明实施例的存储介质的结构示意图。FIG. 6 is a schematic structural diagram of a storage medium according to an embodiment of the present invention.

具体实施方式Detailed ways

下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅是本申请的一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

本申请中的术语“第一”、“第二”、“第三”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”、“第三”的特征可以明示或者隐含地包括至少一个该特征。本申请的描述中,“多个”的含义是至少两个,例如两个,三个等,除非另有明确具体的限定。本申请实施例中所有方向性指示(诸如上、下、左、右、前、后……)仅用于解释在某一特定姿态(如附图所示)下各部件之间的相对位置关系、运动情况等,如果该特定姿态发生改变时,则该方向性指示也相应地随之改变。此外,术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "first", "second" and "third" in this application are only used for descriptive purposes, and should not be construed as indicating or implying relative importance or implying the number of indicated technical features. Thus, a feature defined as "first", "second", "third" may expressly or implicitly include at least one of that feature. In the description of the present application, "a plurality of" means at least two, such as two, three, etc., unless otherwise expressly and specifically defined. All directional indications (such as up, down, left, right, front, rear...) in the embodiments of the present application are only used to explain the relative positional relationship between components under a certain posture (as shown in the accompanying drawings). , motion situation, etc., if the specific posture changes, the directional indication also changes accordingly. Furthermore, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes unlisted steps or units, or optionally also includes For other steps or units inherent to these processes, methods, products or devices.

在本文中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本申请的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。Reference herein to an "embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor a separate or alternative embodiment that is mutually exclusive of other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

图1是本发明第一实施例的SQL语句性能优化方法的流程示意图。需注意的是,若有实质上相同的结果,本发明的方法并不以图1所示的流程顺序为限。如图1所示,该方法包括步骤:FIG. 1 is a schematic flowchart of a method for optimizing SQL statement performance according to the first embodiment of the present invention. It should be noted that, if there is substantially the same result, the method of the present invention is not limited to the sequence of the processes shown in FIG. 1 . As shown in Figure 1, the method includes the steps:

步骤S101:获取用户输入的SQL语句的执行计划。Step S101: Obtain the execution plan of the SQL statement input by the user.

需要说明的是,SQL语句的性能从一定程度上影响整个数据库的性能,很多情况下,数据库性能的低下基本上都是不良SQL语句所引起的,而SQL语句的执行计划则决定了SQL语句将会采用何种方式从数据库提取数据并返回给客户端。It should be noted that the performance of SQL statements affects the performance of the entire database to a certain extent. In many cases, the low performance of the database is basically caused by bad SQL statements, and the execution plan of the SQL statement determines that the SQL statement will How will the data be extracted from the database and returned to the client.

在步骤S101中,获取用户输入的SQL语句的执行计划,可以通过执行计算机指令信息的方式进行获取,例如,首先可以由用户手动输入SQL语句,然后通过触发计算机指令信息预执行用户输入的SQL语句,从而获得SQL语句的执行计划。本实施例中,介绍六种获取SQL语句执行计划的方式:In step S101, the execution plan of the SQL statement input by the user can be obtained by executing the computer instruction information. For example, the user can manually input the SQL statement first, and then pre-execute the SQL statement input by the user by triggering the computer instruction information. , so as to obtain the execution plan of the SQL statement. In this embodiment, six ways to obtain the execution plan of an SQL statement are introduced:

1、使用explain plan for命令生成执行计划并显示;1. Use the explain plan for command to generate an execution plan and display it;

2、使用dbms_system存储过程生成执行计划;2. Use the dbms_system stored procedure to generate an execution plan;

3、使用autotrace工具获取执行计划;3. Use the autotrace tool to obtain the execution plan;

4、从shared_pool中直接抽取执行计划;4. Extract the execution plan directly from the shared_pool;

5、从AWR报告库中获取执行计划;5. Get the execution plan from the AWR report library;

6、使用10046事件跟踪,通过开启事件跟踪,生成跟踪文件,最后通过分析跟踪文件,获取到执行计划。6. Using 10046 event tracking, by enabling event tracking, a tracking file is generated, and finally the execution plan is obtained by analyzing the tracking file.

本实施例优选采用explain plan for命令获取SQL语句的执行计划。In this embodiment, the explain plan for command is preferably used to obtain the execution plan of the SQL statement.

步骤S102:根据执行计划评价SQL语句的性能值。Step S102: Evaluate the performance value of the SQL statement according to the execution plan.

在步骤S102中,SQL语句的性能可通过执行该SQL语句时消耗的资源、SQL语句访问表的方式,表的连接顺序以及连接方式等来确定,因此,根据执行计划评价SQL语句的性能值具体包括:根据SQL语句执行时的消耗资源、访问表的方式以及表的连接顺序和连接方式评估SQL语句,得到性能值。In step S102, the performance of the SQL statement can be determined by the resources consumed when executing the SQL statement, the way the SQL statement accesses the table, the connection order and connection method of the table, etc. Therefore, the performance value of the SQL statement is evaluated according to the execution plan. Including: evaluating the SQL statement according to the consumption of resources when executing the SQL statement, the way of accessing the table, and the connection sequence and connection method of the table to obtain the performance value.

例如:表的访问方式主要是两种:全表扫描(TABLE ACCESS FULL)和索引扫描(INDEX SCAN),如果表上存在选择性很好的索引,却采用的全表扫描,就说明表的访问方式可能存在缺陷;若大表上没有合适的索引而走了全表扫描,就需要分析能否建立索引,或者是否能选择更合适的表连接方式和连接顺序以提高效率。表的连接顺序是指以某张表作为驱动表来连接其他表的先后访问顺序。表的连接方式是指两个表获得满足条件的数据时的连接过程,目前主要有三种表连接方式,嵌套循环(NESTED LOOPS)、哈希连接(HASH JOIN)和排序合并连接(SORT MERGE JOIN)。其中,嵌套循环和哈希连接较为常用。嵌套循环是指用两层循环处理两个游标,外层游标称作驱动表,Oracle检索驱动表的数据,一条一条的代入内层游标,查找满足WHERE条件的所有数据,因此内层游标表中可用索引的选择性越好,嵌套循环连接的性能就越高。哈希连接是指将驱动表的数据按照条件字段以散列的方式放入内存,然后在内存中匹配满足条件的行。哈希连接需要有合适的内存,而且必须在CBO优化模式下,连接两表的WHERE条件有等号的情况下才可以使用。哈希连接在表的数据量较大,表中没有合适的索引可用时比嵌套循环的效率要高。排序合并连接是先将关联表的关联列各自做排序,然后从各自的排序表中抽取数据,到另一个排序表中做匹配,因为需要做更多的排序,导致消耗的资源也更多。For example, there are two main ways to access a table: full table scan (TABLE ACCESS FULL) and index scan (INDEX SCAN). There may be defects in the method; if there is no suitable index on the large table and a full table scan is performed, it is necessary to analyze whether an index can be established, or whether a more suitable table connection method and connection order can be selected to improve efficiency. The connection order of tables refers to the sequential access order in which a table is used as a driving table to connect other tables. The connection method of tables refers to the connection process when two tables obtain data that meets the conditions. At present, there are three main table connection methods, nested loop (NESTED LOOPS), hash join (HASH JOIN) and sort merge join (SORT MERGE JOIN) ). Among them, nested loops and hash joins are more commonly used. Nested loop refers to processing two cursors with two layers of loops. The outer cursor is called the driving table. Oracle retrieves the data of the driving table and substitutes it into the inner cursor one by one to find all the data that meets the WHERE condition. Therefore, the inner cursor table The better the selectivity of the indexes available in , the higher the performance of the nested loop join. Hash join means that the data of the driving table is hashed into the memory according to the condition field, and then the rows that meet the condition are matched in the memory. Hash joins require appropriate memory, and can only be used when the WHERE condition of joining two tables has an equal sign in CBO optimization mode. Hash joins are more efficient than nested loops when the amount of data in the table is large and there is no suitable index available in the table. Sort merge join is to first sort the associated columns of the associated table, and then extract data from the respective sorting table to match in another sorting table. Because more sorting is required, more resources are consumed.

步骤S103:当性能值未达到第一预设性能阈值时,对SQL语句进行压力测试,确定SQL语句的待优化点。Step S103: When the performance value does not reach the first preset performance threshold, perform a stress test on the SQL statement to determine the point to be optimized of the SQL statement.

需要说明的是,SQL语句存在的待优化点包括执行SQL语句占用资源过多、SQL语句访问表的方式不合适、表的连接方式不合适等。第一预设性能阈值预先设定,当SQL语句的性能值低于第一预设性能阈值时,说明该条SQL语句存在待优化的缺陷。It should be noted that the points to be optimized in the SQL statement include excessive resource consumption for executing the SQL statement, inappropriate way of accessing the table by the SQL statement, and inappropriate connection method of the table. The first preset performance threshold is preset, and when the performance value of the SQL statement is lower than the first preset performance threshold, it indicates that the SQL statement has a defect to be optimized.

在步骤S103中,部分SQL语句存在的缺陷在数据量较少时无法被开发人员感知,例如:当查询一个表的数据时,若该表的数据量较少,使用全表扫描和索引扫描两种方式时,两者的消耗时间的时间差非常小,无法被开发人员感知,此时,开发人员可能误认为两种方式的效果相同,但是,当表的数据量很大时,时间差就会被放大,全表扫描方式的消耗时间明显高于索引扫描方式的消耗时间。因此,本实施例在通过执行计划判断SQL语句性能较差时,对其进行压力测试,以暴露其存在的缺陷,从而确认该SQL语句存在的待优化点。In step S103, the defects existing in some SQL statements cannot be perceived by developers when the amount of data is small. For example, when querying data of a table, if the amount of data in the table is small, two full table scans and index scans are used. In this way, the time difference between the two methods is very small and cannot be perceived by developers. At this time, developers may mistakenly believe that the effects of the two methods are the same. However, when the amount of data in the table is large, the time difference will be Enlarged, the consumption time of the full table scan method is significantly higher than that of the index scan method. Therefore, in this embodiment, when it is judged by the execution plan that the performance of the SQL statement is poor, a stress test is performed on the SQL statement to expose its existing defects, so as to confirm the existing point to be optimized of the SQL statement.

进一步的,在一些实施例中,对SQL语句进行压力测试,确定SQL语句的待优化点具体包括:Further, in some embodiments, performing a stress test on the SQL statement, and determining the point to be optimized of the SQL statement specifically includes:

1、从SQL语句中获取表字段DDL相关信息,以确认目标表。1. Obtain the DDL-related information of the table field from the SQL statement to confirm the target table.

2、通过预设的模拟数据生成器生成预设数量的目标表的模拟数据。2. Generate simulation data of a preset number of target tables through a preset simulation data generator.

具体地,该模拟数据生成器具体由lazy mock或者Data-Processer构成,通过从SQL语句中获取表字段DDL相关信息后,根据该表字段DDL相关信息由模拟数据生成器模拟目标表中的实际数据,得到预设数量的模拟数据。需要说明的是,该预设数量预先设定,且充分满足SQL语句进行压力测试时所需要的数据量。Specifically, the simulated data generator is specifically composed of a lazy mock or a Data-Processer. After obtaining the table field DDL related information from the SQL statement, the simulated data generator simulates the actual data in the target table according to the table field DDL related information. to get a preset amount of simulation data. It should be noted that the preset number is preset, and fully meets the data volume required for the stress test of the SQL statement.

3、根据模拟数据测试SQL语句,并输出SQL语句的待优化点。3. Test the SQL statement according to the simulated data, and output the point to be optimized of the SQL statement.

具体地,利用模拟数据对SQL语句进行测试,记录并分析测试的结果,从而确认SQL语句中的缺陷,将该缺陷作为SQL语句的待优化点输出。Specifically, the SQL statement is tested with simulated data, and the test result is recorded and analyzed, thereby confirming the defect in the SQL statement, and outputting the defect as the point to be optimized of the SQL statement.

步骤S104:基于SQL语句和待优化点查询预先设置好的SQL性能优化参数表,以对SQL语句进行优化。Step S104 : query a preset SQL performance optimization parameter table based on the SQL statement and the point to be optimized, so as to optimize the SQL statement.

需要说明的是,该SQL性能优化参数表预先进行设定,其综合了本领域技术人员所知的所有SQL语句优化方案。例如,索引方面相关的优化规则、底层的数据结构原理等均可写入SQL性能优化参数表中。It should be noted that the SQL performance optimization parameter table is preset, which integrates all SQL statement optimization solutions known to those skilled in the art. For example, optimization rules related to indexes and underlying data structure principles can be written into the SQL performance optimization parameter table.

在步骤S104中,当确认SQL语句的待优化点之后,从该SQL性能优化参数表中查询合适的优化方案,从而对SQL语句进行优化。In step S104, after confirming the to-be-optimized point of the SQL statement, query an appropriate optimization scheme from the SQL performance optimization parameter table, so as to optimize the SQL statement.

进一步的,在一些实施例中,步骤S104之后,还包括:对优化后的SQL语句再次进行压力测试,以检测待优化点是否已被优化;若否,则记录SQL语句,并将SQL语句待优化点上报。Further, in some embodiments, after step S104, the method further includes: performing a stress test on the optimized SQL statement again to detect whether the point to be optimized has been optimized; if not, recording the SQL statement, and storing the SQL statement to be Optimizing point reporting.

具体地,在进行压力测试时,不需要再次模拟生成模拟数据,直接用先前生成的模拟数据进行测试即可。本实施例中,利用再次进行压力测试以验证该SQL语句的优化是否合理,若优化不合理,则说明SQL性能优化参数表的优化建议不能解决该SQL语句存在的缺陷,此时,将该缺陷上报给开发人员,由开发人员主动解决该缺陷,并且还可将该缺陷的解决方式和原理说明写入至SQL性能优化参数表中,丰富SQL性能优化参数表中的内容。Specifically, when performing a stress test, it is not necessary to simulate again to generate simulated data, and the test can be performed directly with the previously generated simulated data. In this embodiment, the stress test is performed again to verify whether the optimization of the SQL statement is reasonable. If the optimization is unreasonable, it means that the optimization suggestion of the SQL performance optimization parameter table cannot solve the defect existing in the SQL statement. In this case, the defect is Report it to the developer, and the developer will take the initiative to solve the defect, and the solution method and principle description of the defect can also be written into the SQL performance optimization parameter table to enrich the content in the SQL performance optimization parameter table.

本发明第一实施例的SQL语句性能优化方法通过利用SQL语句的执行计划初步判断SQL语句是否存在缺陷,当通过执行计划确认SQL语句存在缺陷时,则对该SQL语句进行压力测试,从而暴露出该SQL语句存在的缺陷,并根据预先设置好的SQL性能优化参数表对SQL语句进行优化,其有效地帮助开发人员及时发现SQL中隐藏的问题,而且为开发人员直接给出了优化方案,提升了SQL语句的优化效率。The SQL statement performance optimization method according to the first embodiment of the present invention preliminarily determines whether the SQL statement has defects by using the execution plan of the SQL statement. There are defects in the SQL statement, and the SQL statement is optimized according to the pre-set SQL performance optimization parameter table, which effectively helps developers discover hidden problems in SQL in time, and directly gives developers an optimization plan to improve The optimization efficiency of SQL statements.

进一步的,在一些实施例中,在对SQL语句进行优化之后,还包括:将优化后的所述SQL语句上传至区块链中。Further, in some embodiments, after optimizing the SQL statement, the method further includes: uploading the optimized SQL statement to the blockchain.

具体地,基于优化后的SQL语句得到对应的摘要信息,具体来说,摘要信息由优化后的SQL语句进行散列处理得到,比如利用sha256s算法处理得到。将摘要信息上传至区块链可保证其安全性和对用户的公正透明性。用户设备可以从区块链中下载得该摘要信息,以便查证优化后的SQL语句是否被篡改。本示例所指区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链(Blockchain),本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层等。Specifically, the corresponding summary information is obtained based on the optimized SQL statement. Specifically, the summary information is obtained by hashing the optimized SQL statement, for example, by using the sha256s algorithm. Uploading summary information to the blockchain ensures its security and fairness and transparency to users. The user equipment can download the summary information from the blockchain to verify whether the optimized SQL statement has been tampered with. The blockchain referred to in this example is a new application mode of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. Blockchain, essentially a decentralized database, is a series of data blocks associated with cryptographic methods. Each data block contains a batch of network transaction information to verify its Validity of information (anti-counterfeiting) and generation of the next block. The blockchain can include the underlying platform of the blockchain, the platform product service layer, and the application service layer.

进一步的,在一些实施例中,在对SQL语句进行优化之后,还包括:从SQL性能优化参数表中获取优化SQL语句时采用的数据结构原理和相关解释说明,再将SQL语句的优化结果、采用的数据结构原理和相关解释说明一并输出。Further, in some embodiments, after optimizing the SQL statement, the method further includes: obtaining the data structure principle and related explanations used when optimizing the SQL statement from the SQL performance optimization parameter table, and then comparing the optimization result, The adopted data structure principle and related explanations are output together.

需要说明的是,数据结构原理和相关解释说明均在构建SQL性能优化参数表时,预先输入至SQL性能优化参数表中。It should be noted that the data structure principle and related explanations are input into the SQL performance optimization parameter table in advance when constructing the SQL performance optimization parameter table.

本实施例通过将SQL语句的优化结果、以及SQL性能优化参数表中优化该SQL语句时采用的数据结构原理和相关解释说明一并输出,帮助开发人员理解和学习,提升开发人员SQL知识储备的。In this embodiment, the optimization result of the SQL statement, the data structure principle and related explanations used in optimizing the SQL statement in the SQL performance optimization parameter table are output together, so as to help developers understand and learn, and improve the SQL knowledge reserves of developers. .

图2是本发明第二实施例的SQL语句性能优化方法的流程示意图。需注意的是,若有实质上相同的结果,本发明的方法并不以图2所示的流程顺序为限。如图2所示,该方法包括步骤:FIG. 2 is a schematic flowchart of a method for optimizing SQL statement performance according to a second embodiment of the present invention. It should be noted that, if there is substantially the same result, the method of the present invention is not limited to the sequence of the processes shown in FIG. 2 . As shown in Figure 2, the method includes the steps:

步骤S201:获取用户输入的SQL语句的执行计划。Step S201: Obtain the execution plan of the SQL statement input by the user.

在本实施例中,图2中的步骤S201和图1中的步骤S101类似,为简约起见,在此不再赘述。In this embodiment, step S201 in FIG. 2 is similar to step S101 in FIG. 1 , and for the sake of brevity, details are not repeated here.

步骤S202:根据执行计划评价SQL语句的性能值。当性能值未达到第一预设性能阈值时,执行步骤S203~步骤S204。当性能值超过第二预设性能阈值时,执行步骤S205~步骤S206。Step S202: Evaluate the performance value of the SQL statement according to the execution plan. When the performance value does not reach the first preset performance threshold, steps S203 to S204 are performed. When the performance value exceeds the second preset performance threshold, steps S205 to S206 are performed.

在本实施例中,图2中的步骤S202和图1中的步骤S102类似,为简约起见,在此不再赘述。In this embodiment, step S202 in FIG. 2 is similar to step S102 in FIG. 1 , and for the sake of brevity, details are not repeated here.

步骤S203:对SQL语句进行压力测试,确定SQL语句的待优化点。Step S203: Perform stress testing on the SQL statement to determine the point to be optimized of the SQL statement.

在本实施例中,图2中的步骤S203和图1中的步骤S103类似,为简约起见,在此不再赘述。In this embodiment, step S203 in FIG. 2 is similar to step S103 in FIG. 1 , and for the sake of brevity, details are not repeated here.

步骤S204:基于SQL语句和待优化点查询预先设置好的SQL性能优化参数表,以对SQL语句进行优化。Step S204 : query the preset SQL performance optimization parameter table based on the SQL statement and the point to be optimized, so as to optimize the SQL statement.

在本实施例中,图2中的步骤S204和图1中的步骤S104类似,为简约起见,在此不再赘述。In this embodiment, step S204 in FIG. 2 is similar to step S104 in FIG. 1 , and for the sake of brevity, details are not repeated here.

步骤S205:获取开发人员输入的SQL语句的数据结构原理和原理解释说明。Step S205: Obtain the data structure principle and principle explanation of the SQL statement input by the developer.

需要说明的是,第二预设性能阈值预先设定,且大于第一预设性能阈值。It should be noted that the second preset performance threshold is preset and greater than the first preset performance threshold.

在步骤S205中,当SQL语句的性能值高于第二预设性能阈值时,说明该SQL语句的性能优良,可以将其样例以供参考,因此,需要开发人员输入该SQL语句的数据结构原理和原理解释说明,作为后续优化SQL语句的参考和建议,在其他开发人员看到该数据结构原理和原理解释说明时,也能够帮助其他开发人员理解该SQL语句。In step S205, when the performance value of the SQL statement is higher than the second preset performance threshold, it indicates that the performance of the SQL statement is excellent, and its sample can be used for reference. Therefore, the developer needs to input the data structure of the SQL statement The principle and principle explanation, as a reference and suggestion for subsequent optimization of the SQL statement, can also help other developers understand the SQL statement when they see the data structure principle and principle explanation.

步骤S206:将数据结构原理和原理解释说明与SQL语句对应后,写入SQL性能优化参数表。Step S206: After the data structure principle and principle explanation are corresponding to the SQL statement, write the SQL performance optimization parameter table.

在步骤S206中,将该SQL语句、与之对应的数据结构原理和原理解释说明均写入SQL性能优化参数表,从而丰富SQL性能优化参数表中的样例。需要说明的是,当SQL性能优化参数表存在该SQL语句的样例时,不需要再次写入。In step S206, the SQL statement, the corresponding data structure principle and principle explanation are all written into the SQL performance optimization parameter table, thereby enriching the samples in the SQL performance optimization parameter table. It should be noted that when there is a sample of the SQL statement in the SQL performance optimization parameter table, it does not need to be written again.

本发明第二实施例的SQL语句性能优化方法在第一实施例的基础上,当SQL语句的性能高于该第二预设性能阈值时,则可认为该SQL语句的性能优良,因此,当SQL语句的性能超过第二预设性能阈值时,提醒开发人员输入该SQL语句的数据结构原理和原理解释说明,并将该SQL语句作为样例写入所述SQL性能优化参数表,作为后续优化相似SQL语句的建议,以供其他开发人员参考和学习。On the basis of the first embodiment, the SQL statement performance optimization method according to the second embodiment of the present invention, when the performance of the SQL statement is higher than the second preset performance threshold, it can be considered that the performance of the SQL statement is excellent. Therefore, when the performance of the SQL statement is higher than the second preset performance threshold When the performance of the SQL statement exceeds the second preset performance threshold, the developer is reminded to input the data structure principle and principle explanation of the SQL statement, and the SQL statement is written as a sample into the SQL performance optimization parameter table as a follow-up optimization Suggestions of similar SQL statements for reference and learning by other developers.

图3是本发明第三实施例的SQL语句性能优化方法的流程示意图。需注意的是,若有实质上相同的结果,本发明的方法并不以图3所示的流程顺序为限。如图3所示,该方法包括步骤:FIG. 3 is a schematic flowchart of a method for optimizing SQL statement performance according to a third embodiment of the present invention. It should be noted that, if there is substantially the same result, the method of the present invention is not limited to the flow sequence shown in FIG. 3 . As shown in Figure 3, the method includes the steps:

步骤S301:获取用户输入的SQL语句的执行计划。Step S301: Obtain the execution plan of the SQL statement input by the user.

在本实施例中,图3中的步骤S301和图1中的步骤S101类似,为简约起见,在此不再赘述。In this embodiment, step S301 in FIG. 3 is similar to step S101 in FIG. 1 , and for the sake of brevity, details are not repeated here.

步骤S302:根据执行计划评价SQL语句的性能值。Step S302: Evaluate the performance value of the SQL statement according to the execution plan.

在本实施例中,图3中的步骤S302和图1中的步骤S102类似,为简约起见,在此不再赘述。In this embodiment, step S302 in FIG. 3 is similar to step S102 in FIG. 1 , and for the sake of brevity, details are not repeated here.

步骤S303:当性能值未达到第一预设性能阈值时,对SQL语句进行压力测试,确定SQL语句的待优化点。Step S303: When the performance value does not reach the first preset performance threshold, perform a stress test on the SQL statement to determine the point to be optimized of the SQL statement.

在本实施例中,图3中的步骤S303和图1中的步骤S103类似,为简约起见,在此不再赘述。In this embodiment, step S303 in FIG. 3 is similar to step S103 in FIG. 1 , and for the sake of brevity, details are not repeated here.

步骤S304:基于SQL语句和待优化点查询预先设置好的SQL性能优化参数表,以对SQL语句进行优化。Step S304 : query the preset SQL performance optimization parameter table based on the SQL statement and the point to be optimized, so as to optimize the SQL statement.

在本实施例中,图3中的步骤S304和图1中的步骤S104类似,为简约起见,在此不再赘述。In this embodiment, step S304 in FIG. 3 is similar to step S104 in FIG. 1 , and for the sake of brevity, details are not repeated here.

步骤S305:记录SQL语句的优化记录,生成优化后的SQL语句的执行计划,并存储至高速缓存。需要说明的是,该高速缓存预先设置,用于存储SQL语句的执行计划。优化记录可以记录SQL语句是否进行过优化。Step S305: Record the optimization record of the SQL statement, generate an execution plan of the optimized SQL statement, and store it in the cache. It should be noted that the cache is preset to store the execution plan of the SQL statement. The optimization record can record whether the SQL statement has been optimized.

在步骤S305中,在对SQL语句进行优化之后,记录该SQL语句的优化记录,并且,需要重新生成优化后的SQL语句的执行计划,此时可以查询SQL语句的优化记录以确认该SQL语句是否是第一次优化,若是第一次优化,则生成优化后的SQL语句的执行计划,并将该执行计划保存至高速缓存中,若不是第一次优化,则可直接从高速缓存中查询对应的执行计划,而不需要重新生成。In step S305, after the SQL statement is optimized, the optimization record of the SQL statement is recorded, and the execution plan of the optimized SQL statement needs to be regenerated. At this time, the optimization record of the SQL statement can be queried to confirm whether the SQL statement is It is the first optimization. If it is the first optimization, the execution plan of the optimized SQL statement will be generated, and the execution plan will be saved in the cache. If it is not the first optimization, the corresponding query can be directly obtained from the cache. The execution plan does not need to be regenerated.

进一步的,优化记录还可用于记录SQL语句的优化结果,当开发人员输入SQL语句之后,查询是否存在该SQL语句的优化记录,若存在,则直接按照优化记录对SQL语句进行优化,再从高速缓存中查询该SQL语句对应的执行计划,并按照该执行计划执行该SQL语句,不需要再次对该SQL语句进行优化,避免重复的优化过程占用过多资源。本发明第三实施例的SQL语句性能优化方法在第一实施例的基础上,通过将SQL语句的优化记录,以及优化后的SQL语句的执行计划存储,在后续执行相同的SQL语句时,可直接按照优化记录对SQL语句进行优化,通知直接调用执行计划,不需要再解析优化后的SQL语句,提升了SQL语句的查询效率,同时避免重复的优化过程占用过多资源。Further, the optimization record can also be used to record the optimization result of the SQL statement. After the developer enters the SQL statement, it is queried whether there is an optimization record of the SQL statement. The execution plan corresponding to the SQL statement is queried in the cache, and the SQL statement is executed according to the execution plan, and the SQL statement does not need to be optimized again, so as to avoid the repeated optimization process occupying too many resources. On the basis of the first embodiment, the SQL statement performance optimization method according to the third embodiment of the present invention stores the optimization record of the SQL statement and the execution plan of the optimized SQL statement. The SQL statement is optimized directly according to the optimization record, and the execution plan is notified to be called directly, and the optimized SQL statement does not need to be parsed, which improves the query efficiency of the SQL statement and avoids the repeated optimization process occupying too many resources.

图4是本发明实施例的SQL语句性能优化装置的功能模块示意图。如图4所示,该装置40包括获取模块41、评价模块42、测试模块43和优化模块44。FIG. 4 is a schematic diagram of functional modules of an apparatus for optimizing SQL statement performance according to an embodiment of the present invention. As shown in FIG. 4 , the apparatus 40 includes an acquisition module 41 , an evaluation module 42 , a testing module 43 and an optimization module 44 .

获取模块41,用于获取用户输入的SQL语句的执行计划;Obtaining module 41, for obtaining the execution plan of the SQL statement input by the user;

评价模块42,用于根据执行计划评价SQL语句的性能值;The evaluation module 42 is used for evaluating the performance value of the SQL statement according to the execution plan;

测试模块43,用于当性能值未达到第一预设性能阈值时,对SQL语句进行压力测试,确定SQL语句的待优化点;A test module 43, configured to perform a stress test on the SQL statement when the performance value does not reach the first preset performance threshold, and determine the point to be optimized of the SQL statement;

优化模块44,用于基于SQL语句和待优化点查询预先设置好的SQL性能优化参数表,以对SQL语句进行优化。The optimization module 44 is configured to query a preset SQL performance optimization parameter table based on the SQL statement and the point to be optimized, so as to optimize the SQL statement.

可选地,测试模块43对SQL语句进行压力测试,确定SQL语句的待优化点的操作还可以为:从SQL语句中获取表字段DDL相关信息,以确认目标表;通过预设的模拟数据生成器生成预设数量的目标表的模拟数据;根据模拟数据测试SQL语句,并输出SQL语句的待优化点。Optionally, the test module 43 performs a stress test on the SQL statement, and the operation of determining the point to be optimized of the SQL statement can also be: obtaining the table field DDL related information from the SQL statement to confirm the target table; The generator generates a preset number of simulated data of the target table; tests the SQL statement according to the simulated data, and outputs the to-be-optimized point of the SQL statement.

可选地,评价模块42根据执行计划评价SQL语句的性能值的操作还可以为根据SQL语句执行时的消耗资源、访问表的方式以及表的连接顺序和连接方式评估SQL语句,得到性能值。Optionally, the operation of evaluating the performance value of the SQL statement by the evaluation module 42 according to the execution plan may also be to evaluate the SQL statement according to the consumption of resources during the execution of the SQL statement, the way of accessing the table, and the connection sequence and connection method of the table to obtain the performance value.

可选地,评价模块42根据执行计划评价SQL语句的性能值的操作之后,当性能值超过第二预设性能阈值时,还用于获取开发人员输入的SQL语句的数据结构原理和原理解释说明;将数据结构原理和原理解释说明与SQL语句对应后,写入SQL性能优化参数表。Optionally, after the evaluation module 42 evaluates the performance value of the SQL statement according to the execution plan, when the performance value exceeds the second preset performance threshold, it is also used to obtain the data structure principle and principle explanation of the SQL statement input by the developer. ; After corresponding the data structure principle and principle explanation with the SQL statement, write it into the SQL performance optimization parameter table.

可选地,优化模块44对SQL语句进行优化操作之后,还用于记录SQL语句的优化记录,生成优化后的SQL语句的执行计划,并存储至高速缓存。Optionally, after the optimization module 44 performs the optimization operation on the SQL statement, it is further configured to record the optimization record of the SQL statement, generate an execution plan of the optimized SQL statement, and store it in the cache.

可选地,优化模块44对SQL语句进行优化操作之后,还用于对优化后的SQL语句再次进行压力测试,以检测待优化点是否已被优化;若否,则记录SQL语句,并将SQL语句待优化点上报。Optionally, after the optimization module 44 performs the optimization operation on the SQL statement, it is also used to perform a stress test on the optimized SQL statement again to detect whether the point to be optimized has been optimized; The statement is reported to the optimization point.

可选地,优化模块44对SQL语句进行优化操作之后,还用于将优化后的所述SQL语句上传至区块链中。Optionally, after optimizing the SQL statement, the optimization module 44 is further configured to upload the optimized SQL statement to the blockchain.

请参阅图5,图5为本发明实施例的终端的结构示意图。如图5所示,该终端60包括处理器61及和处理器61耦接的存储器62。Please refer to FIG. 5 , which is a schematic structural diagram of a terminal according to an embodiment of the present invention. As shown in FIG. 5 , the terminal 60 includes a processor 61 and a memory 62 coupled to the processor 61 .

存储器62存储有用于实现上述任一实施例所述的SQL语句性能优化方法的程序指令。The memory 62 stores program instructions for implementing the SQL statement performance optimization method described in any of the foregoing embodiments.

处理器61用于执行存储器62存储的程序指令以对SQL语句进行优化。The processor 61 is configured to execute program instructions stored in the memory 62 to optimize the SQL statement.

其中,处理器61还可以称为CPU(Central Processing Unit,中央处理单元)。处理器61可能是一种集成电路芯片,具有信号的处理能力。处理器61还可以是通用处理器、数字信号处理器(DSP)、专用集成电路(ASIC)、现场可编程门阵列(FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。The processor 61 may also be referred to as a CPU (Central Processing Unit, central processing unit). The processor 61 may be an integrated circuit chip with signal processing capability. The processor 61 may also be a general purpose processor, digital signal processor (DSP), application specific integrated circuit (ASIC), field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components . A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.

参阅图6,图6为本发明实施例的存储介质的结构示意图。本发明实施例的存储介质存储有能够实现上述所有方法的程序文件71,其中,该程序文件71可以以软件产品的形式存储在上述存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器(processor)执行本申请各个实施方式所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质,或者是计算机、服务器、手机、平板等终端设备。Referring to FIG. 6, FIG. 6 is a schematic structural diagram of a storage medium according to an embodiment of the present invention. The storage medium of the embodiment of the present invention stores a program file 71 capable of implementing all the above methods, wherein the program file 71 may be stored in the above-mentioned storage medium in the form of a software product, and includes several instructions to enable a computer device (which can be A personal computer, a server, or a network device, etc.) or a processor (processor) executes all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes , or terminal devices such as computers, servers, mobile phones, and tablets.

在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are only illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, for example, multiple units or components may be combined or integrated. to another system, or some features can be ignored, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in electrical, mechanical or other forms.

另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。以上仅为本申请的实施方式,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware, or may be implemented in the form of software functional units. The above are only the embodiments of the present application, and are not intended to limit the scope of the patent of the present application. Any equivalent structure or equivalent process transformation made by using the contents of the description and drawings of the present application, or directly or indirectly applied in other related technical fields, All are similarly included in the scope of patent protection of the present application.

Claims (10)

1.一种SQL语句性能优化方法,其特征在于,包括:1. a SQL statement performance optimization method, is characterized in that, comprises: 获取用户输入的SQL语句的执行计划;Get the execution plan of the SQL statement entered by the user; 根据所述执行计划评价所述SQL语句的性能值;Evaluate the performance value of the SQL statement according to the execution plan; 当所述性能值未达到第一预设性能阈值时,对所述SQL语句进行压力测试,确定所述SQL语句的待优化点;When the performance value does not reach the first preset performance threshold, perform a stress test on the SQL statement to determine the point to be optimized of the SQL statement; 基于所述SQL语句和所述待优化点查询预先设置好的SQL性能优化参数表,以对所述SQL语句进行优化。The preset SQL performance optimization parameter table is queried based on the SQL statement and the point to be optimized, so as to optimize the SQL statement. 2.根据权利要求1所述的SQL语句性能优化方法,其特征在于,所述对所述SQL语句进行压力测试,确定所述SQL语句的待优化点包括:2. The SQL statement performance optimization method according to claim 1, wherein the stress test is performed on the SQL statement, and determining the point to be optimized of the SQL statement comprises: 从所述SQL语句中获取表字段DDL相关信息,以确认目标表;Obtain table field DDL related information from the SQL statement to confirm the target table; 通过预设的模拟数据生成器生成预设数量的所述目标表的模拟数据;Generate a preset number of simulation data of the target table through a preset simulation data generator; 根据所述模拟数据测试所述SQL语句,并输出所述SQL语句的待优化点。The SQL statement is tested according to the simulated data, and the to-be-optimized point of the SQL statement is output. 3.根据权利要求1所述的SQL语句性能优化方法,其特征在于,所述根据所述执行计划评价所述SQL语句的性能值,包括:3. The SQL statement performance optimization method according to claim 1, wherein the evaluating the performance value of the SQL statement according to the execution plan comprises: 根据所述SQL语句执行时的消耗资源、访问表的方式以及表的连接顺序和连接方式评估所述SQL语句,得到所述性能值。The performance value is obtained by evaluating the SQL statement according to the resource consumption when the SQL statement is executed, the way of accessing the table, and the connection sequence and connection mode of the table. 4.根据权利要求1所述的SQL语句性能优化方法,其特征在于,所述根据所述执行计划评价所述SQL语句的性能值之后,还包括:4. The SQL statement performance optimization method according to claim 1, wherein after evaluating the performance value of the SQL statement according to the execution plan, the method further comprises: 当所述性能值超过第二预设性能阈值时,获取开发人员输入的所述SQL语句的数据结构原理和原理解释说明;When the performance value exceeds the second preset performance threshold, obtain the data structure principle and principle explanation of the SQL statement input by the developer; 将所述数据结构原理和原理解释说明与所述SQL语句对应后,写入所述SQL性能优化参数表。After the data structure principle and principle explanation are corresponding to the SQL statement, write the SQL performance optimization parameter table. 5.根据权利要求1所述的SQL语句性能优化方法,其特征在于,所述对所述SQL语句进行优化之后,还包括:5. The SQL statement performance optimization method according to claim 1, characterized in that, after the described SQL statement is optimized, further comprising: 记录所述SQL语句的优化记录,生成所述优化后的SQL语句的执行计划,并存储至高速缓存。An optimization record of the SQL statement is recorded, an execution plan of the optimized SQL statement is generated, and stored in a cache. 6.根据权利要求1所述的SQL语句性能优化方法,其特征在于,所述对所述SQL语句进行优化之后,还包括:6. The SQL statement performance optimization method according to claim 1, characterized in that, after the described SQL statement is optimized, further comprising: 对优化后的SQL语句再次进行压力测试,以检测所述待优化点是否已被优化;Perform a stress test again on the optimized SQL statement to detect whether the to-be-optimized point has been optimized; 若否,则记录所述SQL语句,并将所述SQL语句所述所述待优化点上报。If not, the SQL statement is recorded, and the to-be-optimized point of the SQL statement is reported. 7.根据权利要求1所述的SQL语句性能优化方法,其特征在于,所述对所述SQL语句进行优化之后,还包括:7. The SQL statement performance optimization method according to claim 1, characterized in that, after the described SQL statement is optimized, further comprising: 将优化后的所述SQL语句上传至区块链中。Upload the optimized SQL statement to the blockchain. 8.一种SQL语句性能优化装置,其特征在于,包括:8. A device for optimizing SQL statement performance, comprising: 获取模块,用于获取用户输入的SQL语句的执行计划;The acquisition module is used to acquire the execution plan of the SQL statement input by the user; 评价模块,用于根据所述执行计划评价所述SQL语句的性能值;an evaluation module, configured to evaluate the performance value of the SQL statement according to the execution plan; 测试模块,用于当所述性能值未达到第一预设性能阈值时,对所述SQL语句进行压力测试,确定所述SQL语句的待优化点;a test module, configured to perform a stress test on the SQL statement when the performance value does not reach the first preset performance threshold, and determine the point to be optimized of the SQL statement; 优化模块,用于基于所述SQL语句和所述待优化点查询预先设置好的SQL性能优化参数表,以对所述SQL语句进行优化。An optimization module, configured to query a preset SQL performance optimization parameter table based on the SQL statement and the point to be optimized, so as to optimize the SQL statement. 9.一种终端,其特征在于,所述终端包括处理器、与所述处理器耦接的存储器,其中,9. A terminal, characterized in that the terminal comprises a processor and a memory coupled to the processor, wherein, 所述存储器存储有用于实现如权利要求1-7中任一项所述的SQL语句性能优化方法的程序指令;The memory stores program instructions for implementing the method for optimizing SQL statement performance according to any one of claims 1-7; 所述处理器用于执行所述存储器存储的所述程序指令以对SQL语句进行优化。The processor is configured to execute the program instructions stored in the memory to optimize SQL statements. 10.一种存储介质,其特征在于,存储有能够实现如权利要求1-7中任一项所述的SQL语句性能优化方法的程序文件。10 . A storage medium, characterized in that a program file capable of implementing the method for optimizing the performance of an SQL statement according to any one of claims 1 to 7 is stored. 11 .
CN202010910839.4A 2020-09-02 2020-09-02 SQL statement performance optimization method, device, terminal and storage medium Pending CN112035513A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010910839.4A CN112035513A (en) 2020-09-02 2020-09-02 SQL statement performance optimization method, device, terminal and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010910839.4A CN112035513A (en) 2020-09-02 2020-09-02 SQL statement performance optimization method, device, terminal and storage medium

Publications (1)

Publication Number Publication Date
CN112035513A true CN112035513A (en) 2020-12-04

Family

ID=73591219

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010910839.4A Pending CN112035513A (en) 2020-09-02 2020-09-02 SQL statement performance optimization method, device, terminal and storage medium

Country Status (1)

Country Link
CN (1) CN112035513A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115544064A (en) * 2022-11-24 2022-12-30 中国电子信息产业集团有限公司 Data optimization method and device based on custom optimization rule
CN117290377A (en) * 2023-09-28 2023-12-26 北京领雁科技股份有限公司 Method and device for converting SQL sentences among relational databases

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090077016A1 (en) * 2007-09-14 2009-03-19 Oracle International Corporation Fully automated sql tuning
CN105224458A (en) * 2015-10-09 2016-01-06 上海瀚银信息技术有限公司 A kind of database method of testing and system
CN105989137A (en) * 2015-02-27 2016-10-05 中国移动通信集团河北有限公司 Structured query language performance optimization method and system
CN108197306A (en) * 2018-01-30 2018-06-22 平安科技(深圳)有限公司 SQL statement processing method, device, computer equipment and storage medium
CN108519949A (en) * 2018-04-12 2018-09-11 郑州云海信息技术有限公司 A pressure testing method, system and device for an ORACLE database
CN110287114A (en) * 2019-06-26 2019-09-27 深圳前海微众银行股份有限公司 Method and device for database script performance testing

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090077016A1 (en) * 2007-09-14 2009-03-19 Oracle International Corporation Fully automated sql tuning
CN105989137A (en) * 2015-02-27 2016-10-05 中国移动通信集团河北有限公司 Structured query language performance optimization method and system
CN105224458A (en) * 2015-10-09 2016-01-06 上海瀚银信息技术有限公司 A kind of database method of testing and system
CN108197306A (en) * 2018-01-30 2018-06-22 平安科技(深圳)有限公司 SQL statement processing method, device, computer equipment and storage medium
CN108519949A (en) * 2018-04-12 2018-09-11 郑州云海信息技术有限公司 A pressure testing method, system and device for an ORACLE database
CN110287114A (en) * 2019-06-26 2019-09-27 深圳前海微众银行股份有限公司 Method and device for database script performance testing

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115544064A (en) * 2022-11-24 2022-12-30 中国电子信息产业集团有限公司 Data optimization method and device based on custom optimization rule
CN117290377A (en) * 2023-09-28 2023-12-26 北京领雁科技股份有限公司 Method and device for converting SQL sentences among relational databases

Similar Documents

Publication Publication Date Title
US11163744B2 (en) Test data generation and scale up for database testing using unique common factor sequencing
US20080243779A1 (en) Integration of predefined multi-dimensional and flexibly-ordered dynamic search interfaces
US9195730B2 (en) Verifying correctness of a database system via extended access paths
CN110959153A (en) Application analysis using flexible post-processing
CN106991116A (en) The optimization method and device of database executive plan
CN110968495A (en) A method and device for evaluating the performance of a container cloud platform
US8850407B2 (en) Test script generation
CN112035513A (en) SQL statement performance optimization method, device, terminal and storage medium
CN116450496A (en) System performance test method, device, computer equipment and storage medium
CN116610700A (en) Query statement detection method and device and storage medium
CN116204396A (en) Test method and device for performance of analytical database
CN112380127B (en) Test case regression method, device, equipment and storage medium
CN114238085A (en) Interface testing method and device, computer equipment and storage medium
US20240134888A1 (en) User interface for providing an entity relationship diagram
CN118885405A (en) Database testing method and device
WO2024167773A1 (en) Systems and methods for heterogeneous data analysis
CN115239088A (en) Method and device for determining power engineering safety quality evaluation index weight
CN115292178A (en) Test data searching method, device, storage medium and terminal
Chen et al. Testing of big data analytics systems by benchmark
CN112559331A (en) Test method and device
CN118296001B (en) Data query method, device, computer equipment, storage medium and program product
US20250315618A1 (en) Grounding automatically-generated responses produced by a q&a system
CN120278095B (en) DRC test result verification method, device, equipment and storage medium
CN120780723A (en) Database operation statement generation method, device, equipment and storage medium
CN117453703A (en) Test method, apparatus, device, medium and program product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20201204