Database operation statement analysis method, storage medium and computer device

By analyzing the subquery structure of database operation statements and skipping steps that do not require optimization, the problem of excessively long subquery optimization time in UNION ALL statements is solved, thereby improving database execution efficiency and reducing resource consumption.

CN117171197BActive Publication Date: 2025-11-07CETC JINCANG (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311335502.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-16
Publication Date
2025-11-07
Estimated Expiration
2043-10-16

AI Technical Summary

Technical Problem

When optimizing subqueries in a UNION ALL statement, existing techniques require analyzing each subquery individually, resulting in excessively long planning times. This is especially true when dealing with multiple UNION ALL queries, where the time cost increases exponentially, and ineffective optimization measures may also exist.

Method used

By retrieving subqueries from database operation statements layer by layer, the target judgment conditions are determined based on the structure of the subqueries. Steps that do not require subquery optimization are skipped, including determining whether the subquery contains specific keywords and the data table being queried. The results are returned directly to avoid ineffective optimization.

Benefits of technology

It improves database execution speed, reduces resource consumption, and shortens the time required to generate execution plans.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117171197B_ABST
    Figure CN117171197B_ABST
Patent Text Reader

Abstract

The application provides a database operation statement analysis method, a storage medium and a computer device. The method comprises the following steps: obtaining a database operation statement; layer by layer obtaining a subquery statement included in the database operation statement; determining a target judgment condition to be taken according to the structure of the subquery statement; and in the case that the structure of the subquery statement meets the target judgment condition, judging that the subquery statement does not need to be subjected to subquery optimization and skipping the subquery optimization step. Through the above method, each subquery statement in the database operation statement is analyzed, and the subquery optimization step is skipped for the subquery statement meeting the judgment condition, so that invalid optimization measures are avoided, the database execution speed is improved, the time for generating an execution plan is reduced, and the resource consumption of the database is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of database, in particular to a database operation statement analysis method, a storage medium and a computer device. BACKGROUND

[0002] Currently, when the KES database processes the UNION ALL statement, the left and right sub-queries may need to be promoted, but the content of the sub-query must be obtained first, and whether the sub-query can be promoted is analyzed one by one, for example:

[0003] Select * from (select * from test1 where a in (select b from test2));

[0004] The sub-query can be optimized into a table join form, if the sub-query is used as the left and right sub-query content of the union all statement, further reading is needed, that is, recursively entering the sub-query and executing the sub-query optimization.

[0005] In the process of sub-query optimization of the UNION ALL statement, the plan time is relatively long when reading and analyzing the content of the sub-query and constructing the related data structure of the sub-query optimization; if the query statement with multiple UNION ALL is processed, the time cost is multiplied by the number of UNION ALL.

[0006] When there is, for example:

[0007] (Select * from test1) union all (Select * from test2) union all(Select * from test3);

[0008] At this time, the content of the sub-query in the statement does not need to be processed by the sub-query optimization, if the "simple sub-query" which does not need the sub-query optimization is judged in advance, it is directly returned, thus most of the plan time is saved. SUMMARY

[0009] An object of the present application is to avoid invalid optimization measures.

[0010] A further object of the present application is to improve the database execution speed.

[0011] In particular, the present application provides a database operation statement analysis method, which comprises:

[0012] obtaining a database operation statement;

[0013] obtaining a sub-query statement included in the database operation statement layer by layer;

[0014] determining a target judging condition to be taken according to the structure of the subquery statement;

[0015] in the case that the structure of the subquery statement meets the target judging condition, judging that the subquery statement does not need to be optimized and skipping the step of subquery optimization.

[0016] Optionally, the step of determining a target judging condition to be taken according to the structure of the subquery statement comprises:

[0017] in the case that the subquery statement is composed of multiple subquery statement clauses which are connected in parallel by a first keyword, judging the multiple subquery statement clauses one by one according to a first judging condition, the first keyword comprising UNION ALL;

[0018] in the case that all the subquery statement clauses meet the first judging condition, judging that the subquery statement meets the first judging condition.

[0019] Optionally, the step of judging the multiple subquery statement clauses one by one according to a first judging condition comprises:

[0020] judging whether a second keyword exists in the subquery statement clause, the second keyword comprising WHERE;

[0021] in the case that the second keyword does not exist in the subquery statement clause, judging whether a third keyword exists in the subquery statement clause, the third keyword comprising FROM;

[0022] in the case that the third keyword does not exist in the subquery statement clause, judging that the subquery statement clause meets the first judging condition.

[0023] Optionally, the step of judging whether a third keyword exists in the subquery statement clause further comprises:

[0024] in the case that the third keyword exists in the subquery statement clause, judging whether the subquery statement clause only queries a single data table;

[0025] in the case that the subquery statement clause only queries a single data table, judging that the subquery statement clause meets the first judging condition.

[0026] Optionally, the step of judging whether the subquery statement clause only queries a single data table further comprises:

[0027] in the case that the subquery statement clause does not only query a single data table, judging whether the content contained after the third keyword contains the first keyword and meets the first judging condition;

[0028] In a case where the content contained after the third keyword does not contain the first keyword and meets the first judging condition, it is determined that the subquery statement meets the first judging condition.

[0029] Optionally, the step of determining the target judging condition to be taken according to the structure of the subquery statement further comprises:

[0030] In a case where the subquery statement is a single database query statement, it is judged whether the subquery statement meets the second judging condition;

[0031] If yes, it is determined that the subquery statement meets the target judging condition.

[0032] Optionally, the step of judging whether the outer layer of the subquery statement meets the second judging condition comprises:

[0033] It is judged whether the target value queried by the subquery statement is a column value of a data table;

[0034] In a case where the target value queried by the subquery statement is a column value of a data table, it is judged whether the target content queried by the subquery statement is only from the third keyword and whether the target content only comprises single data table information;

[0035] In a case where the target content queried by the subquery statement is only from the third keyword and the target content only comprises single data table information, it is judged whether the single data table information is from a single database query statement;

[0036] In a case where the single data table information is from a single database query statement, it is judged whether the single database query statement meets the second judging condition;

[0037] In a case where the single database query statement meets the second judging condition, it is determined that the subquery statement meets the second judging condition.

[0038] Optionally, the step of judging whether the target content queried by the subquery statement is only from the third keyword and whether the target content only comprises single data table information further comprises:

[0039] In a case where the target content queried by the subquery statement is only from the third keyword and the target content only comprises single data table information, it is judged whether the single data table information is from a UNION ALL joint table;

[0040] If yes, it is judged whether all query statements corresponding to the UNION ALL joint table meet the first judging condition;

[0041] In a case where all query statements corresponding to the UNION ALL joint table meet the first judging condition, it is determined that the subquery statement meets the second judging condition.

[0042] According to still another aspect of the present application, there is also provided a machine readable storage medium having stored thereon a machine executable program which, when executed by a processor, implements any of the above database operation statement analysis methods.

[0043] According to still another aspect of the present application, there is also provided a computer device comprising a memory, a processor, and a machine executable program stored on the memory and running on the processor, and the processor implements any of the above database operation statement analysis methods when executing the machine executable program.

[0044] The database operation statement analysis method of the present application analyzes the obtained database operation statement, obtains the subquery statement included in the database operation statement layer by layer, determines the target judgment condition to be taken according to the structure of the subquery statement, and determines that the subquery statement does not need to be optimized in the case that the structure of the subquery statement meets the target judgment condition, thereby skipping the subquery optimization step. By analyzing each subquery statement in the database operation statement and skipping the subquery optimization step for the subquery statement meeting the judgment condition, the present application avoids invalid optimization measures and improves the database execution speed.

[0045] The above and other objects, advantages and features of the present application will become more apparent from the following detailed description of some embodiments thereof, when taken in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS

[0046] Some embodiments of the present application will now be described in detail in the following description, with reference to the drawings, in which:

[0047] Figure 1 is a flowchart of a database operation statement analysis method according to an embodiment of the present application;

[0048] Figure 2 is a flowchart of a database operation statement analysis method according to another embodiment of the present application;

[0049] Figure 3 is a flowchart of a database operation statement analysis method according to still another embodiment of the present application;

[0050] Figure 4 is a schematic diagram of a machine readable storage medium in a database operation statement analysis method according to an embodiment of the present application; and

[0051] Figure 5 is a schematic diagram of a computer device in a database operation statement analysis method according to an embodiment of the present application. DETAILED DESCRIPTION

[0052] Those skilled in the art should understand that the embodiments described below are only a part of the embodiments of the present application, and are not the whole embodiments of the present application, and are intended to explain the technical principles of the present application, and not to limit the protection scope of the present application. Based on the embodiments provided by the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor should fall within the protection scope of the present application.

[0053] Figure 1 is a flowchart of an analysis method of a database operation statement according to an embodiment of the present application. In the present embodiment, the flowchart can generally include:

[0054] In step S101, a database operation statement is acquired.

[0055] In step S102, a subquery statement included in the database operation statement is acquired layer by layer. In the present embodiment, after the database receives the database operation statement, the database operation statement needs to be analyzed, and the analysis process is to split the database operation statement into a parse tree according to a keyword, each layer of the parse tree corresponds to a layer of subquery statement of the database operation statement, and by layer-by-layer analysis of the parse tree, the multi-layer nested database operation statement is split into multiple subquery statements for processing.

[0056] In step S103, a target judgment condition to be taken is determined according to the structure of the subquery statement. In some optional embodiments, each layer of subquery statement can include a parallel connection of subquery statement clauses through UNION ALL, or can be a single subquery statement, and different judgment conditions are needed to determine whether the subquery optimization is needed for different types of subquery statements.

[0057] In step S104, in the case where the structure of the subquery statement meets the target judgment condition, it is determined that the subquery optimization is not needed for the subquery statement, and the subquery optimization step is skipped.

[0058] By analyzing each subquery statement in the database operation statement through the method, the subquery statement meeting the judgment condition is skipped in the subquery optimization step, so as to avoid invalid optimization measures, improve the database execution speed, and reduce the resource consumption of the database.

[0059] In some optional embodiments, the step of determining the target judgment condition to be taken according to the structure of the subquery statement can generally include: in the case that the subquery statement is composed of multiple subquery statement clauses which are parallelly linked by a first keyword, judging the multiple subquery statement clauses one by one according to a first judgment condition, the first keyword including UNION ALL; in the case that all the subquery statement clauses meet the first judgment condition, determining that the subquery statement meets the first judgment condition. An optional example of the subquery statement can be: (Select …) union all (select …) union all …, and such a subquery statement contains multiple subquery statement clauses which are parallelly linked by union all.

[0060] In the present embodiment, the step of judging the multiple subquery statement clauses one by one according to the first judgment condition can generally include: judging whether the subquery statement clause contains a second keyword, the second keyword including where; in the case that the subquery statement clause does not contain the second keyword, judging whether the subquery statement clause contains a third keyword, the third keyword including from; in the case that the subquery statement clause does not contain the third keyword, determining that the subquery statement clause meets the first judgment condition. In the present embodiment, an optional example of the subquery statement can be: Select random() union all select random(), wherein random() is a function expression in the database. As can be seen from the above subquery statement, it contains two subquery statement clauses of Select random(), and neither of them contains the where keyword nor the from keyword, i.e. it is determined that the subquery statement clause meets the first judgment condition.

[0061] In the embodiment, the step of judging whether the third keyword exists in the subquery statement clause can further include: in the case that the third keyword exists in the subquery statement clause, judging whether the subquery statement clause queries only a single data table; and in the case that the subquery statement clause queries only a single data table, determining that the subquery statement clause meets the first judging condition. In the embodiment, an optional example of the subquery statement can be: Select * from test1 union all select * from test2. In the subquery statement, there are multiple subquery statement clauses connected in parallel by union all: Select * from test1 and select * from test2. When the above subquery statement clause does not have a where keyword but has a from keyword, it is determined whether the subquery statement clause queries only a single data table. As can be seen from the example, Select * from test1 does not have a where keyword but has a from keyword, and queries only a single data table test1; and select * from test2 also does not have a where keyword but has a from keyword, and queries only a single data table test2. Therefore, it is determined that the subquery statement clause meets the first judging condition.

[0062] In the embodiment, the step of judging whether the subquery statement sentence only queries a single data table can further comprise: in the case that the subquery statement sentence is not only querying a single data table, judging whether the content contained after the third keyword contains the first keyword and meets the first judging condition; in the case that the content contained after the third keyword does not contain the first keyword and meets the first judging condition, determining that the subquery statement sentence meets the first judging condition. An optional example of the subquery statement can be: Select * from (select a from test1) union all select * from (select random()); wherein the subquery statement is composed of the subquery statement sentences Select * from (select a from test1) and select * from (select random()) which are connected in parallel by UNION ALL. Wherein the two subquery statement sentences do not have the where keyword, but include the from keyword, and the query conditions of both are not only querying a single data table, thus, it is necessary to judge whether the query contents select a from test1 and select random() contain the UNION ALL keyword and meet the first judging condition. By judging that select a from test1 and select random() do not contain the UNION ALL keyword and meet the first judging condition, it is determined that Select * from (select a from test1) and select * from (select random()) both meet the first judging condition.

[0063] The step of determining the target judging condition to be taken according to the structure of the subquery statement can further comprise: in the case that the subquery statement is a single database query statement, judging whether the subquery statement meets the second judging condition; if yes, determining that the subquery statement meets the target judging condition. An example of the subquery statement meeting the step can be: Select * from (select a from test union all select * from (select random()); the outermost layer of the above subquery statement is a single database query statement Select * from (), and then it is judged whether the subquery statement meets the second judging condition, so as to determine whether the subquery statement needs to be subjected to the subquery optimization operation.

[0064] The step of judging whether the outer layer of the subquery statement meets the second judging condition can include: judging whether the target value queried by the subquery statement is a column value of the data table; in the case that the target value queried by the subquery statement is a column value of the data table, judging whether the target content queried by the subquery statement is only from the third keyword and whether the target content only includes single data table information; in the case that the target content queried by the subquery statement is only from the third keyword and the target content only includes single data table information, judging whether the single data table information is from a single database query statement; in the case that the single data table information is from a single database query statement, judging whether the single database query statement meets the second judging condition; and in the case that the single database query statement meets the second judging condition, judging that the subquery statement meets the second judging condition. In this embodiment, an optional example of a subquery statement can be: Select * from (select a from test). First, it is judged whether the target value queried by the subquery statement is a column value of the data table, and in this example, the target value is *, i.e., all column values of the data table. Then, the target content queried by the subquery statement is only from the result set content of from, which belongs to single data table information, and the target content is only from select a from test, so it is judged that this kind of subquery statement meets the second judging condition.

[0065] After the step of judging whether the target content queried by the subquery statement is only from the third keyword and whether the target content only includes single data table information, the method can further include: in the case that the target content queried by the subquery statement is only from the third keyword and the target content only includes single data table information, judging whether the single data table information is from a UNION ALL joint table; if yes, judging whether all query statements corresponding to the UNION ALL joint table meet the first judging condition; in the case that all query statements corresponding to the UNION ALL joint table meet the first judging condition, determining that the subquery statement meets the second judging condition. In this embodiment, an optional example of a subquery statement can be: Select * from (select a from test union all select * from test2); first, judging whether the target value queried by the subquery statement is a column value of a data table, in this example, the target value is *, i.e., all column values of the data table; then, judging whether the target content queried by the subquery statement is only from the result set content of from, which belongs to single data table information, and whether the target content is from select a from test union all select * from test2, i.e., whether the target content is a UNION ALL joint table; and then, judging whether the target content meets the first judging condition, and in the case that the target content meets the first judging condition, determining that the subquery statement meets the second judging condition.

[0066] It should be noted that the database operation statement, the subquery statement and the subquery statement clause in this embodiment are only used to represent the hierarchical relationship among them, and in the case that the database operation statement is multi-layer nested, a person skilled in the art can determine the relative relationship between each layer according to the actual situation.

[0067] Figure 2 FIG. 1 is a flow diagram of a method for analyzing a database operation statement according to another embodiment of the present application. In some optional embodiments, the method can generally include:

[0068] In step S201, a database operation statement is obtained. In this embodiment, an example of a database operation statement is: select a from test union all select random(). The following steps are the specific process of judging and analyzing the example.

[0069] Step S202, recursively traversing the contents of the UNION ALL subquery. In this embodiment, in the case of judging that the database operation statement is parallel linked by UNION ALL, recursively traverse the contents of each subquery, such as select a from test and select random().

[0070] Step S203, judging whether the subquery statement conforms to the following rules:

[0071] ① No where, no from scalar subquery;

[0072] ② No where, with from, but only query a single table;

[0073] ③ No where, with from, and the from content is a subquery conforming to the standards of ①②③ without union all clause. In this embodiment, in the process of judging select a from test, it can be judged that this subquery statement belongs to no where keyword, with from keyword and only query a single data table test, thus conforming to rule ②. In the process of judging select random(), it can be judged that this subquery statement has no where keyword and no from keyword, thus conforming to rule ①.

[0074] Step S204, in the case of judging yes in step S203, skipping the subquery optimization step for the subquery statement. In this embodiment, since step S203 judges that the two subquery statements conform to the rules, the above two subquery statements are skipped from the subquery optimization step, thus avoiding meaningless subquery optimization of the database.

[0075] Step S205, in the case of judging no in step S203, executing the subquery optimization step.

[0076] Step S206, in the case of executing step S204 or step S205, continuing to execute the subsequent operation.

[0077] Through the above method of analyzing each subquery statement in the database operation statement, the subquery statement conforming to the judgment condition is skipped from the subquery optimization step, thus avoiding invalid optimization measures, improving the database execution speed and reducing the resource consumption of the database.

[0078] Figure 3 is a flowchart of the analysis method of the database operation statement according to another embodiment of the present application. In some optional embodiments, the present flowchart can generally include:

[0079] In the embodiment, an example of a database operation statement is: select * from (select * from(select * from (select * from test1 union all select * from test2))). The following steps are the specific process of judgment analysis for the example.

[0080] In step S301, a database operation statement is processed. In the embodiment, after the analysis and processing of the above database operation statement, it is detected that the outer database operation statement is a single select query statement, and then the judgment operation of step S302 is performed on the outer database operation statement.

[0081] In step S302, it is judged whether the select query statement meets all the following rules:

[0082] (1) The target column is the column value in the query table.

[0083] (2) There is only a from clause, and only a single table element information is queried, wherein the single table element information can include: a basic table, a UNION ALL joint table, and a select subquery.

[0084] (3) If the single table element in (2) is a select subquery, it meets the conditions (1), (2), and (3).

[0085] In the embodiment, the outer query statement is select * from (), the target column is *, which means that all column values of the target column meet the condition (1); there is no where keyword and only a from keyword, and the from content is select * from () which is a select subquery, and the result is also a single table element information, which meets the condition (2); in the case that the single table element information is also a select subquery, it is further judged whether the inner select subquery meets the judgment condition in this step. After layer-by-layer judgment, it is finally judged that the single table element is a UNION ALL joint table, and the specific content is select * from test1 union all select * from test2. It is determined that the query statement meets all the rules in this step.

[0086] In step S303, if the result of step S302 is yes, the UNION ALL subquery content is recursively traversed. In this step, the query statement corresponding to the UNION ALL joint table obtained in step S302 is recursively traversed, and finally the UNION ALL subquery statements select * from test1 and select * from test2 are obtained.

[0087] Step S304, judging whether the subquery statement meets the following rules:

[0088] ① No where, no from scalar subquery;

[0089] ② No where, with from, but only query a single table;

[0090] ③ No where, with from, and the from content is a subquery meeting the rules ①, ② and ③ without union all clause.

[0091] In the embodiment, the UNION ALL subquery statement obtained in step S303 is judged respectively. Wherein select * from test1 belongs to no where keyword, with from keyword but the query content is a single table test1, meeting the rule ②; similarly, select * from test2 also meets the rule ②. Therefore, it is determined that the UNION ALL subquery statement meets the judgment condition.

[0092] Step S305, in the case of yes in step S304, the subquery statement skips the subquery optimization step. In the embodiment, when the UNION ALL subquery statement meets the judgment condition in step S304, it is indicated that the query statement does not need to be subquery optimized, so the subquery optimization step is skipped.

[0093] Step S306, in the case of no in step S302 or no in step S304, the subquery optimization step is executed.

[0094] Step S307, in the case of step S305 or step S306 being executed, the subsequent operation is continued.

[0095] Through the above method, each subquery statement in the database operation statement is analyzed, the subquery statement meeting the judgment condition is skipped from the subquery optimization step, so that the invalid optimization measures are avoided, the database execution speed is improved, the time for generating the execution plan is reduced, and the resource consumption of the database is reduced.

[0096] The embodiment also provides a machine readable storage medium and a computer device. Figure 4 Fig. 401 is a schematic diagram of the machine readable storage medium 401 according to an embodiment of the present application, Figure 5 Fig. 503 is a schematic diagram of the computer device 503 according to an embodiment of the present application.

[0097] The machine readable storage medium 401 has stored thereon machine executable programs 402 which, when executed by the processor, implement the method of analyzing the database operation statement of any of the above embodiments.

[0098] The computer device 503 can include the memory 501, the processor 502, and the machine executable programs 402 stored on the memory 501 and running on the processor 502, and the processor 502 implements the method of analyzing the database operation statement of any of the above embodiments when executing the machine executable programs 402.

[0099] It should be noted that the logic and / or steps represented in the flowcharts or otherwise described herein, such as layer-by-layer obtaining the subquery statements included in the database operation statement, can be embodied in any machine readable storage medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor- containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions, or in conjunction with which the instructions may

[0100] For the description of the present embodiment, the machine readable storage medium 401 can be any device that can contain, store, communicate, propagate or transport the program for use by or in connection with the instruction execution system, apparatus, or device, or in conjunction with which the instruction execution system, apparatus, or device is used. More specific examples (non-exhaustive list) of the machine readable storage medium 401 include the following: an electrical connection having one or more wires (electrical device), a portable computer diskette (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). In addition, the machine readable storage medium 401 can even be paper or another suitable medium upon which the program can be printed, as the program can be electronically obtained, for example, by optical scanning of the paper or other medium, followed by electronic

[0101] It should be understood that parts of the present application can be realized by hardware, software, firmware, or a combination thereof. In the above-described embodiments, a plurality of steps or methods can be realized by software or firmware stored in a memory and executed by a suitable instruction execution system.

[0102] The computer device 503 can be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smartphone. In some examples, the computer device 503 can be a cloud computing node. The computer device 503 can be described in the general context of computer system-executable instructions, such as program modules, being executed by a computer system. Generally, program modules can include routines, programs, objects, components, logic, data structures, and so on that perform particular tasks or implement particular abstract data types. The computer device 503 can be practiced in distributed cloud computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed cloud computing environment, program modules can be located in local or remote computer system storage media including memory storage devices.

[0103] The computer device 503 can include a processor 502 adapted to execute instructions stored in memory 501, which in operation provides temporary storage for the instructions during execution. The processor 502 can be a single core processor, multi-core processor, computing cluster, or any number of other configurations. The memory 501 can include random access memory (RAM), read only memory (ROM), flash memory, or any other suitable memory systems.

[0104] The processor 502 can be connected through a system interconnect (e.g., a PCI, PCI-Express, or other interconnect) to an I / O interface adapted to connect the computer device 503 to one or more I / O devices (input / output devices). The I / O devices can include, for example, a keyboard and a pointing device, where the pointing device can include a touchpad or touchscreen, among others. The I / O devices can be built-in components of the computer device 503, or can be devices externally connected to the computer device.

[0105] The processor 502 can also be linked through the system interconnect to a display interface adapted to connect the computer device 503 to a display device. The display device can include a display screen that is a built-in component of the computer device 503. The display device can also include a computer monitor, television, or projector, among others, that is externally connected to the computer device 503. Further, a network interface controller (NIC) can be adapted to connect the computer device 503 to a network through the system interconnect. In some embodiments, the NIC can use any suitable interface or protocol (such as Internet Small Computer Systems Interface, among others) to transfer data. The network can be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN), or the Internet, among others. Remote devices can be connected to the computer device through the network.

[0106] The flowcharts provided by the embodiments are not intended to indicate that the operations of the methods will be executed in any particular order, or that all of the operations of the methods are included in every case. In addition, the methods can include additional operations. Additional changes can be made to the above-described methods within the scope of the technical ideas provided by the embodiments.

[0107] Thus, those skilled in the art will recognize that the present application has been well- described and clearly demonstrated by way of example, and that many changes and modifications can be made thereto without departing from the spirit and scope of the application. It is therefore intended to cover in the appended claims all such changes and modifications that are within the scope of this application.

Claims

1. A method for analyzing a database operation statement, comprising: obtaining the database operation statement; obtaining subquery statements included in the database operation statement layer by layer; determining a target judgment condition to be taken according to a structure of the subquery statement; in a case where the structure of the subquery statement meets the target judgment condition, judging that the subquery statement does not need to be subjected to subquery optimization, and skipping the step of subquery optimization; the step of determining the target judgment condition to be taken according to the structure of the subquery statement comprises: in a case where the subquery statement is composed of multiple subquery statement clauses linked in parallel by a first keyword, judging whether the subquery statement clause exists a second keyword, the first keyword comprising UNION ALL, and the second keyword comprising where; if the second keyword does not exist, judging whether the subquery statement clause exists a third keyword, the third keyword comprising from; if the third keyword does not exist, judging that the subquery statement clause meets a first judgment condition; in a case where all the subquery statement clauses meet the first judgment condition, judging that the subquery statement meets the first judgment condition; the step of determining the target judgment condition to be taken according to the structure of the subquery statement further comprises: in a case where the subquery statement is a single database query statement, judging whether the subquery statement meets a second judgment condition; if yes, judging that the subquery statement meets the target judgment condition; the step of judging whether the subquery statement meets the second judgment condition comprises: judging whether a target value queried by the subquery statement is a column value of a data table; if the target value is the column value of the data table, judging whether a target content queried by the subquery statement is only from the third keyword, and whether the target content only comprises single data table information; if yes, judging whether the single data table information is from a single database query statement; if from the single database query statement, judging whether the single database query statement meets the second judgment condition; in a case where the single database query statement meets the second judgment condition, judging that the subquery statement meets the second judgment condition.

2. The method for analyzing the database operation statement according to claim 1, wherein, the step of judging whether the subquery statement clause exists the third keyword further comprises: in a case where the subquery statement clause exists the third keyword, judging whether the subquery statement clause only queries a single data table; in a case where the subquery statement clause only queries the single data table, judging that the subquery statement clause meets the first judgment condition.

3. The method for analyzing the database operation statement according to claim 2, wherein, the step of judging whether the subquery statement clause only queries the single data table further comprises: in a case where the subquery statement clause is not only to query the single data table, judging whether content included after the third keyword contains the first keyword and meets the first judgment condition; In a case where the content included after the third keyword does not include the first keyword and meets the first judgment condition, it is determined that the subquery statement meets the first judgment condition.

4. The database operation statement analysis method according to claim 1, wherein, The step of judging whether the target content queried by the subquery statement is only from the third keyword and whether the target content only includes single data table information further comprises: In a case where the target content queried by the subquery statement is only from the third keyword and the target content only includes single data table information, it is judged whether the single data table information is from a UNION ALL joint table; If yes, it is judged whether all query statements corresponding to the UNION ALL joint table meet the first judgment condition; In a case where all query statements corresponding to the UNION ALL joint table meet the first judgment condition, it is determined that the subquery statement meets a second judgment condition.

5. A machine readable storage medium having stored thereon a machine executable program which, when executed by a processor, implements the database operation statement analysis method according to any one of claims 1 to 4.

6. A computer device comprising a memory, a processor, and a machine executable program stored on the memory and running on the processor, and the processor implements the database operation statement analysis method according to any one of claims 1 to 4 when executing the machine executable program.

Citation Information

Patent Citations

  • Query statement optimization method and device, computer device and storage medium

    CN110688393A

  • Query statement optimization method and device, equipment and storage medium

    CN112732752A