Query statement processing method and related device
By identifying and deleting redundant sorting operations in multi-level queries in database systems, query efficiency is improved, and the inefficiency problem caused by the failure of existing optimizers to recognize cross-level redundancy is solved.
Patent Information
- Application Number
- CN202510630469.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-15
- Publication Date
- 2025-07-22
AI Technical Summary
In the database system, in scenarios involving multi-level queries, existing optimizers cannot recognize cross-level redundancy, resulting in low query efficiency.
By obtaining the sub-statements in the query statement, determining whether the sorting operation is redundant, and optimizing when determining the redundancy, deleting the redundant sorting operation, and obtaining the target query statement.
It effectively improves the query efficiency of query statements and reduces calculation overhead.
Smart Images

Figure CN120353818A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular, to a query statement processing method and related devices. Background Art
[0002] In a database system, query optimization is a core part of improving execution efficiency. For example, the computational overhead is reduced by eliminating duplicate sorting or invalid deduplication in query statements. However, in scenarios involving multi-level queries, the optimizer cannot identify cross-level redundancies, resulting in low query efficiency. Summary of the Invention
[0003] Embodiments of this application provide a query statement processing method and related devices for improving the query efficiency of query statements.
[0004] In a first aspect, embodiments of this application provide a query statement processing method, including:
[0005] Obtain a query statement to be processed;
[0006] When the query statement includes a sub-statement and the sub-statement includes a sorting operation, determine whether the sorting operation is a redundant operation;
[0007] If so, optimize the query statement according to the sorting operation to obtain a target query statement;
[0008] Execute the target query statement.
[0009] In some embodiments, the sub-statement is a sub-query statement. Determining whether the sorting operation is a redundant operation includes:
[0010] If the parent query statement performs secondary sorting on the result set corresponding to the sub-query statement and there is no condition in the sub-query statement that changes the result set of the sub-query statement, determine that the sorting operation is a redundant operation.
[0011] In some embodiments, the sub-statement is a sub-query statement. Determining whether the sorting operation is a redundant operation includes:
[0012] If the parent query statement does not perform secondary processing on the result set corresponding to the sub-query statement and there is no condition in the sub-query statement that changes the result set of the sub-query statement, determine that the sorting operation is a redundant operation.
[0013] In some embodiments, the sub-statement is a set operation statement. Determining whether the sorting operation is a redundant operation includes:
[0014] If there is no condition in each branch statement of the set operation statement that changes the result set of the subquery statement, it is determined that the sorting operation is a redundant operation.
[0015] In some embodiments, the optimizing the query statement according to the sorting operation includes:
[0016] Delete the sorting operation to obtain the target query statement.
[0017] In some embodiments, the method further includes:
[0018] If the query statement nests multiple subquery statements, recursively process each subquery statement and delete the sorting operations in each subquery statement.
[0019] In some embodiments, the determining that there is no condition in the subquery statement that changes the result set of the subquery statement includes:
[0020] If there is no preset field in the filtering condition of the sub-statement, it is determined that there is no condition that changes the result set of the sub-statement, and the preset field includes one or more of limit, rownum, and distncton.
[0021] In a second aspect, an embodiment of the present application provides a query statement processing device, including:
[0022] An acquisition module, configured to acquire a query statement to be processed;
[0023] A determination module, configured to determine whether the sorting operation is a redundant operation when the query statement includes a sub-statement and the sub-statement includes a sorting operation;
[0024] An optimization module, configured to, if so, optimize the query statement according to the sorting operation to obtain a target query statement;
[0025] An execution module, configured to execute the target query statement.
[0026] In a third aspect, the present application provides an electronic device, including: a memory and a processor;
[0027] The memory is used to store computer instructions; the processor is used to run the computer instructions stored in the memory to implement the method according to any one of the first aspect.
[0028] In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the method according to any one of the first aspect.
[0029] In a fifth aspect, the present application provides a computer program product, including a computer program which, when executed by a processor, implements the method according to any one of the first aspect.
[0030] The query statement processing method and related device provided in the embodiments of the present application include obtaining a query statement to be processed; when the query statement includes a sub-statement and the sub-statement includes a sorting operation, determining whether the sorting operation is a redundant operation; if so, optimizing the query statement according to the sorting operation to obtain a target query statement; and executing the target query statement. Through the above method, redundant sorting operations in the query statement can be deleted, thereby effectively improving the query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 is a schematic flowchart of a query statement processing method provided in an embodiment of the present application Figure 1 ;
[0032] Figure 2 is a schematic flowchart of a query statement processing method provided in an embodiment of the present application Figure 2 ;
[0033] Figure 3 is a schematic structural diagram of a query statement processing device provided in an embodiment of the present application;
[0034] Figure 4 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0035] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Apparently, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0036] In the embodiments of the present application, terms such as "first" and "second" are used to distinguish identical or similar items with basically the same functions and effects, and do not limit their sequence. Those skilled in the art can understand that the terms "first" and "second" do not limit the quantity and execution order, and the terms "first" and "second" do not necessarily mean different.
[0037] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to represent examples, illustrations or explanations. Any embodiment or design solution described as "exemplary" or "for example" in the present application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Rather, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific manner.
[0038] Currently, when multiple sorting operations are performed on the same column in a query statement, the optimizer will make a simple judgment. If the sorting keys of the sorting operations are exactly the same, a deduplication operation will be performed and only one sorting will be carried out. Or, when there are sorting operations in sub-links such as in and any, the optimizer will delete the deduplication operation in the sub-link to reduce the computational overhead and thus improve the query efficiency.
[0039] However, in a scenario involving multi-level queries in a query statement, for example, when the query statement includes sub-statements, the optimizer cannot identify whether there is redundant content in the sub-statement that affects the query efficiency, resulting in a lower query efficiency of the optimized query statement.
[0040] In view of this, the embodiments of the present application provide a query statement processing method. In a scenario involving multi-level queries, according to the characteristics of the sub-statement, when it is determined that there is redundant content in the sub-statement, the redundant content can be deleted, thereby improving the query efficiency of the query statement.
[0041] The following uses specific embodiments to detail the technical solution of the present application and how the technical solution of the present application solves the above technical problems. These several specific embodiments can be implemented independently or in combination with each other. For the same or similar concepts or processes, they may not be repeated in some embodiments.
[0042] Figure 1 A flowchart of a query statement processing method provided by an embodiment of the present application is as Figure 1 shown, and includes the following steps:
[0043] S101. Obtain a query statement to be processed.
[0044] The execution subject of the embodiments of the present application can be an optimizer or an executor that processes the query statement. Hereinafter, the optimizer is taken as an example for illustration.
[0045] The optimizer can obtain the query statement input by the user from the outside.
[0046] S102. When the query statement includes a sub-statement and the sub-statement includes a sorting operation, determine whether the sorting operation is a redundant operation.
[0047] Among them, the sorting operation can refer to, for example, the sorting operation can be an order by operation.
[0048] In some embodiments, the optimizer can construct an abstract syntax tree based on the query statement; traverse the target fields (such as select, from, etc.) in the abstract syntax tree, and if it is determined that a query block is nested in the node after the target field, it is determined that the query statement includes a sub-statement.
[0049] In some embodiments, after the optimizer determines that the query statement includes a sub-statement, it can analyze the sub-statement to determine whether the sub-statement includes a sorting operation (such as an order by operation). If the sub-statement does not include a sorting operation, the optimizer can perform other optimization processes (such as cost evaluation) and execute the query statement.
[0050] If the sub-statement includes a sorting operation, the optimizer can determine whether the sorting operation in the sub-statement is a redundant sorting operation. If so, it can perform the steps shown in S103. If not, it can perform other optimization processes and execute the query statement.
[0051] In some embodiments, the optimizer can determine whether the sorting operation in the sub-statement is redundant based on the usage of the result set of the sub-statement by the sub-statement and / or the parent statement.
[0052] For example, if the optimizer determines that the parent statement will sort the result set of the sub-statement again, it is determined that the sorting operation in the sub-statement is a redundant operation. Or, if the optimizer determines that the parent statement only uses the result set of the sub-statement and will not perform additional processing on it, it is determined that the sorting operation in the sub-statement is a redundant operation. Or, if the sub-statement is a set operation statement, the sorting operation in the sub-statement is a redundant operation. Or, if multiple statements are nested in the sub-statement, the sorting operation in the sub-statement is a redundant operation.
[0053] S103. Optimize the query statement according to the sorting operation to obtain a target query statement.
[0054] In some embodiments, the optimizer can delete the sorting operation to obtain the target query statement.
[0055] Exemplarily, the following query statement:
[0056] Select v.b from t1, (select a,b from t2 order by a,b,c) v where t1.a = v.b;
[0057] If the optimizer determines that the ORDER BY operation in the sub-statement "select a,b from t2 order by a,b,c" is a redundant operation, the optimizer can delete this ORDER BY operation to obtain the optimized target query statement.
[0058] Exemplarily, the target query statement is as follows:
[0059] Select v.b from t1, (select a,b from t2 ) v where t1.a = v.b;
[0060] S104. Execute the target query statement.
[0061] When obtaining the target query statement, the optimizer can perform other optimization processes in the prior art (such as cost evaluation) on the target query statement, and execute the target query statement to obtain the query result.
[0062] The query statement processing method provided by the embodiments of the present application includes: obtaining a query statement to be processed; when the query statement includes a sub-statement and the sub-statement includes a sorting operation, determining whether the sorting operation is a redundant operation; if so, optimizing the query statement according to the sorting operation to obtain a target query statement; and executing the target query statement. By performing redundancy identification on the sorting operation in the sub-statement included in the query statement and optimizing the redundant sorting operation when it is determined to be redundant, the query efficiency of the query statement can be effectively improved.
[0063] Based on the above embodiments, the process of the optimizer determining whether the sorting operation is a redundant operation will be further described below in conjunction with Figure 2 , as
[0064] Figure 2 is a flowchart of the query statement processing method provided by the embodiments of the present application Figure 2 , as Figure 2 shown, and includes:
[0065] S201. Determine whether the sorting operation in the sub-statement is redundant according to the usage of the sub-statement result set by the sub-statement and / or the parent statement.
[0066] S202. Delete the sorting operation in the sub-statement.
[0067] In some embodiments, the following method can be used in step 201 to determine whether the sorting operation in the sub-statement is redundant.
[0068] In a possible implementation, when the sub-statement is a sub-query statement, if the parent query statement performs a secondary sorting on the result set corresponding to the sub-query statement, and there is no condition in the sub-query statement that changes the result set of the sub-query statement, then it is determined that the sorting operation is a redundant operation.
[0069] Among them, the fact that there is no condition in the sub-query statement that changes the result set of the sub-query statement may mean that there is no preset field in the filtering conditions of the sub-statement that modifies the result set of the sub-query statement. For example, the preset fields include one or more of limit, rownum, and distncton.
[0070] Exemplarily, the query statement is as follows:
[0071] Select t1.*, v.b from t1, (select a,b from t2 order by a,b) v orderby v.b;
[0072] Among them, the sub-query statement is select a,b from t2 order by a,b. There are no fields such as limit, rownum, and distncton in this sub-query statement. The parent query statement includes order by v.b, which will re-sort the result set v of the sub-query by b. At this time, the optimizer can determine that the sorting operation in the sub-query statement is a redundant sorting operation. Then the optimizer can delete the sorting operation in the sub-query statement to obtain the target query statement.
[0073] Exemplarily, the optimized target query statement is as follows:
[0074] Select t1.*, v.b from t1, (select a,b from t2 ) v order by v.b;
[0075] In a possible implementation, when the sub-statement is a sub-query statement, if the parent query statement does not perform secondary processing on the result set corresponding to the sub-query statement, and there is no condition in the sub-query statement that changes the result set of the sub-query statement, then it is determined that the sorting operation is a redundant operation.
[0076] Among them, the fact that the parent query statement does not perform secondary processing on the result set corresponding to the sub-query statement may mean that the parent query statement only uses the result set of the sub-query and does not perform additional processing on it.
[0077] Exemplarily, the query statement is as follows:
[0078] Select v.b from t1, (select a,b from t2 order by a,b,c) v where t1.a= v.b;
[0079] Among them, the subquery statement is select a,b from t2 order by a,b,c. There are no fields such as limit, rownum, distncton, etc. in this subquery statement. The sorting operation in the subquery statement only affects the output order of the subquery result set and does not affect the data volume of the subquery result set. And the parent query statement only uses the result set v of the subquery statement. At this time, the optimizer can determine that the sorting operation in the subquery statement is a redundant sorting operation, so the optimizer can delete the sorting operation in the subquery statement to obtain the target query statement.
[0080] Exemplarily, the optimized query statement is as follows:
[0081] Select t1.*, v.b from t1, (select a,b from t2 ) v order by v.b;
[0082] In a possible implementation, when the sub-statement is a set operation statement and there is no condition in each branch statement of the set operation statement that changes the result set of the subquery statement, it is determined that the sorting operation is a redundant operation.
[0083] Among them, the set operation statement can refer to a statement including operators such as union [all], except [all], minus [all], intersect [all], etc.
[0084] Exemplarily, the query statement is as follows:
[0085] Select v.id from t1, (
[0086] (select id from t1 order by id)
[0087] Union
[0088] (select id from t2 order by id)
[0089] intersect
[0090] (select id from t3 order by id)
[0091] )v;
[0092] Among them, the set operation statement is:
[0093] (select id from t1 order by id)
[0094] Union
[0095] (select id from t2 order by id)
[0096] intersect
[0097] (select id from t3 order by id)
[0098] This set operation statement includes 3 sub - statements, connected by Union and intersect. There are no fields such as limit, rownum, distncton, etc. in each branch statement. At this time, the optimizer can determine that the sorting operations in each branch statement of this set operation statement are redundant sorting operations. Then the optimizer can recursively process each branch statement and delete the sorting operations in each branch statement to obtain the target query statement.
[0099] Exemplarily, the optimized target query statement is as follows:
[0100] Select v.id from t1, (
[0101] (select id from t1)
[0102] Union
[0103] (select id from t2)
[0104] intersect
[0105] (select id from t3)
[0106] )v;
[0107] Optionally, if the query statement is a set statement and there are sorting operations in each branch statement of the set statement, the optimizer can determine that the sorting operations in each branch statement of this set operation statement are redundant sorting operations. Then the optimizer can recursively process each branch statement and delete the sorting operations in each branch statement to obtain the target query statement.
[0108] Exemplarily, the optimization of the set statement can be as follows:
[0109] (select id from t1 order by id)
[0110] Union
[0111] (select id from t2 order by id)
[0112] intersect
[0113] (select id from t3 order by id);
[0114] =>
[0115] (select id from t1 )
[0116] Union
[0117] (select id from t2)
[0118] intersect
[0119] (select id from t3);
[0120] In a possible implementation, if the query statement nests multiple sub-query statements, each sub-query statement is processed recursively, and the sorting operations in each sub-query statement are deleted.
[0121] Exemplarily, the query statement is as follows:
[0122] Select v.b from t1, (select a,b,c from t2,(select c from t3 order by c) v1 order by a,b) v
[0123] Among them, the sub-query statement select a,b from t2 order by a,b also nests a sub-query statement select c from t3 order by c. There are no fields such as limit, rownum, and distincton in this sub-query statement and the nested sub-query statement, and the parent query statement only uses the result set v of the sub-query statement. At this time, the optimizer can determine that the sorting operation in this sub-query statement is a redundant sorting operation. Then the optimizer can process each sub-query statement recursively and delete the sorting operations in each sub-query statement to obtain the target query statement.
[0124] Exemplarily, the optimized target query statement is as follows:
[0125] Select v.b from t1, (select a,b ,c from t2,(select c from t3 ) v1 )v;
[0126] In summary, for the query statement processing method provided by the embodiments of the present application, after obtaining a query statement, each table after the from field in the query statement is traversed. If the table corresponds to a set operation statement, each branch statement of the set operation is traversed to determine whether there is any content such as limit, rownum, or distncton that affects the result set output in each branch statement. If not, the sorting operation in each branch statement is deleted to obtain an optimized target query statement. If the table corresponds to a subquery statement, it is determined whether there is any content such as limit, rownum, or distncton that affects the result set output in the subquery statement. If not, the sorting operation in the subquery statement is deleted to obtain an optimized target query statement. Through the above processing logic, redundant sorting operations in the query statement can be reduced, thereby improving the query efficiency.
[0127] Based on the above embodiments, the embodiments of the present application further provide a query statement processing device.
[0128] Figure 3 It is a schematic structural diagram of the query statement processing device 30 provided by the embodiments of the present application. As Figure 3 shown, it includes:
[0129] An acquisition module 301, configured to acquire a query statement to be processed.
[0130] A determination module 302, configured to determine whether the sorting operation is a redundant operation when the query statement includes a sub-statement and the sub-statement includes a sorting operation.
[0131] An optimization module 303, configured to, if so, optimize the query statement according to the sorting operation to obtain a target query statement.
[0132] An execution module 304, configured to execute the target query statement.
[0133] In some embodiments, the sub-statement is a subquery statement, and the determination module 302 is further configured to determine that the sorting operation is a redundant operation if the parent query statement performs a secondary sorting on the result set corresponding to the subquery statement and there is no condition in the subquery statement that changes the result set of the subquery statement.
[0134] In some embodiments, the sub-statement is a sub-query statement, and the determination module 302 is further configured to determine that the sorting operation is a redundant operation if the parent query statement does not perform secondary processing on the result set corresponding to the sub-query statement and there is no condition in the sub-query statement that changes the result set of the sub-query statement.
[0135] In some embodiments, the sub-statement is a set operation statement, and the determination module 302 is further configured to determine that the sorting operation is a redundant operation if there is no condition in each branch statement of the set operation statement that changes the result set of the sub-query statement.
[0136] In some embodiments, the optimization module 303 is further configured to delete the sorting operation to obtain the target query statement.
[0137] In some embodiments, the optimization module 303 is further configured to recursively process each sub-query statement and delete the sorting operations in each sub-query statement if the query statement nests multiple sub-query statements.
[0138] In some embodiments, the determination module 302 is further configured to determine that there is no condition that changes the result set of the sub-statement if there is no preset field in the filtering condition of the sub-statement, where the preset field includes one or more of limit, rownum, and distncton.
[0139] The query statement processing device provided by the embodiments of the present application can execute the query statement processing method provided by any of the foregoing embodiments, and the principles and technical effects are similar, which will not be elaborated here.
[0140] The embodiments of the present application further provide an electronic device.
[0141] Figure 4 Shown in the following is the structural schematic diagram of the electronic device 40 provided by the embodiments of the present application. Figure 4 As shown, it includes:
[0142] A processor 401.
[0143] A memory 402 for storing executable instructions of the terminal device.
[0144] Specifically, the program may include program codes, and the program codes include computer operation instructions. The memory 402 may include a high-speed RAM memory, and may also include non-volatile memory, such as at least one disk memory.
[0145] The processor 401 is configured to execute the computer execution instructions stored in the memory 402 to implement the technical solutions of the query statement processing method embodiments described in the foregoing method embodiments.
[0146] Among them, the processor 401 may be a Central Processing Unit (CPU), or an Application Specific Integrated Circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
[0147] Optionally, the electronic device 40 may further include a communication interface, through which it can communicate with external devices. The external device may be, for example, a user terminal (such as a mobile phone, a tablet). In a specific implementation, if the communication interface, the memory 402, and the processor 401 are implemented independently, the communication interface, the memory 402, and the processor 401 may be connected to each other through a bus and communicate with each other.
[0148] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc., but it does not mean that there is only one bus or one type of bus.
[0149] Optionally, in a specific implementation, if the communication interface, the memory 402, and the processor 401 are integrated on a chip, the communication interface, the memory 402, and the processor 401 can complete communication through an internal interface.
[0150] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the technical solutions of the embodiments of the above query statement processing method are implemented. The implementation principle and technical effects are similar and will not be elaborated here.
[0151] In one possible implementation, a computer-readable medium may include random access memory (RAM), read-only memory (ROM), compact disc read-only memory (CD-ROM), or other optical disc storage, magnetic disk storage, or any other medium targeted to carry or store the required program code in the form of instructions or data structures and accessible by a computer. Moreover, any connection is properly termed a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL), or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of the medium. As used herein, disk and optical disc include optical disc, laser disc, optical disc, digital versatile disc (DVD), floppy disk, and Blu-ray disc, where disks typically reproduce data magnetically, while optical discs utilize lasers to optically reproduce data. Combinations of the above should also be included within the scope of computer-readable media.
[0152] In an embodiment of this application, a computer program product is also provided, including a computer program which, when executed by a processor, implements the technical solutions of the above embodiment of the query statement processing method. The implementation principle and technical effects are similar and will not be elaborated here.
[0153] In the specific implementation of the above terminal device or server, it should be understood that the processor may be a central processing unit (CPU for short), or may also be other general-purpose processors, digital signal processors (DSP for short), application-specific integrated circuits (ASIC for short), etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of this application may be directly implemented by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0154] Those skilled in the art can understand that all or part of the steps of any of the above method embodiments can be completed by hardware related to program instructions. The foregoing program may be stored in a computer-readable storage medium, and when the program is executed, all or part of the steps of the above method embodiments are executed.
[0155] If the technical solution of this application is implemented in the form of software and sold or used as a product, it can be stored in a computer-readable storage medium. Based on such an understanding, all or part of the technical solution of this application can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes a computer program or several instructions. This computer software product enables a computer device (which can be a personal computer, a server, a network device, or a similar electronic device) to execute all or part of the steps of the method described in the embodiments of this application.
[0156] It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that this application is not limited by the described action sequence, because according to this application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.
[0157] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed sequentially according to the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps has no strict order limitation, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same moment, but can be executed at different moments. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or sub-steps or stages of other steps.
[0158] It should be understood that the above device embodiments are only illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical function division, and there can be other division methods in actual implementation. For example, multiple units, modules, or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0159] In addition, without special instructions, in each embodiment of this application, each functional unit / module can be integrated in one unit / module, or each unit / module can exist physically alone, or two or more units / modules can be integrated together. The above integrated unit / module can be implemented in the form of hardware or in the form of a software program module.
[0160] When the integrated unit / module is implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any suitable magnetic storage medium or magneto-optical storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), etc.
[0161] When the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. And the aforementioned memory includes: USB flash drives, read-only memory (ROM), random access memory (RAM), mobile hard disks, magnetic disks, or optical discs, etc., all kinds of media that can store program codes.
[0162] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.
[0163] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A query statement processing method, characterized in that: Obtain a query statement to be processed; When the query statement includes a sub-statement and the sub-statement includes a sorting operation, determine whether the sorting operation is a redundant operation; If so, optimize the query statement according to the sorting operation to obtain a target query statement; Execute the target query statement.
2. The method according to claim 1, wherein The sub-statement is a sub-query statement. The determination of whether the sorting operation is a redundant operation includes: If the parent query statement performs a secondary sorting on the result set corresponding to the sub-query statement and there is no condition in the sub-query statement that changes the result set of the sub-query statement, determine that the sorting operation is a redundant operation.
3. The method according to claim 1, wherein The sub-statement is a sub-query statement. The determination of whether the sorting operation is a redundant operation includes: If the parent query statement does not perform secondary processing on the result set corresponding to the sub-query statement and there is no condition in the sub-query statement that changes the result set of the sub-query statement, determine that the sorting operation is a redundant operation.
4. The method according to claim 1, wherein The sub-statement is a set operation statement. The determination of whether the sorting operation is a redundant operation includes: If there is no condition in each branch statement of the set operation statement that changes the result set of the sub-query statement, determine that the sorting operation is a redundant operation.
5. The method according to any one of claims 2 to 4, characterized in that, The optimization of the query statement according to the sorting operation includes: Delete the sorting operation to obtain the target query statement.
6. The method according to claim 5, wherein The method further includes: If the query statement nests multiple sub-query statements, recursively process each sub-query statement and delete the sorting operations in each sub-query statement.
7. The method according to any one of claims 2 to 4, characterized in that, The determination that there is no condition in the sub-query statement that changes the result set of the sub-query statement includes: If there is no preset field in the filtering condition of the sub-statement, determine that there is no condition that changes the result set of the sub-statement. The preset field includes one or more of limit, rownum, and distncton.
8. An electronic device, characterized in that, Includes: A memory for storing a computer program; A processor for executing the computer program to implement the method according to any one of claims 1-7.
9. A computer-readable storage medium, characterized in that, A computer program is stored thereon, and the computer program is executed by a processor to implement the method according to any one of claims 1-7.
10. A computer program product, characterized in that, Includes a computer program, which implements the method according to any one of claims 1-7 when executed by a controller.