A query adjustment method, device, electronic device, storage medium and program product

By converting the ROWNUM filtering condition into top expressions and optimizing the query statement, the performance problems caused by ROWNUM as the outermost pagination query filtering condition are solved, and more efficient database query is achieved.

CN119739735APending Publication Date: 2025-04-01SHANGHAI DAMENG DATABASE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411954536.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-04-01

AI Technical Summary

Technical Problem

In structured query language, when ROWNUM is the outermost pagination query filtering condition, a large amount of unrelated data is involved in the calculation, which reduces the database query performance.

Method used

By obtaining the query statement to be adjusted, converting the pseudo-column filtering condition to the top expression, and removing the pseudo-column filtering condition in the query expression semantic structure, adding the top expression to its corresponding position to achieve priority execution of the pseudo-column filtering condition.

Benefits of technology

Filter data in advance, control the amount of data in the query process within a reasonable range, reduce the amount of calculations of related calculations, and improve the query performance and query efficiency of the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119739735A_ABST
    Figure CN119739735A_ABST
Patent Text Reader

Abstract

The present invention discloses a query adjustment method, device, electronic device, storage medium and program product, which specifically relate to the field of database technology. The specific implementation scheme includes: firstly obtaining the query statement to be adjusted; then converting the pseudo-column filter condition in the query statement to be adjusted into a form to obtain a top expression; then removing the pseudo-column filter condition in the query expression after semantic analysis of the query statement to be adjusted; and finally adding the top expression to the position corresponding to the pseudo-column filter condition in the semantic structure of the query expression. By converting the pseudo-column filter condition into a top expression, removing the pseudo-column filter condition, and adding the top expression to the query expression, the priority execution of the pseudo-column filter condition is achieved, and the data is filtered in advance to control the data volume of the query process within a reasonable range, reducing the amount of calculation of related calculations, improving the query performance of the database, and improving the query efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of databases, and in particular, to a query adjustment method, device, electronic device, storage medium, and program product. Background Art

[0002] In the Structured Query Language, ROWNUM is a dummy column that represents the row number queried from a table or the number of rows in the result set of a join query. By using ROWNUM, the number of rows returned by a query can be restricted. In scenarios where paged query needs to be implemented, the condition ROWNUM>m (or >=m) and ROWNUM<n (or <=n) (where n - m is a fixed value) can be specified to filter out n - m - 1 (i.e., the fixed value defined by the ROWNUM condition) data for each page.

[0003] When using ROWNUM as the outermost paged query filter condition, when executing a Structured Query Language statement, only ROWNUM<n can be pushed down to the inner query to filter the data to n - 1 rows, and ROWNUM>m only plays a filtering role after various calculations are completed, which will cause a large amount of irrelevant data to participate in the calculations. Summary of the Invention

[0004] The present invention provides a query adjustment method, device, electronic device, storage medium, and program product to achieve the preferential execution of dummy column filter conditions and improve the query performance of the database.

[0005] According to one aspect of the present invention, a query adjustment method is provided, including:

[0006] Obtain a query statement to be adjusted, where the query statement to be adjusted includes a query statement to be adjusted by the execution timing of a filter condition;

[0007] Perform a formal conversion on the dummy column filter condition in the query statement to be adjusted to obtain a top - taking expression, where the dummy column filter condition is a filter condition based on a dummy column in the Structured Query Language, and the dummy column filter condition is the outermost query filter condition in the query statement to be adjusted;

[0008] Remove the dummy column filter condition from the query expression after semantic analysis of the query statement to be adjusted;

[0009] Add the top - taking expression to the position corresponding to the dummy column filter condition in the query expression semantic structure, where the query expression semantic structure includes the semantic structure formed by the query expressions of the derived tables filtered by the dummy column filter condition.

[0010] According to another aspect of the present invention, a query adjustment device is provided, including:

[0011] An acquisition module, used for acquiring a query statement to be adjusted, wherein the query statement to be adjusted includes a query statement to be adjusted by the execution timing of the filtering condition;

[0012] A conversion module, used for converting the pseudo column filtering condition in the query statement to be adjusted to obtain a top expression, wherein the pseudo column filtering condition is a filtering condition based on a pseudo column in a structured query language, and the pseudo column filtering condition is a filtering condition of the outermost query in the query statement to be adjusted;

[0013] A removal module, used to remove the pseudo-column filtering condition in the query expression after the semantic analysis of the query statement to be adjusted;

[0014] An adding module is used to add the top expression to the position corresponding to the pseudo-column filtering condition in the query expression semantic structure, and the query expression semantic structure includes a semantic structure formed by the query expression of the derived table filtered by the pseudo-column filtering condition.

[0015] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:

[0016] at least one processor; and

[0017] a memory communicatively connected to the at least one processor; wherein,

[0018] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the query adjustment method described in any embodiment of the present invention.

[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the query adjustment method described in any embodiment of the present invention when executed.

[0020] According to another aspect of the present invention, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the query adjustment method according to any embodiment of the present invention is implemented.

[0021] The technical solution of the embodiment of the present invention first obtains the query statement to be adjusted; then the pseudo-column filter condition in the query statement to be adjusted is converted into a form to obtain a top expression; then the pseudo-column filter condition is removed from the query expression after the semantic analysis of the query statement to be adjusted; finally, the top expression is added to the position corresponding to the pseudo-column filter condition in the semantic structure of the query expression. By converting the pseudo-column filter condition into a top expression, removing the pseudo-column filter condition, and adding the top expression to the query expression, the priority execution of the pseudo-column filter condition is achieved, and the data is filtered in advance to control the data volume of the query process within a reasonable range, reducing the amount of calculation of related calculations, improving the query performance of the database, and improving the query efficiency.

[0022] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0024] Figure 1 is a flowchart of a query adjustment method provided according to Embodiment 1 of the present invention;

[0025] Figure 2 is a flow chart of a method for determining a first character comparison position provided according to Embodiment 2 of the present invention;

[0026] Figure 3 is a structural diagram of a query adjustment device provided according to Embodiment 3 of the present invention;

[0027] Figure 4 It is a block diagram of an electronic device provided according to a fourth embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0030] Embodiment 1

[0031] Figure 1 A flowchart of a query adjustment method is provided for the first embodiment of the present invention. This embodiment is applicable to the case where the semantic structure of the query statement to be adjusted is adjusted. The method can be executed by a query adjustment device, which can be implemented in the form of hardware and / or software. The query adjustment device can be configured in an electronic device, which can be a mobile terminal, a PC or a server. Figure 1 As shown, the method includes:

[0032] S110: Obtain a query statement to be adjusted, where the query statement to be adjusted includes a query statement to be adjusted through an execution sequence of a filtering condition.

[0033] In this embodiment, the query statement to be adjusted can be understood as a statement that can be adjusted according to the execution sequence of the filter condition, and the query statement to be adjusted can be the statement where the outermost filter condition of the structured query statement is located. The filter condition can be understood as being used to retrieve data that meets the condition from the database and output rows that meet the filter condition.

[0034] Specifically, for the sentence containing the outermost filter condition of the structured query, the sentence is subjected to grammatical and semantic analysis, and the sentence satisfying the set condition is used as the query sentence to be adjusted, and the set condition may include determining whether the filter condition included in the sentence is complete and the source of the filter condition.

[0035] For example, assuming that there is the following structured query statement, a paginated query scenario can be implemented:

[0036] create table t1(id int primary key,id2 int);

[0037] create table t2(id int primary key,id2 int);

[0038] insert into t1 select level,level from dual connect by level<10000;

[0039] insert into t2 select level,level from dual connect by level<10000;

[0040] SELECT * FROM(

[0041] SELECT T.*,ROWNUM AS RN

[0042] FROM(

[0043] SELECT T1.*,

[0044] (SELECT SUM(T2.ID2)FROM T2 WHERE T2.ID=T1.ID)AS SUM_T2_ID2

[0045] FROM T1

[0046] )T

[0047] ORDER BY T.ID2 )

[0049] WHERE RN>=9990AND RN<10000;

[0050] For the above statement, after performing grammatical and semantic analysis on the statement, the statement can be used as a query statement to be adjusted.

[0051] S120. Convert the pseudo-column filter condition in the query statement to be adjusted to obtain a top expression, wherein the pseudo-column filter condition is a filter condition based on a pseudo-column in a structured query language, and the pseudo-column filter condition is a filter condition of the outermost query in the query statement to be adjusted.

[0052] In this embodiment, the pseudo column assigns a unique serial number to each row in the query result set of the structured query statement, starting from 1. This serial number is generated when the query result is retrieved and is unique for each row in the result set. The pseudo column filter condition can be understood as the filter condition formed by the query statement where the pseudo column is located in the structured query statement. The pseudo column filter condition can be the outermost filter condition of the query statement to be adjusted, which can limit the number of rows returned by the query result in the structured query statement. The top expression can be understood as an expression for taking a number of data starting from a set position in the query result set, and the top expression includes the information indicated by the pseudo column filter condition.

[0053] Specifically, the pseudo column filter condition includes the starting value and the end value that the query statement to be adjusted needs to filter. The number of data to be filtered in the pseudo column filter condition can be obtained according to the starting value and the end value. During semantic analysis, the pseudo column filter condition can be converted into a top expression according to the starting value and the number of data. The top expression is semantically equivalent to the pseudo column filter condition.

[0054] For example, in the query statement to be adjusted, WHERE RN>=9990AND RN<10000 can be used as a pseudo column filtering condition, and the number of data to be filtered is 10 according to the starting value 9990 and the ending value 10000. When performing semantic analysis on it, the pseudo column filtering condition can be converted into a top expression TOP 9989,10.

[0055] S130: Remove the pseudo-column filtering condition from the query expression after semantic analysis of the query statement to be adjusted.

[0056] Specifically, for the query statement to be adjusted that has undergone semantic analysis, its pseudo-column filtering condition has been converted into a top-taking expression, and the pseudo-column filtering condition can be removed from the semantic structure of the query expression of the query statement to be adjusted.

[0057] S140. Add the top expression to the position corresponding to the pseudo-column filtering condition in the query expression semantic structure, where the query expression semantic structure includes a semantic structure formed by the query expression of the derived table filtered by the pseudo-column filtering condition.

[0058] In this embodiment, the derived table can be understood as a temporarily created table, which is used to store the results of the subquery in the FROM item during the query operation.

[0059] Specifically, the query statement to be adjusted includes a query expression filtered by a pseudo-column filter condition, that is, the outermost filter condition. The database can create a derived table in the semantic structure to store the query results filtered by the pseudo-column filter condition in the query statement to be adjusted. After removing the pseudo-column filter condition from the semantic structure of the query expression, the top expression converted from the pseudo-column filter condition after semantic analysis is added to the position corresponding to the pseudo-column filter condition in the semantic structure of the query expression.

[0060] Exemplarily, the conventional execution steps for the above statement are as follows:

[0061]

[0062] It can be seen that during execution, only ROWNUM<10000 (#RN:[1,9999->9999,16]) in the pseudo column filter condition is transferred to the inner query, converted into the TOP condition and integrated into the SORT3 sorting operator. There are 9999 rows of data that need to be sorted in the SORT3 sorting operator (#SORT3:[2,100->9999,16]). When performing the PRJT2 projection operation on the upper layer of the sorting operation, a scalar subquery SELECT SUM(T2.ID2)FROM T2WHERE T2.ID=T1.ID is required for all data with ROWNUM<10000 to obtain the SUM_T2_ID2 column. This scalar subquery is calculated 9999 times. After sorting and projection, SLCT2 filtering (#SLCT2:[2,499->10,16]) is performed, and the filtering condition ROWNUM>=9990 filters the data to 10 rows. Scalar subquery can be understood as a database query method that can be used to return one row and one column of records.

[0063] When performing semantic analysis on the above statement, the pseudo-column filter condition is first converted into a top expression and then the operation is performed. The execution steps are as follows:

[0064]

[0065] It can be seen that the TOPN2 operator for taking the top expression is generated before the PRJT2 projection operation and the SORT3 sorting operation, and the pseudo column filter condition is removed, and the TOPN2 operation of the top expression is added to the position of the pseudo column filter condition, that is, the bold position. The data is filtered to 10 rows in advance, so that only 10 rows of data need to be processed when SORT3 is sorted, and the number of times the scalar subquery is calculated in the PRJT2 projection is only 10 times.

[0066] The technical solution of the embodiment of the present invention first obtains the query statement to be adjusted; then the pseudo-column filter condition in the query statement to be adjusted is converted into a form to obtain a top expression; then the pseudo-column filter condition is removed from the query expression after the semantic analysis of the query statement to be adjusted; finally, the top expression is added to the position corresponding to the pseudo-column filter condition in the semantic structure of the query expression. By converting the pseudo-column filter condition into a top expression, removing the pseudo-column filter condition, and adding the top expression to the query expression, the priority execution of the pseudo-column filter condition is achieved, and the data is filtered in advance to control the data volume of the query process within a reasonable range, reducing the amount of calculation of related calculations, improving the query performance of the database, and improving the query efficiency.

[0067] Based on the above embodiment, a variant embodiment of the above embodiment is proposed. It should be noted that in order to make the description concise, only the differences from the above embodiment are described in the variant embodiment.

[0068] In one embodiment, adding the top expression to the position corresponding to the pseudo-column filtering condition in the query expression semantic structure includes:

[0069] The top expression is added before the sort expression in the query expression semantic structure.

[0070] In this embodiment, the sorting expression can be understood as an expression used to perform a sorting operation on data in a structured query statement.

[0071] Specifically, when adding the top expression to the query expression semantic structure, it is necessary to consider that the semantic expression already includes the top expression and the sorting expression. The corresponding position of the pseudo-column filter condition can be considered to be before the sorting expression in the query expression semantic structure. In order to ensure the correctness of the query results, the order of the top expression and the sorting expression in the semantic structure needs to be considered. Therefore, in the semantic structure, it is necessary to generate nodes for the top expression and the sorting expression separately, and add the top expression before the sorting expression.

[0072] For example, the semantic structure contains both the top expression TOP item and the sorting expression ORDER BY item. The top expression and the sorting expression are independent of each other. When generating the relationship tree, the TOPN2 operator cannot be integrated into the SORT3 sorting operator for processing, otherwise the sorting will be performed first and then the filtering will cause an error in the query result set. Therefore, when adding the top expression to the query expression semantic structure, the top expression TOP item is added before the sorting expression ORDER BY item. That is, when executing the query statement, the TOPN2 operator's filtering operation is first performed on the data, and then the SORT3 sorting operator's sorting operation is performed.

[0073] In one embodiment, adding the top expression to the query expression semantic structure before the sorting expression includes:

[0074] Determine a sorting node in a relationship tree corresponding to the semantic structure of the query expression;

[0075] The top expression is added to the left child node of the sorting node.

[0076] In this embodiment, the relationship tree can be understood as a tree structure used to represent the query operation sequence and dependency relationship during the database query process, and the relationship tree is a type of binary tree. The sorting node can be understood as a node in the relationship tree that indicates the timing of the sorting operation execution. The left child node can be understood as a node located on the left side of the child node of the sorting node in the relationship tree. In terms of execution order, the execution order of the left child node is before the sorting node, and the child node is a direct child node of a node in the relationship tree structure.

[0077] Specifically, when executing a query statement, a corresponding relationship tree needs to be constructed for the semantic structure of the query expression. In the relationship tree, firstly, corresponding independent nodes are determined for the sorting expression and the top expression, respectively, wherein the node corresponding to the sorting expression is the sorting node. When performing the operation of adding the top expression before the sorting expression, the node corresponding to the top expression can be added to the left child node of the sorting node.

[0078] Exemplarily, the sorting node corresponding to the sorting expression may be an ORDER node, and the node corresponding to the top expression may be a TOP node. In the relationship tree, the TOP node is set as the left child node of the ORDER node, completing the operation of adding the top expression before the sorting expression in the query expression semantic structure.

[0079] In one embodiment, obtaining the query statement to be adjusted includes:

[0080] Get the initial query statement;

[0081] Determining whether the initial query statement satisfies the condition to be adjusted;

[0082] If so, the initial query statement is determined as the query statement to be adjusted.

[0083] In this embodiment, the initial query statement can be understood as a structured query statement for querying a database system. The condition to be adjusted can be understood as a condition for determining the query statement to be adjusted, and the condition to be adjusted can include a determination of a filter condition in the initial query statement and a determination of content contained in a derived table.

[0084] Specifically, obtain the structured query statement to be queried against the database as the initial query statement. Determine the conditions to be adjusted, and based on the syntax and semantic analysis of the initial query statement, determine whether the initial query statement meets the conditions to be adjusted. If it meets, determine the initial query statement as the query statement to be adjusted.

[0085] In one embodiment, the conditions to be adjusted include:

[0086] The complete pseudo-column filtering condition in the outermost query filtering condition of the initial query statement; and,

[0087] The column in the pseudo-column filtering condition is a column in the derived table; and,

[0088] The query statement of the derived table contains a sorting item; and,

[0089] The query statement of the derived table does not contain pseudo-column items and top items.

[0090] In this embodiment, the sorting item is used to perform a sorting operation on data in the structured query statement and can sort the query results. The pseudo-column item is used to limit the number of rows returned by the query in the structured query statement. The top item can be converted from the pseudo-column item in the structured query statement and can be used to filter data according to the set value in the structured query statement.

[0091] Exemplarily, the conditions to be adjusted include: 1. The outermost query filtering condition of the initial query statement contains a complete ROWNUM pseudo-column filtering condition. The complete ROWNUM pseudo-column filtering condition is, for example: the pseudo-column filtering condition must contain both the starting value and the ending value for specifying the return result, in the form of ROWNUM>m (or >=m) and ROWNUM<n (or <=n). 2. The column in the pseudo-column filtering condition, that is, the outermost query filtering condition, comes from the column of the derived table in the initial query statement. 3. The query statement corresponding to the derived table in the initial query statement contains a sorting item, that is, the ORDER BY item. 4. The query statement corresponding to the derived table in the initial query statement does not contain a top item, that is, the TOP item, and a pseudo-column item, that is, the ROWNUM item. When the initial query statement meets the above four conditions to be adjusted at the same time, determine the initial query statement as the query statement to be adjusted.

[0092] In one embodiment, after adding the top expression to the position corresponding to the pseudo-column filtering condition in the query expression semantic structure, it further includes:

[0093] Execute the top expression and the sorting expression in the query expression semantic structure in sequence.

[0094] Specifically, after adding the take-top expression to the semantic structure of the query expression, the structured query statement is executed. First, the take-top expression is executed, and according to the filtering conditions included in the take-top expression, the data is filtered to a set number of rows. Finally, the sorting expression is executed to sort the data of the set number of rows.

[0095] Exemplarily, when executing the structured query statement, the TOPN2 operator corresponding to the take-top expression will filter the data to the number of rows specified by the pseudo-column filtering condition in advance, and then sort the filtered data according to the SORT3 sorting operator corresponding to the sorting expression. For example: when the number of rows specified by the pseudo-column filtering condition is the mth to the nth row of data, the take-top expression first filters out the mth to the nth row of data, and then the sorting expression sorts the mth to the nth row of data to obtain the sorting result. For the sorted data, scalar subquery calculations can be performed according to the PRJT2 projection operator.

[0096] Embodiment 2

[0097] Figure 2 The flowchart of a method for determining a take-top expression provided by Embodiment 2 of the present invention is shown. In this embodiment, the method for determining the take-top expression in the above embodiment is elaborated. As Figure 2 shown, the method includes:

[0098] S210. Determine the starting row number indicated by the pseudo-column filtering condition in the query statement to be adjusted.

[0099] In this embodiment, the starting row number can be understood as the position of the starting value on the left side in the pseudo-column filtering condition in the query result set.

[0100] Exemplarily, for the pseudo-column filtering condition, according to different comparison operators, there can be four cases: when ROWNUM>m and ROWNUM<n, the starting row number is m; when ROWNUM>=m and ROWNUM<n, the starting row number is m-1; when ROWNUM>m and ROWNUM<=n, the starting row number is m; when ROWNUM>=m and ROWNUM<=n, the starting row number is m-1.

[0101] S220. Determine the number of rows to be filtered in the pseudo-column filtering condition.

[0102] Specifically, according to the starting row number corresponding to the starting value and the ending row number corresponding to the ending value of the pseudo-column filtering condition, and different comparison operators, determine the number of rows to be filtered indicated by the pseudo-column filtering condition.

[0103] Exemplarily, when ROWNUM > m and ROWNUM < n, the number of rows to be filtered is n - m - 1; when ROWNUM >= m and ROWNUM < n, the number of rows to be filtered is n - m; when ROWNUM > m and ROWNUM <= n, the number of rows to be filtered is n - m; when ROWNUM >= m and ROWNUM <= n, the number of rows to be filtered is n - m + 1.

[0104] S230. Use the selected starting row number and the number of rows as the top - taking expression.

[0105] Specifically, use the starting row number as the starting value of the top - taking expression, and use the number of rows to be filtered as the offset value of the top - taking expression, to obtain the top - taking expression converted from the pseudo - column filtering condition. The meaning of the top - taking expression is to select a set number of rows of data starting from the starting value, where the set number is the offset value.

[0106] Exemplarily, the complete conversion process includes:

[0107] ROWNUM > m and ROWNUM < n ==> TOP m,n - m - 1;

[0108] ROWNUM >= m and ROWNUM < n ==> TOP m - 1,n - m;

[0109] ROWNUM > m and ROWNUM <= n ==> TOP m,n - m;

[0110] ROWNUM >= m and ROWNUM <= n ==> TOP m - 1,n - m + 1.

[0111] The technical solution of the embodiment of the present invention first determines the starting row number indicated by the pseudo - column filtering condition in the query statement to be adjusted; then determines the number of rows to be filtered in the pseudo - column filtering condition; finally, uses the selected starting row number and the number of rows as the top - taking expression. Using the starting row number indicated by the pseudo - column filtering condition and the number of rows to be filtered as the coefficients of the top - taking expression refines the process of converting the pseudo - column filtering condition into the top - taking expression, so as to implement the preferential execution of the pseudo - column filtering condition.

[0112] Embodiment III

[0113] Figure 3 It is a schematic structural diagram of a query adjustment device provided in Embodiment III of the present invention. As Figure 3 shown, the device includes:

[0114] An acquisition module 310 is used to acquire a query statement to be adjusted, wherein the query statement to be adjusted includes a query statement to be adjusted by the execution timing of the filtering condition;

[0115] A conversion module 320, configured to convert the pseudo-column filtering condition in the query statement to be adjusted into a form to obtain a top expression, wherein the pseudo-column filtering condition is a filtering condition based on a pseudo-column in a structured query language, and the pseudo-column filtering condition is a filtering condition of the outermost query in the query statement to be adjusted;

[0116] A removal module 330, configured to remove the pseudo column filtering condition from the query expression after semantic analysis of the query statement to be adjusted;

[0117] The adding module 340 is used to add the top expression to the position corresponding to the pseudo-column filtering condition in the query expression semantic structure, and the query expression semantic structure includes the semantic structure formed by the query expression of the derived table filtered by the pseudo-column filtering condition.

[0118] The query adjustment device provided by the embodiment of the present invention first obtains the query statement to be adjusted through the acquisition module; then the pseudo-column filter condition in the query statement to be adjusted is converted into a form through the conversion module to obtain a top expression; then the pseudo-column filter condition is removed from the query expression after the semantic analysis of the query statement to be adjusted through the removal module; finally, the top expression is added to the position corresponding to the pseudo-column filter condition in the semantic structure of the query expression through the addition module. Through the cooperation between the modules, the pseudo-column filter condition is converted into a top expression, and the pseudo-column filter condition is removed, and the top expression is added to the query expression, so that the pseudo-column filter condition is executed first, and the data is filtered in advance to control the data volume of the query process within a reasonable range, reduce the calculation amount of related calculations, improve the query performance of the database, and improve the query efficiency.

[0119] In one embodiment, the adding module 340 includes:

[0120] An adding unit is used to add the top expression before the sorting expression in the query expression semantic structure.

[0121] In one embodiment, the adding unit is specifically configured to:

[0122] Determine a sorting node in a relationship tree corresponding to the semantic structure of the query expression;

[0123] The top expression is added to the left child node of the sorting node.

[0124] In one embodiment, the acquisition module 310 is specifically configured to:

[0125] Get the initial query statement;

[0126] Determining whether the initial query statement satisfies the condition to be adjusted;

[0127] If so, the initial query statement is determined as the query statement to be adjusted.

[0128] In one embodiment, the conditions to be adjusted include:

[0129] The complete pseudo-column filter condition in the filter condition of the outermost query in the initial query statement; and,

[0130] The columns in the pseudo column filter condition are columns in the derived table; and,

[0131] The query statement of the derived table contains a sorting item; and,

[0132] The query statement of the derived table does not contain pseudo column items and top items.

[0133] In one embodiment, the conversion module 320 is specifically configured to:

[0134] Determine the starting row number indicated by the pseudo column filtering condition in the query statement to be adjusted;

[0135] Determine the number of rows required to be filtered in the pseudo column filtering condition;

[0136] The selected starting row number and the number of rows are used as the top expression.

[0137] In one embodiment, the query adjustment device further includes an execution module, which is specifically configured to:

[0138] The top expression and the sorting expression in the query expression semantic structure are executed in sequence.

[0139] The query adjustment device provided in the embodiment of the present invention can execute the query adjustment method provided in any embodiment of the present invention, completes the adjustment of the query statement through the mutual cooperation and collaboration between the modules, and has the functional modules and beneficial effects corresponding to the execution method.

[0140] Embodiment 4

[0141] According to an embodiment of the present invention, the present invention also provides an electronic device, a computer-readable storage medium and a computer program product.

[0142] Figure 4It is a block diagram of an electronic device provided according to Embodiment 4 of the present invention, and the electronic device can implement the query adjustment method described in the embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0143] like Figure 4 As shown, the electronic device 410 includes at least one processor 411, and a memory connected to the at least one processor 411 in communication, such as a read-only memory (ROM) 412, a random access memory (RAM) 413, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 411 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 412 or the computer program loaded from the storage unit 418 to the random access memory (RAM) 413. In the RAM 413, various programs and data required for the operation of the electronic device 410 can also be stored. The processor 411, the ROM 412, and the RAM 413 are connected to each other via a bus 414. An input / output (I / O) interface 415 is also connected to the bus 414.

[0144] A number of components in the electronic device are connected to the I / O interface 415, including: an input unit 416, such as a keyboard, a mouse, etc.; an output unit 417, such as various types of displays, speakers, etc.; a storage unit 418, such as a disk, an optical disk, etc.; and a communication unit 419, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 419 allows the electronic device to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0145] The processor 411 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 411 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 411 performs the various methods and processes described above, such as the query adjustment method.

[0146] In some embodiments, the query adjustment method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as storage unit 418. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 410 via ROM 412 and / or communication unit 419. When the computer program is loaded into RAM 413 and executed by processor 411, one or more steps of the query adjustment method described above may be performed. Alternatively, in other embodiments, processor 411 may be configured to perform the query adjustment method in any other appropriate manner (e.g., by means of firmware).

[0147] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0148] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0149] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0150] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0151] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0152] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0153] In some embodiments, the computer program product includes a computer program, and when the computer program is executed by a processor, the query adjustment method provided by the embodiment of the present invention is implemented.

[0154] The technical solution of the embodiment of the present invention is through a query adjustment method, device, electronic device, storage medium and program product. First, the query statement to be adjusted is obtained; then, the pseudo-column filter condition in the query statement to be adjusted is converted into a form to obtain a top expression; then, in the query expression after the semantic analysis of the query statement to be adjusted, the pseudo-column filter condition is removed; finally, the top expression is added to the position corresponding to the pseudo-column filter condition in the semantic structure of the query expression. By converting the pseudo-column filter condition into a top expression, removing the pseudo-column filter condition, and adding the top expression to the query expression, the priority execution of the pseudo-column filter condition is achieved, and the data is filtered in advance to control the data volume of the query process within a reasonable range, reducing the amount of calculation of related calculations, improving the query performance of the database, and improving the query efficiency.

[0155] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0156] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A query adjustment method, characterized in that: include: Acquire a query statement to be adjusted, wherein the query statement to be adjusted includes a query statement to be adjusted by an execution sequence of a filtering condition; Converting the pseudo-column filtering condition in the query statement to be adjusted to obtain a top expression, wherein the pseudo-column filtering condition is a filtering condition based on a pseudo-column in a structured query language, and the pseudo-column filtering condition is a filtering condition for the outermost query in the query statement to be adjusted; In the query expression after semantic analysis of the query statement to be adjusted, removing the pseudo column filtering condition; The top expression is added to the position corresponding to the pseudo-column filtering condition in the query expression semantic structure, and the query expression semantic structure includes a semantic structure formed by the query expression of the derived table filtered by the pseudo-column filtering condition.

2. The method according to claim 1, characterized in that The step of adding the top expression to the position corresponding to the pseudo column filtering condition in the query expression semantic structure includes: The top expression is added before the sort expression in the query expression semantic structure.

3. The method according to claim 2, characterized in that The step of adding the top expression to the query expression semantic structure before the sorting expression includes: Determine a sorting node in a relationship tree corresponding to the semantic structure of the query expression; The top expression is added to the left child node of the sorting node.

4. The method according to claim 1, characterized in that The obtaining of the query statement to be adjusted includes: Get the initial query statement; Determining whether the initial query statement satisfies the condition to be adjusted; If so, the initial query statement is determined as the query statement to be adjusted.

5. The method according to claim 4, characterized in that The conditions to be adjusted include: The complete pseudo-column filter condition in the filter condition of the outermost query in the initial query statement; and, The columns in the pseudo column filter condition are columns in the derived table; and, The query statement of the derived table contains a sorting item; and, The query statement of the derived table does not contain pseudo column items and top items.

6. The method according to claim 1, characterized in that The step of converting the pseudo-column filtering condition in the query statement to be adjusted to obtain a top expression includes: Determine the starting row number indicated by the pseudo column filtering condition in the query statement to be adjusted; Determine the number of rows required to be filtered in the pseudo column filtering condition; The selected starting row number and the number of rows are used as the top expression.

7. The method according to claim 1, characterized in that After adding the top expression to the position corresponding to the pseudo column filtering condition in the query expression semantic structure, the method further includes: The top expression and the sorting expression in the query expression semantic structure are executed in sequence.

8. A query adjustment device, characterized in that: include: An acquisition module, used for acquiring a query statement to be adjusted, wherein the query statement to be adjusted includes a query statement to be adjusted by the execution timing of the filtering condition; A conversion module, used for converting the pseudo column filtering condition in the query statement to be adjusted to obtain a top expression, wherein the pseudo column filtering condition is a filtering condition based on a pseudo column in a structured query language, and the pseudo column filtering condition is a filtering condition of the outermost query in the query statement to be adjusted; A removal module, used to remove the pseudo column filtering condition in the query expression after the semantic analysis of the query statement to be adjusted; An adding module is used to add the top expression to the position corresponding to the pseudo-column filtering condition in the query expression semantic structure, and the query expression semantic structure includes a semantic structure formed by the query expression of the derived table filtered by the pseudo-column filtering condition.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the query adjustment method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the query adjustment method according to any one of claims 1 to 7 when executed.

11. A computer program product, characterized in that The computer program product comprises a computer program, which, when executed by a processor, implements the query adjustment method according to any one of claims 1 to 7.