Base estimation method and apparatus
By calculating the association between multiple specified columns and using a probabilistic graphical model to calculate the joint probability, the problem of inaccurate cardinality estimation in existing technologies is solved, achieving accurate cardinality estimation under associated and skewed distribution data, and improving database query efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NORTHEASTERN UNIV CHINA
- Filing Date
- 2023-03-31
- Publication Date
- 2026-05-19
AI Technical Summary
Existing cardinality estimation methods rely on assumptions of independence and uniform distribution, which cannot provide accurate cardinality estimates for associated and skewed data, thus affecting database query performance.
By obtaining data query requests, calculating the correlation between multiple specified columns, and using a probabilistic graphical model to calculate joint probabilities, the assumptions of independence and uniform distribution are eliminated, providing accurate cardinality estimation.
It provides accurate cardinality estimation results in multi-column query scenarios and maintains excellent performance under high load, thereby improving database query efficiency.
Smart Images

Figure CN116662378B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of computer technology in one or more embodiments, and in particular to a cardinality estimation method and apparatus. Background Technology
[0002] Cardinality estimation is a very important module in the database optimizer. This module provides the optimizer with the number of rows that a query may return, thereby guiding the choice of query plan and directly affecting or even determining the query speed.
[0003] Cardinality estimation methods in related technologies often rely on the assumptions of independence and uniform distribution. Under these assumptions, cardinality estimation is modeled as a simple statistical problem. However, real-world business data is often correlated and skewed, making it difficult for these methods to obtain accurate estimates, thus severely impacting database query performance. Summary of the Invention
[0004] In view of this, one or more embodiments of this specification provide a cardinality estimation method and apparatus.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a cardinality estimation method is proposed, comprising:
[0007] Obtain a data query request, which is used to query data from multiple first-specified columns in the database;
[0008] Calculate the joint probability of multiple first-specified columns based on the correlation between them;
[0009] Based on the joint probability, estimate the cardinality corresponding to the data query request.
[0010] According to a second aspect of one or more embodiments of this specification, a cardinality estimation apparatus is provided, comprising:
[0011] The acquisition module is used to acquire data query requests, which are used to query data from multiple first specified columns in the database.
[0012] The calculation module is used to calculate the joint probability of multiple first specified columns based on the correlation between them.
[0013] The estimation module is used to estimate the cardinality corresponding to a data query request based on the joint probability.
[0014] According to a third aspect of one or more embodiments of this specification, an electronic device is provided, comprising:
[0015] processor;
[0016] Memory used to store processor-executable instructions;
[0017] The processor implements the method described in the first aspect by running executable instructions.
[0018] According to a fourth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided that stores computer instructions thereon, which, when executed by a processor, implement the steps of the method as described in the first aspect.
[0019] The cardinality estimation method provided in this specification eliminates the reliance on independence and uniform distribution assumptions by determining the relationships between multiple first-specified columns and then calculating their joint probability. This method not only provides accurate cardinality estimation results in multi-column query scenarios but also maintains excellent performance under high load, thereby improving database query efficiency. Attached Figure Description
[0020] Figure 1 This is a schematic diagram of a system architecture provided in an exemplary embodiment.
[0021] Figure 2 This is a schematic flowchart of a cardinality estimation method provided in an exemplary embodiment.
[0022] Figure 3 This is a schematic diagram of a joint probability calculation method provided in an exemplary embodiment.
[0023] Figure 4 This is a schematic diagram of a probabilistic graphical model provided in an exemplary embodiment.
[0024] Figure 5 This is a schematic diagram illustrating a specific application of a cardinality estimation method provided in an exemplary embodiment.
[0025] Figure 6 This is a flowchart illustrating a probabilistic graphical model construction method provided in an exemplary embodiment.
[0026] Figure 7 This is a schematic diagram of a probabilistic graphical model construction process provided in an exemplary embodiment.
[0027] Figure 8 This is a schematic diagram of the structure of a device provided in an exemplary embodiment.
[0028] Figure 9 This is a schematic diagram of the structure of a cardinality estimation device provided in an exemplary embodiment. Detailed Implementation
[0029] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0030] It should be noted that the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification in other embodiments. In some other embodiments, the methods may include more or fewer steps than described in this specification. Furthermore, a single step described in this specification may be broken down into multiple steps in other embodiments; and multiple steps described in this specification may be combined into a single step in other embodiments.
[0031] In this specification, the term "cardinality" refers to the number of result entries in the query results obtained after performing a query on the database using a query statement, that is, the number of data rows obtained by the query.
[0032] Cardinality estimation (CE) is a crucial part of database query optimization. Since the cardinality of a subquery represents the size of an intermediate result, most existing cost-based query optimization techniques heavily rely on cardinality estimation for subquery plan cost estimation. A good cardinality estimation model can help the optimizer better select an appropriate query plan.
[0033] When performing cardinality estimation, related techniques are often based on the assumptions of independence and uniform distribution.
[0034] The independence assumption holds that any two columns A1 and A2 in a database table are independent. Under this assumption, the probability that A1 = 1 and A2 = 1 is P(A1, A2) = P(A1) × P(A2), where P(A1) is the probability that A1 = 1 and P(A2) is the probability that A2 = 1. The histogram method is a typical cardinality estimation method based on the independence assumption. This method summarizes each column of the database table into a histogram of equal width or equal depth. Finally, based on the query conditions and the assumption of column independence, it estimates the size of the query result. Whether the independence assumption holds depends on whether there is an inherent relationship between the columns. However, in real-world business scenarios, most data have some relationship; for example, "height" and "weight" always maintain a potential linear relationship. Therefore, for "height" and "weight," the independence assumption does not hold, and accurate cardinality estimation results cannot be obtained using related technical estimation methods.
[0035] The uniform distribution assumption posits that the values of each column in a database table appear evenly across every row. The sampling method is a typical cardinality estimation method based on this assumption. This method approximates the distribution of the entire table's data by sampling a small amount of data from the database table, but it assumes that the data values are uniformly distributed. In cases of severe data skew or when Structured Query Language (SQL) queries involve multiple table joins, the sampling method's error will increase significantly, and it can also lead to zero results due to missed samples.
[0036] Therefore, the core problem addressed in this specification is how to perform cardinality estimation for complex multi-column joint queries. To this end, this specification considers the relationships between the specified columns of the query when calculating the joint probability, thereby optimizing the solution process for joint probability in related techniques and obtaining accurate technical estimation results.
[0037] Figure 1 This is a schematic diagram of a system architecture provided in an exemplary embodiment. This system architecture 100 can be applied to the cardinality estimation method or cardinality estimation apparatus provided in this specification, and includes a user terminal 101, a server 102, and a database 103. The server 102 is equipped with a database management module.
[0038] Specifically, the database management module may include a parser 1021, an optimizer 1022, and an executor 1023. When the user terminal 101 queries the database 103 using commands in SQL, the parser 1021 first analyzes the SQL command, then the optimizer 1022 selects a query plan, and finally the executor 1023 executes it.
[0039] Optimizer 1022 is a cost-based query optimizer that selects the query plan with the lowest estimated processing cost by estimating the total number of rows (cardinality) processed at each level of the query plan and combining this with the cost pattern of the algorithms specified by the operators used in the query. In this embodiment, optimizer 1022 can be used to execute the cardinality estimation method provided in the embodiments of this specification, thereby improving the accuracy of cardinality estimation.
[0040] After the optimizer 1022 generates a query plan, the executor 1023 can execute the query plan. The query plan can be executed directly on database objects stored in the database 103. The database 103 may include data files, indexes, etc.
[0041] The following will describe the exemplary implementation method in detail with reference to the accompanying drawings and embodiments.
[0042] First, this specification provides a cardinality estimation method in its embodiments, which can be executed by any electronic device.
[0043] Figure 2 This is a flowchart illustrating a cardinality estimation method provided in an exemplary embodiment, such as... Figure 2 As shown in the embodiments of this specification, the cardinality estimation method includes the following steps.
[0044] S201, Obtain a data query request. The data query request is used to query data in multiple first specified columns in the database.
[0045] It's important to note that a database can be understood as a computer software system that stores and manages data according to a data structure. Databases typically use tables containing rows and columns to store data. Columns in a database can also be called "attributes" or "fields." A database can contain any number of tables, and each table can contain any number of rows and columns.
[0046] It should be noted that the data query requests in this manual can be database queries. For example, a data query request can be a SELECT statement in SQL. Using query statements, you can quickly filter out the desired data from the massive amounts of data stored in the database.
[0047] Specifically, data query requests can be used to query single-column data in a database, or to query multiple-column data. The method provided in this specification improves the accuracy of cardinality estimation by considering the relationships between multiple columns. Querying single-column data typically does not require considering the relationships between columns and can be achieved directly through sampling or other methods.
[0048] It should be noted that the first specified column in this specification refers to the column specified in the data query request. It should be understood that when the data query request is used to query multiple columns of data in the database, the number of first specified columns can be multiple.
[0049] In some embodiments, a data query request can specify query conditions for each first specified column, thereby enabling point queries or range queries on the first specified column in the database.
[0050] For example, suppose a data query request is used to find the names of students in the student grade table whose scores are greater than 70 and whose overall evaluation is excellent. In this case, "score" and "overall evaluation" in the "student grade table" are the two first specified columns, and "greater than 70" (range query) and "excellent" (point query) are the query conditions for the two first specified columns, respectively.
[0051] S202, calculate the joint probability of multiple first specified columns based on the correlation between them.
[0052] It should be noted that the relationships in this specification include dependency relationships and independence relationships. A dependency relationship refers to the relationship between two mutually dependent columns in the database, while an independence relationship refers to the relationship between two mutually independent columns in the database (i.e., there is no dependency relationship).
[0053] The "dependency" here can be understood as a clear, directional dependency between two data columns. For example, it is known that 90% of patients with a cold also have nasal congestion. In this case, if there are two data columns, "Number of people with colds" and "Number of people with nasal congestion," then there is a dependency between the two data columns.
[0054] It is important to note that the term "dependency" in this instruction manual is not limited to this. "Dependency" in this instruction manual can also be understood as an implicit relationship between two columns of data. For example, since mathematics and physics may share some commonalities in their thinking methods, there is also a dependency relationship between the "Mathematics Score" and "Physics Score" columns for the same student.
[0055] Furthermore, the relationships in this specification are not limited to those between columns; similar dependency and independence relationships can also exist between tables, which will not be elaborated upon in this specification.
[0056] It should be noted that the term "probability" in this specification can be understood as the frequency of occurrence of specified data in a database query request. "Probability" can also be called selection rate, which is the percentage of database table rows that meet certain conditions, such as having a specific value. "Joint probability" refers to the frequency of occurrence of specified data within a set of multiple specified columns joined together.
[0057] In some embodiments, the joint probability of multiple first specified columns can be calculated based on the association relationship between the multiple first specified columns.
[0058] Specifically, Figure 3 This is a schematic diagram illustrating a joint probability calculation method provided in an exemplary embodiment. For example... Figure 3 As shown, if multiple second specified columns exist among multiple first specified columns, a potential function is constructed among the multiple second specified columns. If a third specified column exists among the multiple first specified columns, the probability of the third specified column is calculated. Here, the multiple second specified columns are specified columns that have a mutual dependency relationship, and the third specified column is a specified column that is independent of any of the multiple first specified columns.
[0059] The joint probability of multiple first-specified columns can be obtained based on the potential function among multiple second-specified columns and / or the probability of the third-specified column.
[0060] For example, the potential function between multiple second specified columns and / or the probability of the third specified column can be multiplied to obtain the joint probability of multiple first specified columns.
[0061] In some embodiments, the relationships between multiple first-specified columns are determined by querying a preset probabilistic graphical model. To characterize the complex relationships between columns in a database, especially implicit non-directed relationships, the probabilistic graphical model in this specification can be an undirected probabilistic graphical model. In an undirected probabilistic graphical model, the influence between variables (nodes) connected by undirected edges is equivalent; there is no concept of one variable influencing or determining another variable; their influence is more like a functional relationship. Therefore, undirected probabilistic graphical models are usually decomposed into a set of functions, which are typically not any type of probability distribution. Any set of nodes in an undirected model graph that is connected pairwise by edges is called a clique. If adding any node to a clique prevents the formation of another clique, the clique is called a maximal clique. The term "potential function" in this specification is a functional representation of the joint probability of two (or more) nodes within the same clique (or maximal clique) in an undirected graphical probabilistic model.
[0062] It should be noted that the probabilistic graphical model in this specification includes multiple first nodes, each of which is used to indicate each column in the database. The connection relationship between the multiple first nodes is used to indicate the association relationship between the columns in the database. The columns in the database include multiple first specified columns.
[0063] Specifically, for each pair of first nodes among multiple first nodes, if the two first nodes are connected to each other in the probabilistic graphical model, then the columns indicated by the two first nodes are dependent; otherwise, the columns indicated by the two first nodes are independent.
[0064] Figure 4 This is a schematic diagram of a probabilistic graphical model provided in an exemplary embodiment. Figure 4 In the diagram, the first node A and the first node B are connected by an undirected edge, therefore the columns indicated by the first nodes A and B have a dependency relationship. However, the first node C and the first node B are not connected, therefore the first nodes C and B have an independent relationship.
[0065] In some embodiments, if a data query request is used to perform a first range query on a plurality of second specified columns, the first range query is decomposed into a plurality of first point queries, and the potential function among the plurality of second specified columns includes the sum of the potential functions corresponding to each first point query.
[0066] In some embodiments, if a data query request is used to perform a second range query on a third specified column, the second range query is decomposed into multiple second point queries, and the probability of the third specified column includes the sum of the probabilities corresponding to each second point query.
[0067] For example, if a data query request is used to find the names of students aged 10 to 12, this range query can be broken down into point queries targeting the names of students aged 10, 11, and 12 respectively. Then, by calculating the sum of the probability / potential functions for each point query, the probability / potential function corresponding to the age column can be obtained, which can be used for cardinality estimation.
[0068] Furthermore, to improve computational speed and thus enhance cardinality estimation performance, approximate solutions can be obtained through approximate inference methods for calculating the above probability / potential functions, such as the Markov chain Monte Carlo method. This specification does not limit the application to this method.
[0069] This specification proposes a data-driven probabilistic graphical model solution that eliminates the reliance on independence and uniform distribution assumptions in cardinality estimation. The joint probabilities obtained based on the probabilistic graphical model can effectively characterize the features of the data itself, while remaining independent of any particular style of data query request.
[0070] S203, Estimate the cardinality corresponding to the data query request based on the joint probability.
[0071] In some embodiments, the cardinality corresponding to the data query request can be obtained by multiplying the total number of rows in the full outer join result of a single table or multiple tables covered by the data query request by the join probability.
[0072] Among them, the result of a full outer join of multiple tables refers to the connection of multiple tables queried in a data query request, and the retention of all unique data after the join.
[0073] For example, if the calculated joint probability is 30% and the total amount of data covered by the data query request is 100, then the cardinality of the data query request is 30. That is, in order to complete this data query task, it is expected that 30 rows of data need to be retrieved from the database.
[0074] Figure 5 This is a schematic diagram illustrating a specific application of a cardinality estimation method provided in an exemplary embodiment.
[0075] like Figure 5 As shown, the user-input data query request "select * from A,B,C where a1=1,b2=2,c1=3" contains three first-specified columns (a1, b2, and c1). Through the query... Figure 5 As shown in the probabilistic graphical model, a1 and b2 are interconnected and have a dependency relationship. However, c1 is not connected to either a1 or b2, and c1 is independent of both a1 and b2.
[0076] Based on the above relationships, it can be seen that the data query request requires calculating the potential function between a1 and b2, as well as the probability P(c1) of c1. By multiplying the two, the joint probability P(a1,b2,c1) of a1, b2, and c1 can be obtained.
[0077] At this point, the cardinality estimate corresponding to the data query request is the product of the total number of rows in the full outer join results of tables A, B, and C and the joint probability P(a1,b2,c1).
[0078] The cardinality estimation method provided in this specification eliminates the reliance on independence and uniform distribution assumptions by determining the relationships between multiple first-specified columns and then calculating their joint probability. This method not only provides accurate cardinality estimation results in multi-column query scenarios but also maintains excellent performance under high load, thereby improving database query efficiency.
[0079] The cardinality estimation method proposed in this manual has been introduced above. To facilitate understanding, the construction method of the probabilistic graphical model involved will be described in detail below.
[0080] Figure 6 This is a flowchart illustrating a probabilistic graphical model construction method provided in an exemplary embodiment. For example... Figure 6 As shown in the embodiments of this specification, the method for constructing a probabilistic graphical model includes the following steps.
[0081] S601, obtain the first connection tree corresponding to the database. The first connection tree includes multiple second nodes, which are used to indicate each table in the database.
[0082] It should be noted that the second node in the first connection tree indicates a table in the database. In a database, tables are usually connected in the form of "primary key-primary key" or "primary key-foreign key". Therefore, by querying the primary key and foreign key relationships between the tables in the database and organizing them into a "tree" format, the first connection tree in this specification can be obtained.
[0083] S602, based on the correlation between multiple second nodes, divide the first connection tree into at least one second connection tree.
[0084] The correlation in this specification can be understood as an indicator used to evaluate the above-mentioned relationship. When the correlation between two objects (e.g., tables and columns in a database) meets certain conditions (e.g., greater than a specified threshold), it is considered that the two objects have a dependency relationship; otherwise, the two objects are independent.
[0085] In some embodiments, the correlation can be quantified by the randomized correlation coefficient (RDC).
[0086] For example, S602 can be implemented in the following way: for every two second nodes among a plurality of second nodes, if the RDC between the two second nodes meets a first preset condition, then the two second nodes are assigned to the same second connection tree.
[0087] The first preset condition can be that the RDC between two second nodes is greater than a specified threshold.
[0088] S603, for each of the at least one second connection trees, construct a sub-probabilistic graphical model corresponding to the second connection tree based on the correlation between the multiple columns corresponding to the second connection tree, wherein the probabilistic graphical model includes the sub-probabilistic graphical model.
[0089] It should be noted that the probabilistic graphical model in this specification is a collection of sub-probabilistic graphical models.
[0090] In some embodiments, similar to S602, the correlation in S603 can also be quantified based on the random correlation coefficient RDC. The specific meaning of the correlation has been introduced in S602, and will not be repeated here.
[0091] For example, S603 can be implemented as follows: For each of the at least one second connection trees, perform the following operations:
[0092] If the RDC between any two columns in the multiple columns corresponding to the second connection tree satisfies the second preset condition, then a connection is established between the third nodes corresponding to the two columns to form a sub-probabilistic graph model corresponding to the second connection tree. The sub-probabilistic graph model includes a third node, which is used to indicate the column corresponding to the second connection tree.
[0093] To facilitate understanding, the following will combine... Figure 7 This manual provides a detailed explanation of the construction process of the probabilistic graphical model. Figure 7 This is a schematic diagram of a probabilistic graphical model construction process provided in an exemplary embodiment.
[0094] exist Figure 7 In the process, the first step is to obtain the first connection tree corresponding to the database, such as... Figure 7 As shown in (a), the first connection tree includes table A, table B, table C and table D.
[0095] Subsequently, based on the relationships between tables in the database, the first join tree is divided into two second join trees, such as... Figure 7 As shown in (b), one of the second join trees includes tables A, B and C, and the other second join tree includes table D.
[0096] Next, the correlations between columns in each second connection tree are calculated, thereby generating a sub-probabilistic graphical model corresponding to each second connection number, such as... Figure 7 As shown in (c), a1, a2, a3, and a4 are columns contained in table A, b1, b2, b3, and b4 are columns contained in table B, c1, c2, and c3 are columns contained in table A, and d1, d2, d3, and d4 are columns contained in table D. The connection relationship between these columns is the association relationship.
[0097] Thus, we can obtain sub-probabilistic graphical models corresponding to the two second connection numbers respectively. The probabilistic graphical model in this specification is the set of these two sub-probabilistic graphical models.
[0098] In addition, by Figure 7 It can be seen that columns within the same second join tree may have direct or indirect dependencies. However, columns within different second join trees are independent of each other.
[0099] The embodiments in this specification first perform coarse-grained partitioning of the first connection tree corresponding to the database using RDC to obtain at least one second connection tree. Then, a divide-and-conquer strategy is used to perform fine-grained modeling of each partitioned second connection tree, thereby avoiding excessively high time complexity caused by directly modeling the global probabilistic graphical model.
[0100] The probabilistic graphical model constructed in this manual, once capturing the inherent relationships between data, does not require frequent updates, or at least does not require reconstruction of the entire probabilistic graphical model. This manual determines the relationships between multiple first-specified columns by querying the probabilistic graph, and then calculates the joint probability. This improves computational efficiency while ensuring accuracy, and maintains excellent performance even under high load scenarios.
[0101] Figure 8 This is a schematic diagram of the structure of a device provided in an exemplary embodiment. Please refer to... Figure 8 At the hardware level, the device includes a processor 802, an internal bus 804, a network interface 806, memory 808, and non-volatile memory 810, and may also include other hardware required for business operations. One or more embodiments of this specification can be implemented in software, such as the processor 802 reading the corresponding computer program from the non-volatile memory 810 into memory 808 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0102] Please refer to Figure 9 Cardinality estimation devices can be applied to, for example, Figure 8 The device shown implements the technical solution of this specification. The cardinality estimation device 900 may include: an acquisition module 901 for acquiring a data query request, the data query request being used to query data in multiple first specified columns in a database; a calculation module 902 for calculating the joint probability of the multiple first specified columns based on the association relationship between them; and an estimation module 903 for estimating the cardinality corresponding to the data query request based on the joint probability.
[0103] In some embodiments, the association relationship includes dependency and independence. The calculation module 902 can be used to: if multiple second specified columns exist among multiple first specified columns, construct a potential function among the multiple second specified columns, where the multiple second specified columns are specified columns that are mutually dependent; if a third specified column exists among the multiple first specified columns, calculate the probability of the third specified column, where the third specified column is a specified column that is independent of any of the multiple first specified columns. Based on the potential function among the multiple second specified columns and / or the probability of the third specified column, obtain the joint probability of the multiple first specified columns.
[0104] In some embodiments, the association between multiple first specified columns is determined by querying a preset probabilistic graph model. The probabilistic graph model includes multiple first nodes, each of which is used to indicate each column in the database. The connection relationship between the multiple first nodes is used to indicate the association between columns in the database. The columns in the database include multiple first specified columns.
[0105] In some embodiments, for every two first nodes among a plurality of first nodes, if the two first nodes are connected to each other in the probabilistic graphical model, then the columns indicated by the two first nodes are dependent; otherwise, the columns indicated by the two first nodes are independent.
[0106] In some embodiments, the relationships between a plurality of first specified columns are determined by querying a preset probabilistic graphical model. The cardinality estimation device 900 also includes a construction module (not shown in the figure) for constructing the probabilistic graphical model.
[0107] Specifically, the construction module can be used to: obtain a first connection tree corresponding to the database, the first connection tree including multiple second nodes, the multiple second nodes respectively indicating each table in the database; divide the first connection tree into at least one second connection tree according to the correlation between the multiple second nodes; for each second connection tree in the at least one second connection tree, construct a sub-probabilistic graphical model corresponding to the second connection tree according to the correlation between the multiple columns corresponding to the second connection tree, the probabilistic graphical model including the sub-probabilistic graphical model.
[0108] In some embodiments, the correlation is determined based on the random correlation coefficient (RDC). The construction module is also configured to, for every two second nodes among a plurality of second nodes, if the RDC between the two second nodes satisfies a first preset condition, assign the two second nodes to the same second connection tree.
[0109] In some embodiments, the correlation is determined based on the random correlation coefficient (RDC). The building module is also configured to perform the following operations for each of the at least one second connection tree: if the RDC between any two columns of the plurality of columns corresponding to the second connection tree satisfies a second preset condition, then establish a connection between the third nodes corresponding to the two columns to form a subprobabilistic graphical model corresponding to the second connection tree, the subprobabilistic graphical model including a third node, the third node being used to indicate the column corresponding to the second connection tree.
[0110] In some embodiments, the calculation module 902 is further configured to, if the data query request is used to perform a first range query on a plurality of second specified columns, decompose the first range query into a plurality of first point queries, wherein the potential function among the plurality of second specified columns includes the sum of the potential functions corresponding to each first point query. If the data query request is used to perform a second range query on a third specified column, decompose the second range query into a plurality of second point queries, wherein the probability of the third specified column includes the sum of the probabilities corresponding to each second point query.
[0111] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which can take the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email sending and receiving device, game console, tablet computer, wearable device, or any combination of these devices.
[0112] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0113] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0114] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0115] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0116] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0117] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this specification. The singular forms “a,” “described,” and “the” used in one or more embodiments of this specification and in the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0118] It should be understood that although the terms first, second, third, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first information may also be referred to as second information without departing from the scope of one or more embodiments of this specification, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "in response to a determination," or "when," or "in the event of a determination."
[0119] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit the scope of one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of one or more embodiments of this specification should be included within the protection scope of one or more embodiments of this specification.
Claims
1. A cardinality estimation method, comprising: Obtain a data query request, the data query request being used to query data in multiple first specified columns in the database; Based on the association relationships between the plurality of first specified columns, the joint probability of the plurality of first specified columns is calculated; wherein, the association relationships between the plurality of first specified columns are determined by querying a preset probability graph model, the probability graph model includes a plurality of first nodes, the plurality of first nodes are respectively used to indicate each column in the database, the connection relationships between the plurality of first nodes are used to indicate the association relationships between columns in the database, and the columns in the database include the plurality of first specified columns; Based on the joint probability, the cardinality corresponding to the data query request is estimated.
2. The method according to claim 1, wherein the association relationship includes dependency relationship and independence relationship; The step of calculating the joint probability of the multiple first specified columns based on the association relationship between the multiple first specified columns includes: If there are multiple second specified columns among the multiple first specified columns, then construct the potential function among the multiple second specified columns, wherein the multiple second specified columns are specified columns that have a mutual dependency relationship; If a third specified column exists among the plurality of first specified columns, then the probability of the third specified column is calculated. The third specified column is a specified column that is independent of any of the plurality of first specified columns. The common joint probability of the multiple first specified columns is obtained based on the potential function among the multiple second specified columns and / or the probability of the third specified column.
3. According to the method of claim 2, for every two first nodes among the plurality of first nodes, if the two first nodes are connected to each other in the probabilistic graphical model, then the columns indicated by the two first nodes are dependent; otherwise, the columns indicated by the two first nodes are independent.
4. The method according to claim 1 or 2, wherein the association relationship between the plurality of first specified columns is determined by querying a preset probabilistic graphical model, and the method for constructing the probabilistic graphical model includes: Obtain the first connection tree corresponding to the database, the first connection tree includes a plurality of second nodes, the plurality of second nodes being used to indicate each table in the database; Based on the correlation between the plurality of second nodes, the first connection tree is divided into at least one second connection tree; For each of the at least one second connection trees, a sub-probabilistic graphical model corresponding to the second connection tree is constructed based on the correlation between the multiple columns corresponding to the second connection tree, and the probabilistic graphical model includes the sub-probabilistic graphical model.
5. The method according to claim 4, wherein the correlation is determined based on the random correlation coefficient (RDC); The step of dividing the first connection tree into at least one second connection tree based on the correlation between the plurality of second nodes includes: For each pair of the plurality of second nodes, if the RDC between the two second nodes meets the first preset condition, then the two second nodes are assigned to the same second connection tree.
6. The method according to claim 4, wherein the correlation is determined based on the random correlation coefficient (RDC); For each of the at least one second connection trees, constructing a sub-probabilistic graphical model corresponding to that second connection tree based on the correlation between multiple columns corresponding to that second connection tree includes: For each of the at least one second connection trees, perform the following operations: If the RDC between any two columns in the multiple columns corresponding to the second connection tree satisfies the second preset condition, then a connection is established between the third nodes corresponding to the two columns to form a sub-probabilistic graph model corresponding to the second connection tree. The sub-probabilistic graph model includes a third node, which is used to indicate the column corresponding to the second connection tree.
7. The method according to claim 2, further comprising: If the data query request is used to perform a first range query on the plurality of second specified columns, then the first range query is decomposed into a plurality of first point queries, and the potential function between the plurality of second specified columns includes the sum of the potential functions corresponding to each first point query; If the data query request is used to perform a second range query on the third specified column, then the second range query is decomposed into multiple second point queries, and the probability of the third specified column includes the sum of the probabilities corresponding to each second point query.
8. A cardinality estimation device, comprising: The acquisition module is used to acquire a data query request, which is used to query data in multiple first specified columns in the database; The calculation module is used to calculate the joint probability of the plurality of first specified columns based on the association relationship between the plurality of first specified columns; wherein the association relationship between the plurality of first specified columns is determined by querying a preset probability graph model, the probability graph model includes a plurality of first nodes, the plurality of first nodes are respectively used to indicate each column in the database, the connection relationship between the plurality of first nodes is used to indicate the association relationship between the columns in the database, and the columns in the database include the plurality of first specified columns; An estimation module is used to estimate the cardinality corresponding to the data query request based on the joint probability.
9. An electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor implements the method as described in any one of claims 1 to 7 by executing the executable instructions.
10. A computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1 to 7.