Cardinality estimation method of database operation statements and related products

CN119782347APending Publication Date: 2025-04-08CETC JINCANG (BEIJING) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411785041.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2025-04-08

Smart Images

  • Figure CN119782347A_ABST
    Figure CN119782347A_ABST
Patent Text Reader

Abstract

The present invention provides a cardinality estimation method for database operation statements and related products. The above method includes: obtaining database operation statements; in the cardinality estimation stage, judging whether the predicate filtering conditions in the database operation statements are all connected with logical predicates; if so, judging whether the database operation statements meet preset conditions, which are conditions required for using preset extended statistical information, and the preset extended statistical information is used to record statistical information corresponding to multiple target columns with correlation in a data table; if so, cyclically searching for the best preset extended statistical information in the database operation statement to estimate the selectivity. Through this method, the accuracy of the cardinality estimation of the table under the single-table multi-predicate filtering conditions can be improved when the predicate filtering conditions are all connected with logical predicates, thereby enabling the optimizer to select a better execution plan and improve the efficiency of the query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In the current database technology field, if a single table is queried and contains multiple predicate filter conditions, the database optimizer will generally use single-column statistical information for cardinality estimation. If multiple predicate filter conditions are AND operations, cardinality estimation is performed according to the formula P(A and B) = P(A)*P(B). This cardinality estimation method is calculated based on the assumption of independence between column attributes, ignoring the correlation between multiple column attributes, and thus has a large error. Summary of the invention

[0003] In view of the above problems, the present invention proposes a cardinality estimation method for database operation statements and related products that overcome the above problems or at least partially solve the above problems.

[0004] It is an object of the present invention to improve the algorithm for cardinality estimation.

[0005] A further object of the present invention is to consider the correlation between different predicates to improve the accuracy of the selection rate estimation of the predicate filtering condition.

[0006] Another further object of the present invention is to maximize the selectivity of calculation by extending statistical information to improve the estimation accuracy.

[0007] In particular, the present invention provides a method for estimating the cardinality of a database operation statement, comprising:

[0008] Get database operation statements;

[0009] In the cardinality estimation phase, determine whether all predicate filter conditions in the database operation statement are connected with the logical predicate;

[0010] If so, determine whether the database operation statement meets the preset conditions, where the preset conditions are the conditions required to use the preset extended statistical information, and the preset extended statistical information is used to record the statistical information corresponding to multiple target columns that are correlated in the data table;

[0011] If so, the best preset extended statistical information in the database operation statement is searched cyclically to estimate the selectivity. The best preset extended statistical information is the preset extended statistical information that covers the largest number of target columns.

[0012] Optionally, the step of cyclically searching for the best preset extended statistical information in the database operation statement to estimate the selectivity includes:

[0013] Find the best preset extended statistics in the predicate filter conditions in the database operation statement;

[0014] Calculate the selection rate corresponding to the best preset extended statistical information;

[0015] Determine whether there are any remaining unevaluated predicate filter conditions;

[0016] In the case where there is an unevaluated predicate filter condition, determining whether there is a target column covered by preset extended statistical information in the target column corresponding to the unevaluated predicate filter condition;

[0017] If yes, continue to perform the step of finding the best preset extended statistics in the predicate filter condition in the database operation statement.

[0018] Optionally, after the step of determining whether there are target columns covered by preset extended statistical information in the target columns corresponding to the unevaluated predicate filtering condition, the step further includes:

[0019] When there is no target column covered by preset extended statistical information in the target column corresponding to the unestimated predicate filter condition, the unestimated predicate filter condition is estimated according to the single-column statistical information to obtain the selectivity corresponding to each column of the unestimated predicate filter condition.

[0020] Optionally, after the step of cyclically searching for the best preset extended statistical information in the database operation statement to estimate the selectivity, the step further includes:

[0021] Multiply the estimated selectivity to get the final selectivity corresponding to the database operation statement;

[0022] The cardinality estimation value corresponding to the database operation statement is calculated based on the final selectivity.

[0023] Optionally, the step of calculating the estimated cardinality corresponding to the database operation statement according to the final selectivity includes:

[0024] Get the total number of data rows in the data table corresponding to the database operation statement;

[0025] The cardinality estimate is calculated by multiplying the final selectivity by the total number of data rows.

[0026] Optionally, the step of determining whether the database operation statement meets a preset condition includes:

[0027] Get the predicate filter conditions in the database operation statement;

[0028] Determine whether the predicate filter conditions all belong to the same data table;

[0029] When all predicate filtering conditions belong to the same data table, determine whether there is preset extended statistical information in the data table;

[0030] In the case where there is preset extended statistical information in the data table, determining whether the number of predicate filtering conditions is greater than a preset threshold;

[0031] When the number of predicate filtering conditions is greater than a preset threshold, it is determined that the database operation statement meets the preset condition.

[0032] Optionally, after the step of determining whether the database operation statement satisfies a preset condition, the step further includes:

[0033] When the database operation statement does not meet the preset conditions, each column in the predicate filter condition is estimated according to the single column statistical information to obtain the selectivity corresponding to each column predicate filter condition;

[0034] Multiply the estimated selectivity to get the final selectivity corresponding to the database operation statement;

[0035] The cardinality estimation value corresponding to the database operation statement is calculated based on the final selectivity.

[0036] According to another aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned methods for estimating the cardinality of database operation statements are implemented.

[0037] According to yet another aspect of the present invention, a computer program product is provided, comprising a computer program, which implements the steps of any of the above-mentioned methods for estimating the cardinality of database operation statements when executed by a processor.

[0038] According to another aspect of the present invention, there is also provided a computer device, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements the steps of any of the above-mentioned methods for estimating the cardinality of database operation statements when executing the machine executable program.

[0039] The cardinality estimation method of the database operation statement of the present invention first obtains the database operation statement; in the cardinality estimation stage, it is judged whether the predicate filtering conditions in the database operation statement are all connected with the logical predicate; if so, it is judged whether the database operation statement meets the preset condition, the preset condition is the condition required for using the preset extended statistical information, and the preset extended statistical information is used to record the statistical information corresponding to multiple target columns with correlation in the data table; if so, the best preset extended statistical information in the database operation statement is cyclically searched for to estimate the selectivity, and the best preset extended statistical information is the preset extended statistical information covering the largest number of target columns. Through this method, the cardinality estimation algorithm can be improved when the predicate filtering conditions are all connected with the logical predicate, thereby improving the accuracy of the cardinality estimation of the table under the single table multi-predicate filtering condition. As the accuracy of the cardinality estimation of the table is improved, the optimizer can select a better execution plan to improve the efficiency of the query.

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

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

[0042] Figure 1 is a flow chart of a method for estimating the cardinality of a database operation statement according to an embodiment of the present invention;

[0043] Figure 2 is a flow chart of a method for estimating the cardinality of a database operation statement according to another embodiment of the present invention;

[0044] Figure 3 is a schematic diagram of a computer program product according to an embodiment of the present invention;

[0045] Figure 4 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and

[0046] Figure 5 is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0047] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.

[0048] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.

[0049] The present invention provides a method for estimating the cardinality of database operation statements. Figure 1 FIG. 1 is a flow chart of a method for estimating the cardinality of a database operation statement according to an embodiment of the present invention. Figure 1 As shown, the cardinality estimation method of the database operation statement at least includes the following steps S101 to S103.

[0050] Step S101, obtaining database operation statements. An optional example is SQL (Structured Query Language). SQL statements have multiple functions such as data manipulation and data definition. This language has interactive characteristics and can provide great convenience for users. In this step, the way to receive database operation statements can generally be active input by the user, or automatically generated by the database program during operation due to business needs. Those skilled in the art can decide the way to receive database operation statements according to actual conditions.

[0051] Step S102, in the cardinality estimation stage, it is determined whether all predicate filtering conditions in the database operation statement are connected with the logical predicate.

[0052] Step S103, if the judgment in step S102 is yes, it is determined whether the database operation statement meets the preset conditions. The preset conditions are generally conditions required for using preset extended statistical information, and the preset extended statistical information is generally used to record statistical information corresponding to multiple target columns with correlation in the data table.

[0053] In some optional embodiments, the step of determining whether the database operation statement meets the preset conditions may generally include: obtaining the predicate filter conditions in the database operation statement; determining whether the predicate filter conditions all belong to the same data table; if the predicate filter conditions all belong to the same data table, determining whether there is preset extended statistical information in the data table; if there is preset extended statistical information in the data table, determining whether the number of predicate filter conditions is greater than a preset threshold; if the number of predicate filter conditions is greater than the preset threshold, determining that the database operation statement meets the preset conditions. In SQL statements, a predicate is an expression used to specify conditions to filter, compare or judge data. It is a basic element that constitutes a query condition, and the return value is a Boolean type, that is, true (True) or false (False). The predicate filter condition generally refers to a conditional expression used to filter data in statements such as SELECT, WHERE, HAVING, etc., which can select row data that meets the requirements from the table according to specific conditions. The predicate filter condition generally filters data by comparing predicates, such as = (equal to), > (greater than), < (less than), > = (greater than or equal to), < = (less than or equal to) and <> or! = (not equal to). In addition, each predicate filter condition is connected by a logical predicate, and the logical predicate in the logical predicate is generally AND.

[0054] In the process of judging whether the number of predicate filter conditions is greater than the preset threshold, since the extended statistical information generally includes at least 2 columns, the preset threshold can be set to 1, that is, whether the number of predicate filter conditions is greater than 1. When the number of predicate filter conditions is at least 2, it is possible to use the corresponding extended statistical information. Those skilled in the art can set the number of preset thresholds according to actual conditions.

[0055] Step S104: if the judgment in step S103 is yes, loop through the best preset extended statistical information in the database operation statement to estimate the selectivity, wherein the best preset extended statistical information is the preset extended statistical information that covers the largest number of target columns.

[0056] Optionally, the step of cyclically searching for the best preset extended statistical information in the database operation statement to estimate the selectivity may generally include: searching for the best preset extended statistical information in the predicate filtering conditions in the database operation statement; calculating the selectivity corresponding to the best preset extended statistical information; determining whether there are any remaining unestimated predicate filtering conditions; in the case where there are unestimated predicate filtering conditions, determining whether there are any target columns covered by the preset extended statistical information in the target columns corresponding to the unestimated predicate filtering conditions; if so, continuing to execute the step of searching for the best preset extended statistical information in the predicate filtering conditions in the database operation statement.

[0057] When the preset extended statistical information covers the most columns, the number of columns with correlation is also the largest. At this time, the selectivity calculated by the best preset extended statistical information will be more accurate than the result obtained by multiplying the selectivity of each column. The operation of the loop search is that after the best preset extended statistical information is selected, the extended statistical information that covers the most columns in the remaining columns is continued to be searched as the next best preset extended statistical information, until no extended statistical information can be obtained. In this way, the selectivity is estimated as much as possible through the extended statistical information, which can maximize the accuracy of the results.

[0058] It should be noted that the best preset extended statistical information only covers more columns than other currently available extended statistical information. If two or more extended statistical information with the same number of covered columns are encountered during the judgment process, any one of them can be selected as the best preset extended statistical information according to actual needs; if two or more extended statistical information cover the same number of columns and do not repeat, the two or more extended statistical information can be used as the best preset extended statistical information at the same time for synchronous calculation.

[0059] Through this method, the cardinality estimation algorithm can be improved, so that the correlation between different predicates is considered to the greatest extent and the selectivity is calculated through extended statistical information to improve the estimation accuracy.

[0060] In some optional embodiments, after the step of determining whether there are target columns covered by preset extended statistical information in the target columns corresponding to the unestimated predicate filtering conditions, the following method may be generally further included: if there are no target columns covered by preset extended statistical information in the target columns corresponding to the unestimated predicate filtering conditions, estimating the unestimated predicate filtering conditions according to the single-column statistical information to obtain the selectivity corresponding to each column of the unestimated predicate filtering conditions. When there is no preset extended statistical information in the unestimated predicate filtering conditions, it indicates that there is no correlation in the columns corresponding to the remaining predicate filtering conditions, and therefore the selection rate is estimated according to the single-column statistical information.

[0061] Optionally, after the step of cyclically searching for the best preset extended statistical information in the database operation statement to estimate the selectivity, the step further includes: multiplying the estimated selectivities to obtain a final selectivity corresponding to the database operation statement; and calculating a cardinality estimate corresponding to the database operation statement based on the final selectivity.

[0062] In other optional embodiments, the step of calculating the cardinality estimation value corresponding to the database operation statement based on the final selection rate may generally include: obtaining the total number of data rows in the data table corresponding to the database operation statement; and multiplying the final selection rate by the total number of data rows to calculate the cardinality estimation value.

[0063] In some other optional embodiments, after the step of determining whether the database operation statement meets the preset conditions, the step further includes: if the database operation statement does not meet the preset conditions, estimating each column in the predicate filter condition according to the single column statistical information to obtain the selectivity corresponding to each column of the predicate filter condition; multiplying the estimated selectivities to obtain the final selectivity corresponding to the database operation statement; and calculating the cardinality estimation value corresponding to the database operation statement according to the final selectivity. If the predicate filter conditions do not belong to the same data table, but there are target columns corresponding to the predicate filter conditions greater than the preset threshold that belong to the same data table and the data table has preset extended statistical information, the selectivity of this part can also be calculated using the method of the present invention.

[0064] In addition, it should be noted that the method of the present invention is not only applicable to the case where all predicate filter conditions are connected through logical predicates. When the logical predicates between the predicate filter conditions in the database operation statement include logical predicates, the method of the present invention can also be used to calculate the selectivity corresponding to the part of the predicate filter conditions connected with the logical predicates.

[0065] Figure 2 FIG. 1 is a flow chart of a method for estimating the cardinality of a database operation statement according to another embodiment of the present invention. Figure 2 As shown, the cardinality estimation method of the database operation statement at least includes the following steps S201 to S212.

[0066] In order to clearly illustrate the execution process of the solution of the present invention, a specific example is proposed as shown in Formula 1:

[0067] select * from mcv_lists_multi where a=0 and b=0 and c=0 and d=0and e=0 Formula 1

[0068] It is assumed that there are five columns a, b, c, d, and e in the mcv_lists_multi table, and two extended statistics mcv_lists_multi_s1(a,b,c) and mcv_lists_multi_s2(d,e) are pre-created in the table.

[0069] Step S201, obtaining predicate filtering conditions in the database operation statement. Specifically, when the database receives the SQL statement shown in Formula 1, it obtains the predicate filtering conditions therein to form a predicate filtering condition list, including a=0, b=0, c=0, d=0, e=0.

[0070] Step S202, determining whether all predicate filtering conditions are connected with logical predicates.

[0071] Step S203, if the judgment in step S202 is yes, it is judged whether the predicate filtering conditions all belong to the same data table. Specifically, after judging that the five columns a, b, c, d, and e all belong to the data columns in the mcv_lists_multi table, it is judged yes, and step S204 is executed.

[0072] Step S204, if the judgment in step S203 is yes, it is determined whether there is preset extended statistical information in the data table. Specifically, based on the pre-set conditions, it can be determined that there is preset extended statistical information in the data table, so the judgment in step S204 is yes.

[0073] Step S205, if the judgment in step S204 is yes, it is judged whether the number of predicate filtering conditions is greater than a preset threshold. Specifically, since the number of predicate filtering conditions is 5, which is greater than the preset threshold (the preset threshold is set to 1 in this embodiment), step S205 is judged as yes.

[0074] Step S206, if the judgment in step S205 is yes, search for the best preset extended statistical information in the predicate filter condition in the database operation statement. Specifically, since the SQL statement shown in Formula 1 meets the preset conditions, the best preset extended statistical information is searched in the predicate filter condition list, and since mcv_lists_multi_s1(a,b,c) covers the largest number of columns, mcv_lists_multi_s1(a,b,c) is determined as the best preset extended statistical information in this cycle.

[0075] Step S207, calculate the selection rate corresponding to the best preset extended statistical information. There are many methods for calculating the selection rate of the extended statistical information, such as histogram calculation, frequency statistics calculation, Bayesian network calculation, sampling calculation, and machine learning calculation. Those skilled in the art can determine the specific algorithm of the selection rate according to the actual situation.

[0076] Step S208, determining whether there are any remaining unevaluated predicate filter conditions. Specifically, after the first round of loops selects the best preset extended statistical information as mcv_lists_multi_s1(a, b, c), the remaining unevaluated predicate filter conditions are d=0, e=0, so step S208 determines yes.

[0077] Step S209, if the judgment in step S208 is yes, it is determined whether there are target columns covered by the preset extended statistical information in the target columns corresponding to the unevaluated predicate filtering conditions. Specifically, since the remaining unevaluated predicate filtering conditions are d=0, e=0, and the preset extended statistical information remains mcv_lists_multi_s2(d,e), corresponding to the remaining columns, it is determined to be yes. If the judgment in step S208 is yes, step S206 is executed to loop again.

[0078] During the second cycle, the selectivity corresponding to mcv_lists_multi_s2(d,e) is estimated, and then step S208 is executed. Since there are no remaining unevaluated predicate filter conditions, step S211 is executed.

[0079] Step S210: when any of steps S203 to S205 and S209 is judged as No, the remaining unevaluated predicate filter conditions are estimated according to the single-column statistical information to obtain the selectivity corresponding to each column of unevaluated predicate filter conditions.

[0080] Step S211, when step S208 is judged as no or step S210 is completed, the estimated selectivity is multiplied to obtain the final selectivity corresponding to the database operation statement. Specifically, the selectivity of mcv_lists_multi_s1(a,b,c) and mcv_lists_multi_s2(d,e) are multiplied to obtain the final selectivity.

[0081] Step S212, calculate the cardinality estimation value corresponding to the database operation statement according to the final selection rate. Specifically, obtain the total number of data rows in the mcv_lists_multi table, and multiply the total number of data rows by the final selection rate to obtain the cardinality estimation value.

[0082] Finally, in actual use, the cardinality estimation result of the SQL statement shown in Formula 1 before applying the solution of the present invention is 29 rows, while the actual result is 142 rows, which is a large difference; after applying the solution of the present invention, the cardinality estimation result is 143 rows, while the actual result is 142 rows, which is close.

[0083] This method can improve the cardinality estimation algorithm, thereby improving the accuracy of cardinality estimation of tables under single-table multi-predicate filtering conditions. As the accuracy of cardinality estimation of tables improves, the optimizer can select a better execution plan and improve query efficiency.

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

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

[0086] This embodiment also provides a computer program product 10 , a computer readable storage medium 20 , and a computer device 30 . Figure 3 is a schematic diagram of a computer program product 10 according to an embodiment of the present invention, Figure 4 is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention, Figure 5 is a schematic diagram of a computer device 30 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which implements the steps of any of the above-mentioned methods for estimating the cardinality of database operation statements when executed by a processor 32. The computer-readable storage medium 20 stores the above-mentioned computer program 11, which implements the steps of any of the above-mentioned methods for estimating the cardinality of database operation statements when executed by the processor 32. The computer device 30 may include a memory 31, a processor 32, and the computer program 11 stored in the memory 31 and running on the processor 32.

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

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

[0089] The computer device 30 may be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, the computer device 30 may be a cloud computing node. The computer device 30 may be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module may include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device 30 may be implemented in a distributed cloud computing environment where remote processing devices linked via a communication network perform tasks. In a distributed cloud computing environment, program modules may be located on a local or remote computing system storage medium including a storage device.

[0090] The computer device 30 may include a processor 32 adapted to execute stored instructions, and a memory 31 providing temporary storage space for the operation of the instructions during operation. The processor 32 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 31 may include a random access memory (RAM), a read-only memory, a flash memory, or any other suitable storage system.

[0091] The computer device 30 may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows data to be input and output with external devices that may be connected to the computer device. The network adapter / interface may provide communication between the computer device and a network, which is typically shown as a communication network.

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

Claims

1. A method for estimating the cardinality of a database operation statement, comprising: Obtaining the database operation statement; In the cardinality estimation stage, it is determined whether all predicate filtering conditions in the database operation statement are connected with the logical predicate; If so, determining whether the database operation statement satisfies a preset condition, wherein the preset condition is a condition required for using preset extended statistical information, and the preset extended statistical information is used to record statistical information corresponding to a plurality of target columns in the data table that are correlated; If so, the best preset extended statistical information in the database operation statement is searched cyclically to estimate the selectivity, wherein the best preset extended statistical information is the preset extended statistical information that covers the largest number of target columns.

2. The method for estimating the cardinality of database operation statements according to claim 1, wherein: The step of cyclically searching for the best preset extended statistical information in the database operation statement to estimate the selectivity includes: Searching for the optimal preset extended statistical information in the predicate filtering condition in the database operation statement; Calculating the selection rate corresponding to the optimal preset extended statistical information; Determine whether there are any remaining unevaluated predicate filter conditions; In the case where the unevaluated predicate filtering condition exists, determining whether the target column corresponding to the unevaluated predicate filtering condition still has a target column covered by the preset extended statistical information; If yes, continue to execute the step of searching the best preset extended statistical information in the predicate filtering condition in the database operation statement.

3. The method for estimating the cardinality of database operation statements according to claim 2, wherein: After the step of determining whether there is a target column covered by the preset extended statistical information in the target column corresponding to the unevaluated predicate filtering condition, the following step further includes: When there is no target column covered by the preset extended statistical information in the target column corresponding to the unevaluated predicate filtering condition, the unevaluated predicate filtering condition is estimated according to the single-column statistical information to obtain the selectivity corresponding to each column of the unevaluated predicate filtering condition.

4. The method for estimating the cardinality of database operation statements according to claim 3, wherein: After the step of cyclically searching for the best preset extended statistical information in the database operation statement to estimate the selectivity, the following step is further included: Multiplying the estimated selectivity to obtain a final selectivity corresponding to the database operation statement; The cardinality estimation value corresponding to the database operation statement is calculated according to the final selection rate.

5. The method for estimating the cardinality of database operation statements according to claim 4, wherein: The step of calculating the cardinality estimation value corresponding to the database operation statement according to the final selectivity includes: Obtain the total number of data rows in the data table corresponding to the database operation statement; The cardinality estimation value is calculated by multiplying the final selection rate by the total number of data rows.

6. The method for estimating the cardinality of database operation statements according to claim 1, wherein: The step of determining whether the database operation statement meets the preset condition comprises: Obtaining the predicate filtering condition in the database operation statement; Determine whether the predicate filtering conditions all belong to the same data table; In the case where the predicate filtering conditions all belong to the same data table, determining whether the preset extended statistical information exists in the data table; In the case where the preset extended statistical information exists in the data table, determining whether the number of the predicate filtering conditions is greater than a preset threshold; When the number of the predicate filtering conditions is greater than the preset threshold, it is determined that the database operation statement meets the preset condition.

7. The method for estimating the cardinality of database operation statements according to claim 1, wherein: After the step of determining whether the database operation statement meets the preset condition, the following step is further included: When the database operation statement does not satisfy the preset condition, each column in the predicate filtering condition is estimated according to single-column statistical information to obtain a selectivity corresponding to each column of the predicate filtering condition; Multiplying the estimated selectivity to obtain a final selectivity corresponding to the database operation statement; The cardinality estimation value corresponding to the database operation statement is calculated according to the final selection rate.

8. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the cardinality estimation method for database operation statements according to any one of claims 1 to 7 are implemented.

9. A computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the cardinality estimation method for database operation statements according to any one of claims 1 to 7.

10. A computer device comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, wherein the processor implements the steps of the cardinality estimation method for database operation statements according to any one of claims 1 to 7 when executing the machine executable program.