Method, device, electronic equipment and storage medium for data query
By determining the inclusion relationship of the join columns and updating the query statement, the problem of invalid calculations in inner join operations is solved, thereby improving data query performance.
Patent Information
- Application Number
- CN202311641470.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-01
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2043-12-01
AI Technical Summary
When performing inner join operations and data restrictions on two data tables, there are many invalid calculations, which leads to increased system resource consumption and time costs, and poor data query performance.
By determining whether there is an inclusion relationship between the value ranges of the join columns, if the data push-down condition is met, the first query statement is updated, a second query statement is generated to restrict the data, and then the inner join operation is performed, reducing the amount of data processing.
When the data is pushed down, the data table is filtered first before the inner join operation is performed, which reduces the amount of data processing and improves the performance of data query.
Smart Images

Figure CN117785935B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, specifically to a method, apparatus, electronic device, and storage medium for data querying. Background Technology
[0002] In real-world business scenarios, it's often necessary to perform an inner join operation on two data tables to obtain a query result set containing the joined rows. Then, restriction sub-statements such as `LIMIT` are used to limit the data in the query result set. An inner join operation retrieves rows from two data tables that meet equality matching conditions and combines the matching rows.
[0003] However, when performing inner join operations on two data tables and data restrictions, there are often many invalid calculations, which consume a lot of system resources and time costs, resulting in poor data query performance. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, electronic device, and storage medium for data querying, so as to improve data query performance when performing data queries.
[0005] On the one hand, embodiments of this application provide a data query method, including:
[0006] Get the first query statement to be queried; the first query statement is a statement used to perform an inner join on two data tables and then apply data restrictions based on the restriction sub-statement;
[0007] Based on the first query statement, determine the first data table and the second data table used for the inner join operation, as well as the first join column in the first data table and the second join column in the second data table used for the inner join operation;
[0008] Based on the first query statement, determine whether the first join column and the second join column meet the data compression condition; the data compression condition is determined based on whether there is an inclusion relationship between the value range of the first join column and the value range of the second join column.
[0009] If the data pushdown condition is met, the first query statement is updated to obtain the second query statement; the second query statement is used to restrict the data table before performing the inner join operation.
[0010] Based on the second query statement, data is queried from the first and second data tables to obtain the data query results.
[0011] In one implementation, determining whether the first join column and the second join column meet the data pushdown condition based on the first query statement includes:
[0012] Based on the first query statement, determine whether it meets the inclusion relationship judgment condition; the inclusion relationship judgment condition is determined according to the structure of the data table;
[0013] If the inclusion relationship is determined to be met, and there is a foreign key constraint relationship between the first and second join columns or the inner join operation is a self join operation, then an inclusion relationship is determined to exist.
[0014] Based on the specified predicate operator included in the first query statement in addition to the inner join sub-statement, determine whether the data push-down condition is met; the inner join sub-statement is the sub-statement in the first query statement used for the inner join operation.
[0015] In one implementation, determining whether the inclusion relationship condition is met based on the first query statement includes:
[0016] If, based on the first query statement, it is determined that both the first data table and the second data table are basic tables, then the inclusion relationship judgment condition is met.
[0017] If, based on the first query statement, it is determined that a derived table exists in the first data table and the second data table, then, based on the subquery statement corresponding to the derived table, it is determined whether the inclusion relationship judgment condition is met; the derived table is a virtual table constructed based on the subquery statement in the first query statement.
[0018] In one implementation, determining whether the inclusion relationship condition is met based on the subquery statement corresponding to the derived table includes:
[0019] If it is determined that the subquery statement contains the specified join operator, then it is determined that the inclusion relationship judgment condition is not met;
[0020] If it is determined that the subquery statement contains aggregate operators that operate on the join columns, but does not contain extreme value operators that operate on the output of the aggregate operators, then it is determined that the inclusion relationship judgment condition is not met.
[0021] If it is determined that the subquery statement contains the specified filter operator, and the filter range of the specified filter operator does not meet the set filter conditions, then it is determined that the inclusion relationship judgment condition is not met.
[0022] If it is determined that the subquery does not contain the specified join operator, aggregation operator, or specified filter operator, then it is determined that the inclusion relationship condition is met.
[0023] If it is determined that the subquery statement contains aggregate operators and extreme value operators, but does not contain specified join operators and specified filter operators, then it is determined that the inclusion relationship judgment condition is met;
[0024] If the subquery statement contains aggregate operators, extreme value operators, and specified filter operators, but does not contain specified join operators, and meets the set filter conditions, then it is determined that the inclusion relationship judgment condition is met.
[0025] In one implementation, if it is determined that the subquery statement contains a specified filter operator, and the filter range of the specified filter operator does not meet the set filter conditions, then it is determined that the inclusion relationship judgment condition is not met, including:
[0026] Determine the filtering ranges for the first and second data tables respectively based on the specified filtering operators;
[0027] If the filter ranges corresponding to the first and second data tables do not have an overlapping relationship, then it is determined that the set filter conditions are not met.
[0028] In one implementation, determining whether the data pushdown condition is met based on a specified predicate operator included in the first query statement besides the inner join sub-statement includes:
[0029] If it is determined that the first query statement does not contain the specified predicate operator, then the data push condition is met; otherwise, the data push condition is not met.
[0030] If the first query statement is determined to contain a specified predicate operator, and the associated data table of the specified predicate operator is the same as the data table containing the included join column, then the data push condition is met; otherwise, the data push condition is not met. The associated data table is the data table operated on by the specified predicate operator.
[0031] In one implementation, updating the first query statement to obtain the second query statement includes:
[0032] Based on the inclusion relationship, the data table containing the included join column is used as the target data table;
[0033] Based on the restriction sub-statement in the first query statement, generate a target sub-statement for restricting data in the target data table;
[0034] Generate a conditional sub-statement to restrict the join columns of the target data table from being empty;
[0035] The first query statement, the target sub-statement, and the conditional sub-statement are combined to obtain the second query statement.
[0036] On one hand, embodiments of this application provide a data query apparatus, including:
[0037] The retrieval unit is used to retrieve the first query statement to be queried; the first query statement is a statement used to perform an inner join on two data tables and then apply data restrictions based on the restriction sub-statement;
[0038] The determining unit is configured to determine, based on the first query statement, a first data table and a second data table for the inner join operation, as well as a first join column in the first data table and a second join column in the second data table for the inner join operation.
[0039] The judgment unit is used to determine whether the first join column and the second join column meet the data push-down condition based on the first query statement; the data push-down condition is determined based on whether there is an inclusion relationship between the value range of the first join column and the value range of the second join column.
[0040] The update unit is used to update the first query statement and obtain the second query statement if it is determined that the data push-down condition is met. The second query statement is used to restrict the data table before performing the inner join operation.
[0041] The query unit is used to perform data queries on the first and second data tables according to the second query statement, and obtain the data query results.
[0042] In one implementation, the determining unit is used to:
[0043] Based on the first query statement, determine whether it meets the inclusion relationship judgment condition; the inclusion relationship judgment condition is determined according to the structure of the data table;
[0044] If the inclusion relationship is determined to be met, and there is a foreign key constraint relationship between the first and second join columns or the inner join operation is a self join operation, then an inclusion relationship is determined to exist.
[0045] Based on the specified predicate operator included in the first query statement in addition to the inner join sub-statement, determine whether the data push-down condition is met; the inner join sub-statement is the sub-statement in the first query statement used for the inner join operation.
[0046] In one implementation, the determining unit is used to:
[0047] If, based on the first query statement, it is determined that both the first data table and the second data table are basic tables, then the inclusion relationship judgment condition is met.
[0048] If, based on the first query statement, it is determined that a derived table exists in the first data table and the second data table, then, based on the subquery statement corresponding to the derived table, it is determined whether the inclusion relationship judgment condition is met; the derived table is a virtual table constructed based on the subquery statement in the first query statement.
[0049] In one implementation, the determining unit is used to:
[0050] If it is determined that the subquery statement contains the specified join operator, then it is determined that the inclusion relationship judgment condition is not met;
[0051] If it is determined that the subquery statement contains aggregate operators that operate on the join columns, but does not contain extreme value operators that operate on the output of the aggregate operators, then it is determined that the inclusion relationship judgment condition is not met.
[0052] If it is determined that the subquery statement contains the specified filter operator, and the filter range of the specified filter operator does not meet the set filter conditions, then it is determined that the inclusion relationship judgment condition is not met.
[0053] If it is determined that the subquery does not contain the specified join operator, aggregation operator, or specified filter operator, then it is determined that the inclusion relationship condition is met.
[0054] If it is determined that the subquery statement contains aggregate operators and extreme value operators, but does not contain specified join operators and specified filter operators, then it is determined that the inclusion relationship judgment condition is met;
[0055] If the subquery statement contains aggregate operators, extreme value operators, and specified filter operators, but does not contain specified join operators, and meets the set filter conditions, then it is determined that the inclusion relationship judgment condition is met.
[0056] In one implementation, the determining unit is used to:
[0057] Determine the filtering ranges for the first and second data tables respectively based on the specified filtering operators;
[0058] If the filter ranges corresponding to the first and second data tables do not have an overlapping relationship, then it is determined that the set filter conditions are not met.
[0059] In one implementation, the determining unit is used to:
[0060] If it is determined that the first query statement does not contain the specified predicate operator, then the data push condition is met; otherwise, the data push condition is not met.
[0061] If the first query statement is determined to contain a specified predicate operator, and the associated data table of the specified predicate operator is the same as the data table containing the included join column, then the data push condition is met; otherwise, the data push condition is not met. The associated data table is the data table operated on by the specified predicate operator.
[0062] In one implementation, the updating unit is used to:
[0063] Based on the inclusion relationship, the data table containing the included join column is used as the target data table;
[0064] Based on the restriction sub-statement in the first query statement, generate a target sub-statement for restricting data in the target data table;
[0065] Generate a conditional sub-statement to restrict the join columns of the target data table from being empty;
[0066] The first query statement, the target sub-statement, and the conditional sub-statement are combined to obtain the second query statement.
[0067] On one hand, embodiments of this application provide an electronic device, including:
[0068] Processor; and
[0069] The memory stores computer instructions that cause the processor to perform the steps of the methods provided in various alternative implementations of any of the above-described data query methods.
[0070] On one hand, embodiments of this application provide a storage medium storing computer instructions for causing a computer to perform the steps of the methods provided in various optional implementations of any of the above-described data query methods.
[0071] The data query method, apparatus, electronic device, and storage medium provided in this application embodiment obtain a first query statement to be queried. The first query statement is a statement used to perform an inner join on two data tables and then perform data restrictions based on a restriction sub-statement. Based on the first query statement, a first data table and a second data table are determined for the inner join operation, as well as a first join column in the first data table and a second join column in the second data table. Based on the first query statement, it is determined whether the first join column and the second join column meet the data compression condition. The data compression condition is determined based on whether there is an inclusion relationship between the value ranges of the first join column and the value ranges of the second join column. If it is determined that the data compression condition is met, the first query statement is updated to obtain a second query statement. The second query statement is used to perform data restrictions on the data tables before performing the inner join operation. Based on the second query statement, data is queried on the first and second data tables to obtain the data query result. In this way, when the data compression condition is met, the data tables can be filtered first, and then the inner join operation can be performed, thereby reducing the amount of data processing and improving data query performance. Attached Figure Description
[0072] To more clearly illustrate the technical solutions in the specific embodiments of this application or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0073] Figure 1 This is a flowchart of a data query method according to an embodiment of this application.
[0074] Figure 2 This is a detailed flowchart of a data query method according to an embodiment of this application.
[0075] Figure 3 This is a structural block diagram of the data query device in the embodiments of this application.
[0076] Figure 4 This is a schematic diagram of the structure of the electronic device in the embodiments of this application. Detailed Implementation
[0077] The technical solution of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application. Furthermore, the technical features involved in the different embodiments of this application described below can be combined with each other as long as they do not conflict with each other.
[0078] First, some of the terms used in the embodiments of this application will be explained to facilitate understanding by those skilled in the art.
[0079] Terminal devices can be mobile terminals, fixed terminals, or portable terminals, such as mobile phones, sites, units, devices, multimedia computers, multimedia tablets, internet nodes, communicators, desktop computers, laptop computers, notebook computers, netbook computers, tablet computers, personal communication system devices, personal navigation devices, personal digital assistants, audio / video players, digital cameras / camcorders, positioning devices, television receivers, radio broadcast receivers, e-book devices, gaming devices, or any combination thereof, including accessories and peripherals of these devices, or any combination thereof. It is also foreseeable that terminal devices can support any type of user-facing interface (e.g., wearable devices).
[0080] Servers can be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, and big data and artificial intelligence platforms.
[0081] Inner join: A relational algebra join that returns rows that are equal in two tables.
[0082] Self-join: A special type of equi-join in inner join queries. A self-join involves joining a table with itself. In a self-join, the two join columns are essentially the same column, and all rows correspond one-to-one. Therefore, it's possible to apply downward pressure (i.e., filtering) to either table. It's important to note that since databases may have partitioned tables, the columns involved in a self-join must be from the same table, the same column, and the same partition.
[0083] Base table: This is a table that exists independently. In Structured Query Language (SQL), one relation corresponds to one table.
[0084] Derived tables are named temporary tables (i.e., virtual tables) that are the result sets of subqueries obtained from subqueries contained in a query statement.
[0085] The LIMIT statement is used to return a specified number of rows from the result set of a data query.
[0086] Filterability: refers to whether the output of an operation reduces the number of rows compared to the input data.
[0087] Foreign key: A field in one table corresponds to a field in another table, used to represent the relationship between the two tables.
[0088] The technical concept of this application will be explained below.
[0089] In real-world business scenarios, it's common practice to perform an inner join on two data tables and then use a LIMIT statement to push the data down to achieve data limitation. For example, consider a student data table and a student grade table, where the join column in both tables is the student ID. If the student ID in the first row of the student data table is 002, and the student ID in the third row of the student grade table is also 002, then the first and third rows are considered to be identical, and these two rows are joined.
[0090] However, when performing inner join operations on two data tables and data restrictions, there are often many invalid calculations, which consume a lot of system resources and time costs, resulting in poor data query performance.
[0091] In traditional techniques, the data table can usually be pushed down before the left outer join operation, and then the left outer join operation can be performed. However, this method cannot be applied to the push-down scenario of inner join.
[0092] In view of the deficiencies of the aforementioned related technologies, the present application provides a method, apparatus, electronic device and storage medium for data query, which aims to reduce the amount of data processing and improve the performance of data query when performing data query.
[0093] This application provides a data query method that can be applied to electronic devices. This application does not limit the type of electronic device; it can be any suitable device type, such as a smartphone or tablet computer, which will not be elaborated further. In this embodiment, the application to a database (e.g., Ocean Base) is used as an example for illustration.
[0094] See Figure 1 The diagram shown is a flowchart of a data query method according to an embodiment of this application. The following is a detailed explanation. Figure 1 The method is described below, and the specific implementation process is as follows:
[0095] Step 100: Obtain the first query statement to be queried.
[0096] The first query statement is used to perform an inner join on two data tables and then apply data restrictions based on a restriction sub-statement. Specifically, the first query statement includes an inner join sub-statement for performing an inner join operation on the first and second data tables, as well as a restriction sub-statement.
[0097] As an example, the inner join statement can be either an INNER JOIN clause or a JOIN clause, which compares each record (i.e., each row) in the first data table table1 with each record in the second data table table2 to find pairs of records that satisfy equality matching, and then merges each pair of matching records into a new result row.
[0098] It should be noted that, in this embodiment of the application, equality matching of inner joins means that the column value of the first join column in table1 is the same as the column value of the second join column in table2.
[0099] Step 101: Based on the first query statement, determine the first data table and the second data table used for the inner join operation, as well as the first join column in the first data table and the second join column in the second data table used for the inner join operation.
[0100] Specifically, the first data table and the second data table are two data tables used for inner join operations; the first join column and the second join column are the join columns in the corresponding data tables used for inner join operations.
[0101] In one implementation, the first query statement includes the names of the first data table, the first join column, the second data table, and the second join column, respectively. Therefore, the first data table, the first join column, the second data table, and the second join column can be directly obtained from the first query statement. As an example, the first query statement includes T1 and T2, where T1 and T2 are the table names of the first data table and the second data table, respectively.
[0102] In one implementation, at least one of the first data table, the first join column, the second data table, and the second join column is generated based on a sub-statement in the first query statement. Therefore, the first query statement does not directly contain the table name or column name of the inner join.
[0103] As an example, the first query statement contains T1 and a subquery statement q based on T1. T1 is the first data table, and the data table formed by the subquery statement q is the second data table.
[0104] Step 102: Based on the first query statement, determine whether the first join column and the second join column meet the data push-down condition.
[0105] The data compression condition is determined based on whether there is an inclusion relationship between the value ranges of the first and second join columns. It should be noted that the value range of a join column refers to the set of values from all columns within that join column.
[0106] In one implementation, step 102 may be performed using the following steps:
[0107] S1021: Based on the first query statement, determine whether it meets the inclusion relationship judgment condition.
[0108] The inclusion relationship determination criteria are determined based on the structure of the data table.
[0109] In one implementation, when executing S1021, the following method can be used:
[0110] The first method: If the first query statement determines that both the first and second data tables are base tables, then the inclusion relationship condition is met. It should be noted that a base table is an independent table; in SQL, one relation corresponds to one table.
[0111] The second approach: If the first query statement determines that there are derived tables in the first and second data tables, then the subquery statement corresponding to the derived table is used to determine whether the inclusion relationship condition is met.
[0112] In this context, a derived table is a virtual table constructed based on the subquery statements in the first query statement. A derived table is a subquery result set in a query process; it's a named temporary table, the name of which is assigned by the user in the SQL statement. For example, in `select * from (select * from athors) temp`, `temp` is the derived table.
[0113] In one implementation, when executing the second method, the following approach can be used:
[0114] Method 1: If the subquery statement contains the specified join operator, then the inclusion condition is not met. The specified join operator is the operator used for joining; as an example, the specified join operator can be `join`. In practice, the specified join operator can be set according to the actual application scenario, and there are no restrictions here.
[0115] Method 2: If the subquery statement contains aggregate operators that operate on the join columns, but does not contain extreme value operators that operate on the output of the aggregate operators, then it is determined that the inclusion relationship judgment condition is not met.
[0116] As an example, the aggregation operator is aggr, and the extremum operators include min and max. A subquery statement can then contain aggr and min respectively, which are used to perform aggregation operations on the first column (i.e., the join column) of the data table using the aggregation operator aggr, and then use the extremum operator min to determine the minimum value of each aggregation.
[0117] Method 3: If it is determined that the subquery statement contains the specified filter operator, and the filter range of the specified filter operator does not meet the set filter conditions, then it is determined that the inclusion relationship judgment condition is not met.
[0118] As an example, the specified filter operator can include at least one of the following: where-condition, semi-join, and limit. The specified filter operator is the operator used for filtering. In practice, the specified filter operator can be set according to the actual application scenario, and there are no restrictions here.
[0119] In one implementation, the filtering ranges of the first data table and the second data table are determined according to a specified filtering operator; if the filtering ranges corresponding to the first data table and the second data table do not have an overlapping relationship, it is determined that the set filtering conditions are not met.
[0120] As an example, both the first and second data tables are derived tables, generated by the first and second subqueries in the first query statement, respectively. The first subquery statement contains a first specified filter operator `where id>10`, and a second specified filter operator `where id>0`. Obviously, the filtering range of `where id>0` covers the filtering range of `where id>10`.
[0121] It should be noted that if the first query statement contains only one specified filter operator, it can be determined that the two filter ranges have an inclusion relationship. This is because the unfiltered global range must cover the filtered local range.
[0122] Method 4: If it is determined that the subquery does not contain the specified join operator, aggregation operator, or specified filter operator, then it is determined that the inclusion relationship judgment condition is met.
[0123] Method 5: If the subquery statement contains aggregate operators and extreme value operators, but does not contain specified join operators and specified filter operators, then it is determined that the inclusion relationship judgment condition is met.
[0124] Method 6: If the subquery statement contains aggregate operators, extreme value operators, and specified filter operators, but does not contain specified join operators, and meets the set filter conditions, then it is determined that the inclusion relationship judgment condition is met.
[0125] S1022: If the inclusion relationship condition is met, and there is a foreign key constraint relationship between the first join column and the second join column, or the inner join operation is a self join operation, then the inclusion relationship is determined to exist.
[0126] It's important to note that setting foreign key constraints requires at least two tables: the table being constrained is called the child table, and the other is called the parent table, forming a master-detail relationship. Foreign key constraints are used to establish a link between data in two tables, where a field (another name for a column) in one table is constrained by a corresponding field in the other table.
[0127] As an example, if the first data table is the primary table and the second data table is the secondary table, and the connecting column of the first and second data tables is field A, then field A of the first data table can be used as a foreign key of the second data table. Therefore, the set of values (i.e., the range) of each column in the second connecting column must be included in the range of values of the first connecting column.
[0128] Therefore, if there is a foreign key constraint relationship between the first join column and the second join column, then an inclusion relationship can be determined.
[0129] Furthermore, since a self-join is a special type of equi-join in inner join queries, a self-join means that a table is joined with itself. Therefore, if a self-join is performed on two data tables, it is essentially an inner join on two identical tables. Thus, if an inner join is a self-join, there must be an inclusion relationship between them.
[0130] S1023: Determine whether the data pushdown condition is met based on the specified predicate operator contained in the first query statement in addition to the inner join sub-statement.
[0131] Optionally, the specified predicate operator may include at least one of the following functions: where-condition, order-by, and semi-join. The specified predicate operator can be an operator used for operations such as filtering, sorting, and semi-joins. In practice, the specified predicate operator can be set according to the actual application scenario, and there are no restrictions here.
[0132] In one implementation, when executing S1023, the following method can be used:
[0133] Method 1: If it is determined that the first query statement does not contain the specified predicate operator, then the data push-down condition is met.
[0134] Method 2: If it is determined that the first query statement also contains the specified predicate operator, and the associated data table of the specified predicate operator is the same as the data table containing the included join column, then it is determined that the data push-down condition is met; otherwise, it is determined that the data push-down condition is not met; the associated data table is the data table operated on by the specified predicate operator.
[0135] Specifically, for ease of explanation, the data table containing the included join column can be referred to as the target data table. If the value range of the first join column in the first data table includes the value range of the second join column in the second data table, then the second data table is determined to be the target data table; otherwise, the first data table is determined to be the target data table.
[0136] Step 103: If the data pushdown condition is met, update the first query statement to obtain the second query statement.
[0137] The second query statement is used to restrict the data in the data table before performing the inner join operation.
[0138] In one implementation, step 103 may be performed using the following steps:
[0139] S1031: Based on the inclusion relationship, the data table containing the included join column is used as the target data table.
[0140] S1032: Based on the restriction sub-statement in the first query statement, generate a target sub-statement for restricting data in the target data table.
[0141] The target sub-statement contains a restriction sub-statement, and optionally, other sub-statements for filtering. The restriction sub-statement is used to limit data; for example, it can be `limit`.
[0142] S1033: Generates a conditional sub-statement to restrict the join columns of the target data table from being empty.
[0143] S1034: Combine the first query statement, the target sub-statement, and the conditional sub-statement to obtain the second query statement.
[0144] Step 104: Based on the second query statement, perform data queries on the first and second data tables to obtain the data query results.
[0145] In this way, we can first restrict the target data table by generating the target sub-statement based on the restriction sub-statement, and then perform an inner join on the processed data table based on the non-empty condition sub-statement and the inner join sub-statement.
[0146] It's important to note that a sufficient condition for pushing data down on two tables before performing an inner join operation is that there must be an inclusion relationship between the value ranges of the two columns involved in the inner join operation; that is, the inner join has no filtering property. If the value range of the second join column includes the value range of the first join column, then each row in the first column can be matched with one or more rows in the second column. Therefore, the inner join operation will succeed with every non-empty row in the first table and the second table, and the number of rows obtained after the inner join operation will be greater than the number of rows in the first table. In this case, pushing data down on the first table has no semantic change; that is, the final query result of the inner join operation remains unchanged.
[0147] If both tables in an inner join operation are base tables, then it's only necessary to check whether the join columns meet foreign key constraints or are self-joined, and whether the table involved in the specified predicate operator is the target table. However, if a derived table exists, it's necessary to first determine whether the subquery statements constituting the derived table meet the inclusion condition to identify any factors that might have violated the inclusion relationship. If the inclusion condition is met, then it's necessary to check whether the derived table meets foreign key constraints or is self-joined, and whether the table involved in the specified predicate operator is the included target table.
[0148] In this way, when the data push-down condition is met, the included target data table can be pushed down before the inner join operation is performed, thereby reducing the amount of data processing and the cost, and improving data query performance.
[0149] The following is combined Figure 2 The above embodiments will be described in detail. Figure 2 Here is a detailed flowchart of a data query method, combined with... Figure 2 The method is described below, and the specific implementation process is as follows:
[0150] Step 201: Obtain the first query statement for the inner join operation.
[0151] Specifically, when a query statement to be processed is received, if the query statement to be processed is a statement used for inner join operations, then the query statement to be processed is determined to be the first query statement.
[0152] Furthermore, if the query statement to be processed is not a statement used for inner join operations, then the query statement to be processed is executed directly, or the join method of the query statement to be processed is determined, and the query statement to be processed is executed according to other algorithms corresponding to that join method.
[0153] Step 202: Based on the first query statement, determine whether both data tables are basic tables. If so, proceed to step 203; otherwise, proceed to step 209.
[0154] In one implementation, if the data table used for the inner join operation in the first query statement is an independent table, then it is the base table.
[0155] Furthermore, if the data table used for inner join operations in the first query statement is a virtual table constructed by subqueries in the first query statement, then it is determined to be a derived table.
[0156] Step 203: Determine if there is an inclusion relationship between the connected columns. If yes, proceed to step 204; otherwise, proceed to step 208.
[0157] Specifically, if there is a foreign key constraint between the two joined columns (i.e., the first joined column and the second joined column) or the inner join operation is a self join operation, then an inclusion relationship is determined to exist; otherwise, an inclusion relationship is determined not to exist.
[0158] Step 204: Determine the target data table based on the inclusion relationship.
[0159] Step 205: Based on the specified predicate operator included in the first query statement in addition to the inner join sub-statement, and the target data table, determine whether the data push-down condition is met. If yes, proceed to step 206; otherwise, proceed to step 208.
[0160] Specifically, the specified predicate operator can include at least one of the following: where-condition, order-by, and semi-join. If the associated data table operated on by the specified predicate operator is the target data table, that is, the specified predicate operator in the first query statement is used to perform operations such as filtering and sorting on the target data table, then the data push-down condition is determined to be met.
[0161] Thus, if the data table involved in the specified predicate operator (i.e., the associated data table) is the same table as the data table to be pushed down (i.e., the target data table), then the target data table can be pushed down.
[0162] Step 206: Combine the first query statement, the target sub-statement, and the conditional sub-statement to obtain the second query statement.
[0163] Specifically, based on the restriction sub-statement in the first query statement, a target sub-statement is generated to restrict data in the target data table; a conditional sub-statement is generated to restrict the join column of the target data table from being empty; the first query statement, the target sub-statement, and the conditional sub-statement are combined to obtain the second query statement.
[0164] This is because inner joins do not retain rows where the join column is null. Therefore, it is necessary to add a condition that the join column is not null in the target data table to ensure the correctness of the semantics.
[0165] Step 207: Perform a data query on the two data tables according to the second query statement to obtain the data query results.
[0166] Specifically, the second query statement first pushes down the target data table to obtain the pushed target data table. Then, an inner join operation is performed on the pushed target data table and the remaining data tables to obtain the data query results.
[0167] The remaining data tables are the data tables in the first and second data tables other than the target data table, that is, the data tables in the first and second data tables that contain the target data table.
[0168] Step 208: End the process.
[0169] Step 209: Obtain the subquery statement used to construct the derived table from the first query statement.
[0170] The subquery statement is the SELECT clause used to construct the derived table.
[0171] As an example, if the first or second data table is a derived table, then the corresponding subquery statement is retrieved.
[0172] As another example, if both the first and second data tables are derived tables, then the subquery statements corresponding to the first and second data tables can be retrieved respectively.
[0173] In this way, the derived tables and their corresponding number can be determined based on the subquery statements in the first query statement.
[0174] Step 210: Determine whether the subquery statement does not contain the specified join operator. If yes, proceed to step 211; otherwise, proceed to step 208.
[0175] Here, the specified join operator is a statement used for data joining.
[0176] As an example, the specified join operator can be "join".
[0177] Step 211: Determine whether there is an aggregate operator in the subquery statement that operates on the join column. If yes, proceed to step 212; otherwise, proceed to step 203.
[0178] The aggregation operator can be aggr.
[0179] Step 212: Determine whether there is an extreme value operator in the subquery statement that performs an output operation on the aggregate operator. If yes, proceed to step 213; otherwise, proceed to step 208.
[0180] The maximum value operator can be max, and the minimum value operator can be min.
[0181] Step 213: Determine whether the specified filter operator exists in the subquery statement. If yes, proceed to step 214; otherwise, proceed to step 208.
[0182] The specified filter operator is the operator used for data filtering.
[0183] Optionally, the specified filtering operator may include at least one of the following: where-condition, semi-join, and limit.
[0184] Step 214: Determine whether the filtering range of the specified filtering operator meets the set filtering conditions. If yes, proceed to step 203; otherwise, proceed to step 208.
[0185] Specifically, when performing steps 201-214, please refer to steps 100-104 above for the specific steps, which will not be repeated here.
[0186] The following example illustrates the above implementation using a query statement. The following table creation statement, `create table t1(id int primary key,c1 int,c2 int)`, creates a table `t1`. This statement shows that `t1` contains three columns, with values for `id`, `c1`, and `c2`, where `id` is the primary key. A query statement for `t1` would be:
[0187] SELECT * FROM
[0188] (SELECT id,MAX(c1)AS aggr FROM t1 WHERE id>10GROUP BY id)view1
[0189] JOIN
[0190] (SELECT c1 FROM t1 WHERE id>0)view2
[0191] ON view1.aggr = view2.c1
[0192] ORDER BY view1.id
[0193] LIMIT 10;
[0194] First, determine if the query statement is the first query statement used for an inner join operation. Specifically, since the query statement contains the inner join character "JOIN", it is determined to be the first query statement used for an inner join operation. Furthermore, the first and second data tables for the inner join operation are view1 and view2, respectively. Based on view1.aggr = view2.c1, the first join column in view1 used for the inner join operation is view1.aggr, and the second join column in view2 used for the inner join operation is view2.c1.
[0195] Secondly, the table types of each data table are determined based on the first query statement. Specifically, since the first query statement contains two subqueries that constitute derived tables, namely the first subquery statement corresponding to view1: SELECT id,MAX(c1)ASaggr FROM t1 WHERE id>10GROUP BY id, and the second subquery statement corresponding to view2: SELECT c1FROM t1 WHERE id>0, therefore, both the first and second data tables in the first query statement are derived tables.
[0196] Next, it was determined that all subqueries contained specified join operators. Therefore, the aggregation operators in each subquery were evaluated. Specifically, the first subquery contained the aggregation operator `aggr` for the first join column, and also contained the maximum value operator `MAX(c1)` for that aggregation operator, thus satisfying the condition that there was no specified join operator but there were aggregation operators and extremum operators operating on the join column. The second subquery did not contain any specified join operators or aggregation operators.
[0197] Furthermore, the judgment is based on whether the subquery contains the specified filter operator. Specifically, the first subquery contains the specified filter operator for the first join column, namely WHERE id>10, and the second subquery contains the specified filter operator for the second join column, namely WHERE id>0. Therefore, the filter range of WHERE id>0 covers the filter range of WHERE id>10, so it meets the inclusion relationship judgment condition.
[0198] Next, determine if there is an inclusion relationship between the join columns. Specifically, determine that the inner join operation is a self join operation. This is because the column to which the first join column belongs is actually t1.c1, and the column to which the second join column belongs is also actually t1.c1. Furthermore, there is no partition on table t1. Therefore, it is a self join operation. Thus, it is determined that the value range of the first join column is contained within the value range of the second join column, and the first data table is the target data table.
[0199] Next, an update judgment is made based on the specified predicate operator included in the first query statement, in addition to the inner join sub-statement. Specifically, the inner join sub-statement is the sub-statement used for the inner join operation in the first query statement. Since the first query statement also includes the specified predicate operator ORDER BY, and according to ORDER BY view1.id, we know that ORDER BY is used to sort the first data table, i.e., the target data table. Therefore, the data compression condition is met, and the target sub-statement ORDER BY id limit 10 is generated to compress the first data table and achieve data restriction.
[0200] Furthermore, a conditional sub-statement, WHERE aggr IS NOT NULL, can be generated to restrict the join columns of the target data table to be non-nullable.
[0201] Next, by combining the first subquery with the target subquery and the conditional subquery, we can obtain a new first data table, newview.
[0202] ((SELECT id,MAX(c1)AS aggr FROM t1 WHERE id>10GROUP BY id)WHERE aggrIS NOT NULL ORDER BY id limit 10).
[0203] Furthermore, based on the new first subquery, the first query is updated to obtain the second query, namely:
[0204] SELECT*FROM((SELECT id,MAX(c1)AS aggr FROM t1 WHERE id>10GROUP BY id)
[0205] WHERE aggr IS NOT NULL ORDER BY id limit 10)newview
[0206] JOIN
[0207] (SELECT c1 FROM t1 WHERE id>0)view2
[0208] ON newview.aggr = view2.c1
[0209] ORDER BY newview.id
[0210] LIMIT 10.
[0211] In this embodiment, the system determines whether the data compression condition is met based on whether the value ranges of the first and second join columns are inclusive. If so, data compression is performed on the target table included in the two tables before the inner join operation is executed. This effectively reduces the amount of data processing, system resources, and time costs associated with join calculations, thereby improving data processing efficiency and query performance. Furthermore, regardless of whether the two sides of the inner join are base tables or derived tables, it can be determined whether compression can be performed before the inner join. This allows for application in complex scenarios involving derived tables, making it widely applicable and providing convenience for users.
[0212] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0213] Based on the same inventive concept, this application also provides a data query device. Since the principle of the above-described device and apparatus in solving the problem is similar to that of a data query method, the implementation of the above-described device can refer to the implementation of the method, and repeated details will not be described again. This device can be applied to electronic devices. This application does not limit the type of electronic device; it can be any suitable type of device, such as smartphones, tablet computers, etc., which will not be described again in this application.
[0214] See Figure 3 The diagram shown is a structural block diagram of a data query apparatus according to an embodiment of this application. In some embodiments, the data query apparatus exemplified in this application includes:
[0215] The acquisition unit 301 is used to acquire the first query statement to be queried; the first query statement is a statement used to perform an inner join on two data tables and then perform data restrictions based on the restriction sub-statement;
[0216] The determining unit 302 is used to determine, according to the first query statement, a first data table and a second data table for the inner join operation, as well as a first join column in the first data table and a second join column in the second data table for the inner join operation.
[0217] The judgment unit 303 is used to determine whether the first join column and the second join column meet the data compression condition based on the first query statement; the data compression condition is determined based on whether there is an inclusion relationship between the value range of the first join column and the value range of the second join column.
[0218] Update unit 304 is used to update the first query statement and obtain the second query statement if it is determined that the data push-down condition is met; the second query statement is used to restrict the data table before performing the inner join operation.
[0219] The query unit 305 is used to perform data query on the first data table and the second data table according to the second query statement, and obtain the data query result.
[0220] In one embodiment, the determination unit 303 is used to:
[0221] Based on the first query statement, determine whether it meets the inclusion relationship judgment condition; the inclusion relationship judgment condition is determined according to the structure of the data table;
[0222] If the inclusion relationship is determined to be met, and there is a foreign key constraint relationship between the first and second join columns or the inner join operation is a self join operation, then an inclusion relationship is determined to exist.
[0223] Based on the specified predicate operator included in the first query statement in addition to the inner join sub-statement, determine whether the data push-down condition is met; the inner join sub-statement is the sub-statement in the first query statement used for the inner join operation.
[0224] In one embodiment, the determination unit 303 is used to:
[0225] If, based on the first query statement, it is determined that both the first data table and the second data table are basic tables, then the inclusion relationship judgment condition is met.
[0226] If, based on the first query statement, it is determined that a derived table exists in the first data table and the second data table, then, based on the subquery statement corresponding to the derived table, it is determined whether the inclusion relationship judgment condition is met; the derived table is a virtual table constructed based on the subquery statement in the first query statement.
[0227] In one embodiment, the determination unit 303 is used to:
[0228] If it is determined that the subquery statement contains the specified join operator, then it is determined that the inclusion relationship judgment condition is not met;
[0229] If it is determined that the subquery statement contains aggregate operators that operate on the join columns, but does not contain extreme value operators that operate on the output of the aggregate operators, then it is determined that the inclusion relationship judgment condition is not met.
[0230] If it is determined that the subquery statement contains the specified filter operator, and the filter range of the specified filter operator does not meet the set filter conditions, then it is determined that the inclusion relationship judgment condition is not met.
[0231] If it is determined that the subquery does not contain the specified join operator, aggregation operator, or specified filter operator, then it is determined that the inclusion relationship condition is met.
[0232] If it is determined that the subquery statement contains aggregate operators and extreme value operators, but does not contain specified join operators and specified filter operators, then it is determined that the inclusion relationship judgment condition is met;
[0233] If the subquery statement contains aggregate operators, extreme value operators, and specified filter operators, but does not contain specified join operators, and meets the set filter conditions, then it is determined that the inclusion relationship judgment condition is met.
[0234] In one embodiment, the determination unit 303 is used to:
[0235] Determine the filtering ranges for the first and second data tables respectively based on the specified filtering operators;
[0236] If the filter ranges corresponding to the first and second data tables do not have an overlapping relationship, then it is determined that the set filter conditions are not met.
[0237] In one embodiment, the determination unit 303 is used to:
[0238] If it is determined that the first query statement does not contain the specified predicate operator, then the data push condition is met; otherwise, the data push condition is not met.
[0239] If the first query statement is determined to contain a specified predicate operator, and the associated data table of the specified predicate operator is the same as the data table containing the included join column, then the data push condition is met; otherwise, the data push condition is not met. The associated data table is the data table operated on by the specified predicate operator.
[0240] In one embodiment, the update unit 304 is used to:
[0241] Based on the inclusion relationship, the data table containing the included join column is used as the target data table;
[0242] Based on the restriction sub-statement in the first query statement, generate a target sub-statement for restricting data in the target data table;
[0243] Generate a conditional sub-statement to restrict the join columns of the target data table from being empty;
[0244] The first query statement, the target sub-statement, and the conditional sub-statement are combined to obtain the second query statement.
[0245] The data query method, apparatus, electronic device, and storage medium provided in this application embodiment obtain a first query statement to be queried. The first query statement is a statement used to perform an inner join on two data tables and then perform data restrictions based on a restriction sub-statement. Based on the first query statement, a first data table and a second data table are determined for the inner join operation, as well as a first join column in the first data table and a second join column in the second data table. Based on the first query statement, it is determined whether the first join column and the second join column meet the data compression condition. The data compression condition is determined based on whether there is an inclusion relationship between the value ranges of the first join column and the value ranges of the second join column. If it is determined that the data compression condition is met, the first query statement is updated to obtain a second query statement. The second query statement is used to perform data restrictions on the data tables before performing the inner join operation. Based on the second query statement, data is queried on the first and second data tables to obtain the data query result. In this way, when the data compression condition is met, the data tables can be filtered first, and then the inner join operation can be performed, thereby reducing the amount of data processing and improving data query performance.
[0246] This application provides an electronic device, including:
[0247] Processor; and
[0248] The memory stores computer instructions that cause the processor to execute the methods of any of the above-described embodiments.
[0249] This application provides a storage medium storing computer instructions for causing a computer to execute the methods of any of the above embodiments.
[0250] Figure 4 A schematic diagram of the structure of an electronic device 4000 is shown. (See also...) Figure 4 As shown, the electronic device 4000 includes a processor 4010 and a memory 4020, and optionally may also include a power supply 4030, a display unit 4040, and an input unit 4050.
[0251] The processor 4010 is the control center of the electronic device 4000. It connects various components through various interfaces and lines, and performs various functions of the electronic device 4000 by running or executing software programs and / or data stored in the memory 4020.
[0252] In this embodiment, when the processor 4010 calls the computer program stored in the memory 4020, it executes the steps in the above embodiments.
[0253] Optionally, the processor 4010 may include one or more processing units; preferably, the processor 4010 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 4010. In some embodiments, the processor and memory may be implemented on a single chip; in some embodiments, they may also be implemented separately on independent chips.
[0254] The memory 4020 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, various applications, etc.; the data storage area may store data created based on the use of the electronic device 4000, etc. In addition, the memory 4020 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device, etc.
[0255] Electronic device 4000 also includes a power supply 4030 (such as a battery) that supplies power to various components. The power supply can be logically connected to processor 4010 through a power management system, thereby enabling the management of charging, discharging, and power consumption.
[0256] The display unit 4040 can be used to display information input by the user or information provided to the user, as well as various menus of the electronic device 4000. In this embodiment, it is mainly used to display the display interfaces of various applications in the electronic device 4000, as well as text, images, and other objects displayed on the display interfaces. The display unit 4040 may include a display panel 4041. The display panel 4041 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0257] The input unit 4050 can be used to receive information such as numbers or characters input by the user. The input unit 4050 may include a touch panel 4051 and other input devices 4052. The touch panel 4051, also known as a touch screen, can collect touch operations on or near the user (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 4051).
[0258] Specifically, the touch panel 4051 can detect user touch operations and the signals generated by these operations, convert them into touch point coordinates, send them to the processor 4010, and receive and execute commands from the processor 4010. Furthermore, the touch panel 4051 can be implemented using various types of touch technologies, including resistive, capacitive, infrared, and surface acoustic wave. Other input devices 4052 can include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.
[0259] Of course, the touch panel 4051 can cover the display panel 4041. When the touch panel 4051 detects a touch operation on or near it, it transmits the information to the processor 4010 to determine the type of touch event. Subsequently, the processor 4010 provides corresponding visual output on the display panel 4041 according to the type of touch event. Although in Figure 4 In this embodiment, the touch panel 4051 and the display panel 4041 are two separate components to realize the input and output functions of the electronic device 4000. However, in some embodiments, the touch panel 4051 and the display panel 4041 can be integrated to realize the input and output functions of the electronic device 4000.
[0260] The electronic device 4000 may also include one or more sensors, such as a pressure sensor, a gravity acceleration sensor, a proximity sensor, etc. Of course, depending on the specific application, the electronic device 4000 may also include other components such as a camera. Since these components are not the focus of this application embodiment, therefore... Figure 4It is not shown in the text and will not be described in detail here.
[0261] Those skilled in the art will understand that Figure 4 This is merely an example of an electronic device and does not constitute a limitation on the electronic device. It may include more or fewer components than shown, or a combination of certain components, or different components.
[0262] For ease of description, the above sections are divided into modules (or units) according to their functions and described separately. Of course, in implementing this application, the functions of each module (or unit) can be implemented in one or more software or hardware components.
[0263] Obviously, the above embodiments are merely examples for clear illustration and are not intended to limit the embodiments. Those skilled in the art can make other variations or modifications based on the above description. It is neither necessary nor possible to exhaustively list all embodiments here. However, obvious variations or modifications derived therefrom are still within the scope of protection of this application.
Claims
1. A method of data query, the method comprising: obtaining a first query statement to be queried; the first query statement being a statement for performing an inner join operation on two data tables and then performing data restriction based on a restriction sub-statement; determining, according to the first query statement, a first data table and a second data table for the inner join operation, and a first join column in the first data table and a second join column in the second data table for the inner join operation; determining, according to the first query statement, whether the first join column and the second join column satisfy a data pushdown condition; the data pushdown condition being determined according to whether there is an inclusion relationship between a value domain of the first join column and a value domain of the second join column; if it is determined that the data pushdown condition is satisfied, updating the first query statement to obtain a second query statement; the second query statement being used for performing data restriction on a data table and then performing an inner join operation; performing data query on the first data table and the second data table according to the second query statement to obtain a data query result; wherein updating the first query statement to obtain a second query statement comprises: according to the inclusion relationship, taking a data table in which a contained join column is located as a target data table; generating a target sub-statement for performing data filtering on the target data table based on a restriction sub-statement in the first query statement; generating a condition sub-statement for restricting the join column of the target data table to be non-empty; and combining the first query statement, the target sub-statement, and the condition sub-statement to obtain the second query statement.
2. The method of claim 1, wherein determining, according to the first query statement, whether the first join column and the second join column satisfy a data pushdown condition comprises: determining, according to the first query statement, whether an inclusion relationship determination condition is satisfied; the inclusion relationship determination condition being determined according to a construction manner of a data table; if it is determined that the inclusion relationship determination condition is satisfied and there is a foreign key constraint relationship between the first join column and the second join column or the inner join operation is a self-join operation, it is determined that the inclusion relationship exists; and determining, according to a specified predicate operator included in the first query statement other than an inner join sub-statement, whether the data pushdown condition is satisfied; the inner join sub-statement being a sub-statement in the first query statement for the inner join operation.
3. The method of claim 2, wherein determining, according to the first query statement, whether an inclusion relationship determination condition is satisfied comprises: if it is determined, according to the first query statement, that the first data table and the second data table are both base tables, it is determined that the inclusion relationship determination condition is satisfied; and if it is determined, according to the first query statement, that there is a derived table in the first data table and the second data table, determining, according to a sub-query statement corresponding to the derived table, whether the inclusion relationship determination condition is satisfied; the derived table being a virtual table constructed based on a sub-query statement in the first query statement. 4. The method of claim 3, wherein determining whether the inclusion relationship judgment condition is met according to the corresponding subquery statement of the derived table comprises: determining that the inclusion relationship judgment condition is not met if the subquery statement contains a specified join operator; determining that the inclusion relationship judgment condition is not met if the subquery statement contains an aggregation operator for a join column operation and does not contain an extreme value operator for an output operation of the aggregation operator; determining that the inclusion relationship judgment condition is not met if the subquery statement contains a specified filter operator and a filter range of the specified filter operator does not meet a set filter condition; determining that the inclusion relationship judgment condition is met if the subquery statement does not contain the specified join operator, the aggregation operator, and the specified filter operator; determining that the inclusion relationship judgment condition is met if the subquery statement contains the aggregation operator and the extreme value operator and does not contain the specified join operator and the specified filter operator; and determining that the inclusion relationship judgment condition is met if the subquery statement contains the aggregation operator, the extreme value operator, and the specified filter operator, does not contain the specified join operator, and meets the set filter condition.
5. The method of claim 4, wherein determining that the inclusion relationship judgment condition is not met if the subquery statement contains a specified filter operator and a filter range of the specified filter operator does not meet a set filter condition comprises: determining filter ranges of the first data table and the second data table according to the specified filter operator; and determining that the set filter condition is not met if there is no covering relationship between the filter ranges of the first data table and the second data table.
6. The method of any one of claims 2-5, wherein determining whether the data pushdown condition is met according to a specified predicate operator contained in the first query statement except for the inner join sub-statement comprises: determining that the data pushdown condition is met if the first query statement does not contain the specified predicate operator, and otherwise determining that the data pushdown condition is not met; and determining that the data pushdown condition is met if the first query statement contains the specified predicate operator and an associated data table of the specified predicate operator is consistent with a data table in which a join column is contained, and otherwise determining that the data pushdown condition is not met; the associated data table being a data table on which the specified predicate operator operates.
7. An apparatus for data query, the apparatus comprising: an acquisition unit configured to acquire a first query statement to be queried; the first query statement being a statement for performing an inner join operation on two data tables and then performing data limitation based on a restriction sub-statement; and a determination unit configured to determine, according to the first query statement, a first data table and a second data table for the inner join operation, and a first join column in the first data table and a second join column in the second data table for the inner join operation. A judging unit is configured to judge whether the first connection column and the second connection column meet a data pushdown condition according to the first query statement. The data pushdown condition is determined according to whether there is a containing relationship between a value range of the first connection column and a value range of the second connection column. An updating unit is configured to update the first query statement to obtain a second query statement if it is determined that the data pushdown condition is met. The second query statement is used to perform an inner join operation after data restriction on a data table. A querying unit is configured to perform data query on the first data table and the second data table according to the second query statement to obtain a data query result. The updating unit is specifically configured to: according to the containing relationship, take a data table in which a connection column that is contained is located as a target data table; and based on a restriction sub-statement in the first query statement, generate a target sub-statement used to perform data screening on the target data table. A condition sub-statement used to restrict the connection column of the target data table to be non-empty is generated; and the first query statement, the target sub-statement and the condition sub-statement are combined to obtain the second query statement.
8. An electronic device, comprising: a processor; and a memory storing computer instructions for causing the processor to perform the method according to any one of claims 1-6.
9. A storage medium storing computer instructions for causing a computer to perform the method according to any one of claims 1-6.
Citation Information
Patent Citations
Optimizing relational database queries with multi-table predicate expressions
US20150324383A1