Database connection operation execution method, storage medium and computer device

By using the execution result of the smaller table as a constant parameter to replace the join condition, the database join algorithm is optimized, solving the inefficiency problem caused by complex subqueries and achieving more efficient database join operations.

CN115455057BActive Publication Date: 2025-11-28CETC JINCANG (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211152695.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-21
Publication Date
2025-11-28
Estimated Expiration
2042-09-21

AI Technical Summary

Technical Problem

Existing database join algorithms are inefficient in complex subquery scenarios, leading to a decrease in overall execution efficiency, especially when multiple tables are joined, which is greatly affected by complex subqueries.

Method used

By using the execution result of the smaller table as a constant parameter to replace the join condition, and passing the join condition as a filter condition into the complex subquery, the join algorithm is optimized to reduce the complexity of the complex subquery and improve execution efficiency.

Benefits of technology

By reducing the number of records involved in the calculations in complex queries, the execution efficiency of database join operations is significantly improved, and the execution time of SQL queries is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115455057B_ABST
    Figure CN115455057B_ABST
Patent Text Reader

Abstract

The application provides a database connection operation execution method, a storage medium and a computer device. The method comprises the following steps: determining that an executor of a database starts to execute a preselected actual execution plan, the actual execution plan is used to define a connection order and a connection mode of a connection operation, two sides of the connection operation comprise a first subtable and a second subtable, and the second subtable comprises a subquery; scanning data of the first subtable, obtaining data returned by scanning, and obtaining a first result set; saving values in columns related to the connection operation in the first subtable as a supplementary filtering condition; filtering a data table participating in a subquery of the second subtable by using the supplementary filtering condition, and obtaining a second result set by using filtered data to perform the subquery; and connecting the first result set and the second result set to obtain a connection result. According to the scheme, the complexity of the subquery is reduced, and the execution time of the connection operation is saved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to database technology, in particular to a database connection operation execution method, a storage medium and a computer device. BACKGROUND

[0002] The connection query is the most important query in the relational database. The connection is the main feature of the relational database model, and is also a symbol distinguishing from other types of database systems.

[0003] The database generally adopts the cost-based method to select the connection order and the connection mode for the connection of multiple tables. The accuracy of this cost-based selection mode depends on the sampling of data and the algorithm of cost calculation. The connection algorithms commonly used in existing database products include loop nesting, hash connection and merge sorting connection, etc. In order to improve the efficiency of connection, there are also bitmap filters and other technologies in the database executor to assist the execution of these connection algorithms.

[0004] However, the above connection methods have limited optimization effect for some specific use scenarios. For example, a complex subquery is a very time-consuming operation, and the total SQL execution time is greatly affected by the complex subquery Q. If the connection operation involves a complex subquery, the connection query execution time is greatly affected by the complex subquery Q, and the execution plan selected by the existing connection algorithm is generally low in efficiency, resulting in a decline in overall execution efficiency. SUMMARY

[0005] An object of the present application is to at least solve the technical problems of any of the above aspects of the database connection operation execution method, the storage medium and the computer device.

[0006] A further object of the present application is to improve the efficiency for the scene of the connection operation.

[0007] Another further object of the present application is to avoid the influence of the subquery on the processing of the execution plan.

[0008] In particular, the present application provides a database connection operation execution method, which comprises:

[0009] determining that an executor of the database starts to execute a pre-selected actual execution plan, the actual execution plan being used to define a connection order and a connection mode of the connection operation, wherein two side sub-tables of the connection operation comprise a first sub-table and a second sub-table, and an estimated return row number of the first sub-table is less than a preset cardinality estimation threshold value, and the second sub-table contains a subquery;

[0010] scanning data of the first sub-table to obtain scanned return data, and obtaining a first result set;

[0011] save the value in the column related to the join operation in the first sub-table as a supplementary filter condition;

[0012] filter the data table involved in the sub-query of the second sub-table using the supplementary filter condition, and perform the sub-query using the filtered data to obtain a second result set;

[0013] join the first result set and the second result set to obtain a join result.

[0014] Optionally, the step of determining the executor of the database to start executing the pre-selected actual execution plan comprises:

[0015] obtaining an execution identifier of the actual execution plan; when the execution identifier is in a start state, determining the executor to start executing the actual execution plan.

[0016] Optionally, when the execution identifier is in a proceeding state, the step of filtering the data table involved in the sub-query of the second sub-table using the supplementary filter condition is directly performed.

[0017] Optionally, the step of scanning the data of the first sub-table comprises:

[0018] sequentially scanning each piece of data of the first sub-table according to the query condition of the first sub-table itself; and

[0019] after obtaining the first result set, the first result set is cached.

[0020] Optionally, after the step of caching the first result set, the method further comprises:

[0021] modifying the execution identifier of the actual execution plan to a proceeding state.

[0022] Optionally, the step of filtering the data table involved in the sub-query of the second sub-table using the supplementary filter condition comprises:

[0023] reading the records of the data table involved in the sub-query of the second sub-table one by one;

[0024] judging whether the read record involves a column related to the join operation;

[0025] if yes, replacing the filter condition of the column with the supplementary filter condition and performing the filtering.

[0026] Optionally, before the step of determining the executor of the database to start executing the pre-selected actual execution plan, the method further comprises:

[0027] starting the optimization of the join operation by a database optimizer;

[0028] judging whether the two sub-tables involved in the join operation satisfy a pre-set optimization condition;

[0029] If yes, create the actual execution plan.

[0030] Optionally, the method further comprises, after the step of creating the actual execution plan:

[0031] The optimizer calculates the join cost of each candidate in the candidate queue including the actual execution plan, and selects the actual execution plan if the join cost of the actual execution plan is the minimum.

[0032] According to another aspect of the present application, there is also provided a machine readable storage medium having stored thereon a machine executable program which, when executed by a processor, implements any of the above methods for performing a database join operation.

[0033] According to still another aspect of the present application, there is also provided a computer device comprising a memory, a processor, and a machine executable program stored on the memory and running on the processor, and the processor implements any of the above methods for performing a database join operation when executing the machine executable program.

[0034] The method for performing a database join operation according to the present application, for a join operation between a first sub-table with an estimated return row number less than a preset cardinality estimation threshold and a second sub-table containing a sub-query, replaces the join condition of the two tables with the return result of the first sub-table as a constant parameter, and passes the join condition as a filter condition into the sub-query to reduce the complexity of the sub-query, thereby reducing the number of records participating in the operation in the complex query and improving the execution efficiency of the join operation.

[0035] Further, the method for performing a database join operation according to the present application, with the optimization condition being that the estimated return row number of the first sub-table is less than the preset cardinality estimation threshold, and the second sub-table contains a sub-query and the estimated execution cost is greater than a preset execution cost threshold, identifies a specific scenario of the database join operation, and improves the efficiency accordingly, thereby achieving the optimization of the database.

[0036] The above and other objects, advantages and features of the present application will become more apparent from the following detailed description of some embodiments thereof, when taken in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS

[0037] Some embodiments of the present application will now be described in detail with reference to the drawings, which are provided by way of example and are not intended to limit the present application. Like reference numerals refer to like elements throughout the drawings. It should be understood that the drawings are not necessarily to scale. In the drawings:

[0038] Figure 1 is a schematic diagram of a method for performing a database join operation according to an embodiment of the present application;

[0039] Figure 2 is an execution plan data structure diagram generated by an execution method of a database join operation according to an embodiment of the present application;

[0040] Figure 3 is a schematic diagram of an execution process in an execution method of a database join operation according to an embodiment of the present application;

[0041] Figure 4 is a flowchart of sub-table optimization in an execution method of a database join operation according to an embodiment of the present application;

[0042] Figure 5 is a workflow diagram of an optimizer in an execution method of a database join operation according to an embodiment of the present application;

[0043] Figure 6 is a schematic diagram of a machine-readable storage medium according to an embodiment of the present application; and

[0044] Figure 7 is a schematic diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION

[0045] For multi-table connection, the optimizer of a database selects different connection algorithms according to different use scenarios. The method of the present embodiment is directed to a use scenario of connection of a small table T and a complex subquery Q, where the small table is a data table with very small data volume, which can refer to a node with very small data volume after filtering, for example, a data table with very small volume, and for example, a result of a subquery or connection of multiple tables. The complex subquery is a very time-consuming operation, and the total SQL connection operation execution time is greatly affected by the complex subquery Q.

[0046] The implementation principle of the present embodiment is to create an alternative execution plan, which replaces the connection condition of two tables with the execution result of the small table as a constant parameter, and transmits the connection condition as a filtering condition into the complex subquery to reduce the complexity of the complex subquery and improve the execution time of the subquery.

[0047] An SQL (Structured Query Language) statement is taken as an example for introduction: select * from a where exists (select * (select * from b union select * from c) v where v.id = a.id.

[0048] For a specific test database, there are only 8 rows of v.id=a.id result scanned from table A, while there are 2 million rows scanned from table B and C, and most of the time of SQL execution is spent on the HashAggregate operation of the 2 million data APPEND. If a.id in the connection condition v.id=a.id is first queried, and then converted into the id column values in the 8 rows of data, and then the id column values in the 8 rows of data are transmitted to the subquery and finally pushed down to b.id in (8 id values in a), c.id in (8 id values in a), the number of records scanned from table B and C will be very small.

[0049] In fact, the result returned by finally satisfying the query of select * from B where id in (select * from A) union select * from C where id in (select * from A) is only one row.

[0050] The execution method of the database connection operation of the embodiment is used for optimization of the connection algorithm at the database optimizer level. When an execution plan is generated for a SQL query statement of two-table connection, a new connection algorithm is generated.

[0051] Figure 1 is a schematic diagram of the execution method of the database connection operation according to an embodiment of the present application, wherein

[0052] The execution method of the database connection operation can generally include:

[0053] In step S102, it is determined that the executor of the database starts to execute a pre-selected actual execution plan, and the actual execution plan is used to define the connection order and the connection mode of the connection operation, wherein the two-side sub-tables of the connection operation include a first sub-table and a second sub-table, and the estimated return row number of the first sub-table is less than a preset cardinality estimation threshold value, and the second sub-table contains a subquery. That is, the two-side sub-tables participating in the connection operation can be recorded as the first sub-table (small table T) and the second sub-table (complex subquery Q), and the preset optimization condition can include that the estimated return row number of the first sub-table is less than the preset cardinality estimation threshold value, and the second sub-table contains a subquery and the estimated execution cost is greater than a preset execution cost threshold value.

[0054] In step S104, the data of the first sub-table is scanned, the scanned returned data is obtained, and a first result set is obtained;

[0055] In step S106, the values in the columns related to the connection operation in the first sub-table are saved as a supplementary filtering condition.

[0056] Step S108, filter the data table participating in the subquery of the second subtable using the supplementary filter condition, and perform the subquery using the filtered data to obtain a second result set;

[0057] Step S110, join the first result set and the second result set to obtain a connection result.

[0058] The above method is aimed at the connection operation of the first subtable with an estimated return row number less than a preset base estimation threshold and the second subtable containing a subquery, replaces the connection condition of the two tables with the return result of the first subtable as a constant parameter, and transmits the connection condition as a filter condition into the subquery to reduce the complexity of the subquery, thereby reducing the number of records participating in the operation in the complex query and improving the execution efficiency of the connection operation.

[0059] In the step of determining that the executor of the database starts to execute the pre-selected actual execution plan, the execution identifier (start) of the actual execution plan can be acquired first; when the execution identifier is in the start state (start=true), it is determined that the executor starts to execute the actual execution plan. The execution state is indicated by the setting of the execution identifier start. In the case where the execution identifier is in the proceeding state (start=false), the step of filtering the data table participating in the subquery of the second subtable using the supplementary filter condition can be directly executed, that is, in the case where the first subtable has been scanned, step S108 is directly executed.

[0060] The step S104 of scanning the data of the first subtable can include: sequentially scanning each piece of data of the first subtable according to the query condition of the first subtable itself; and after obtaining the first result set, the first result set is cached. After the step of caching the first result set, the execution identifier of the actual execution plan is modified to the proceeding state, that is, start=false is set.

[0061] The step S108 of filtering the data table participating in the subquery of the second subtable using the supplementary filter condition can include: reading the records of the data table participating in the subquery of the second subtable one by one; judging whether the read record involves a column related to the connection operation; if yes, the filter condition of the column is replaced with the supplementary filter condition, and filtering is performed.

[0062] Figure 2is an execution plan data structure diagram generated according to an execution method of a database join operation of one embodiment of the present application. Still taking select*from a where exists(select*(select*from b union select*from c)v where v.id=a.id as an example, the main variables used are identified. The join plan has left and right child nodes, the left node is the execution plan of the subquery v, and the right node is the execution plan of the small table A (it is assumed to be a full table scan SeqScan here). The execution plan of the subquery v is an APPEND operation, and the child node thereof is a scan of the tables B and C. The join condition is pushed down to the filter conditions of the tables B and C, and the join condition is added to the execution plans of the tables B and C.

[0063] Figure 3 is a flowchart of an execution process in an execution method of a database join operation according to one embodiment of the present application, Figure 4 is a flowchart of a subtable optimization process in an execution method of a database join operation according to one embodiment of the present application. The execution process of the executor includes:

[0064] Step S402, the executor starts to execute the execution plan.

[0065] Step S404, it is determined whether it is the first execution. The determination can be made by judging the execution identifier start of the FilterJoin. If start=true, that is, the execution identifier indicates the start state, it is determined that the executor starts to execute the actual execution plan.

[0066] Step S406, if it is the first execution, each record of the small table A is scanned in turn, and the filter condition is executed. The obtained result is cached; that is, the executor first executes the scan execution plan filterjoin->righttree of the small table A in a loop. Each execution returns one record. For each record, the returned record is first stored in the list X.

[0067] Step S408, the values of the small table A and the related columns in the join condition are saved in the list in the memory; for example, according to the join condition A.id=v.id, the ID column number in the execution plan filterjoin->innercols is saved. The value of the ID column of the record is pushed down to the lower layer of the subplan filterjoin->lefttree in the form of "id=value", and is used in the scan operation of the tables B and C. The loop is executed until all records in A are returned, and then start=false is set, that is, the execution identifier is modified to the execution state. The execution state is indicated by the setting of the execution identifier start.

[0068] Step S410, execute the execution plan of the subquery B to obtain filtered records;

[0069] Step S420, connect the records obtained by the subquery B with each data of the cached table A according to the connection condition, and return the connection result if the connection completion condition is met.

[0070] The execution process of step S410 can include: Figure 4

[0071] Step S412, start executing the execution plan of the subquery V;

[0072] Step S414, read records of the data table participating in the subquery of the second subtable one by one;

[0073] Step S416, filter the read records, if the column of the data table involves the connection condition, replace the column name of table A in the connection condition with the value of the column in A in the cache, and judge whether the read records meet the condition, if not, read the next record of the table to continue judging;

[0074] Step S418, after the read records of each data table meet the connection condition, use the records to perform other operations of the subquery. The execution plan is an Append (merge) merge, and the execution process is to first read the records of table B, then read the records of table C, and finally merge the two. Other operations can still follow the original logic.

[0075] When reading each record of table B or table C, in addition to the original filter condition, a plurality of filter conditions added in the first step are added. These filter conditions will reduce the number of records returned by scanning table B and C, thereby further reducing the number of records participating in the Append operation.

[0076] That is, the above execution process can be: scanning the data of the first subtable, obtaining the scanned data, obtaining the first result set (that is, the set of records returned by scanning the small table A); saving the values in the columns related to the connection operation in the first subtable as supplementary filter conditions; filtering the data tables participating in the subquery of the second subtable using the supplementary filter conditions, and performing the subquery using the filtered data (that is, the records after replacing the column name of table A in the connection condition with the value of the column in A in the cache and judging); connecting the first result set and the second result set to obtain the connection result.

[0077] ​When the connection is executed, firstly, the query of the small table is executed, the query result is cached, then the connection condition is converted into the query condition of the large table, the large table is filtered, finally, the query result of the large table and the cached query result of the small table are connected, so that the number of records participating in the operation in the complex query can be reduced, and the execution efficiency of the SQL is greatly improved, and the execution time of the SQL query is reduced.

[0078] Before the step of starting the execution of the pre-selected actual execution plan by the executor, the optimization of the connection operation can also be started by the database optimizer, and the provided connection algorithm of the embodiment is added to the candidate queue for selection.

[0079] That is, before the step of determining that the executor of the database starts the execution of the pre-selected actual execution plan, the optimization of the connection operation is also started by the database optimizer, it is judged whether the two side sub-tables participating in the connection operation meet the preset optimization condition, and if so, the actual execution plan is created. After the step of creating the actual execution plan, the optimizer can also calculate the connection cost of the candidate queue including the actual execution plan respectively, and if the connection cost of the actual execution plan is the minimum, the actual execution plan is selected.

[0080] Figure 5 It is the work flow diagram of the optimizer in the execution method of the database connection operation according to an embodiment of the application. Taking that the database executes the connection A join B as an example, the physical optimization module of the optimizer will firstly perform the cardinality estimation and cost estimation for the two sub-tables (table A and table B) participating in the connection, enumerate the supported connection algorithms (including the loop nest algorithm, the hash connection, the sorting merge connection and the like) based on the estimated data, and calculate the execution cost of each connection algorithm, and finally select the algorithm with the optimal cost. One of the main improvements of the embodiment is that when the optimizer enumerates the algorithms of the connection, if the two tables participating in the connection meet the following conditions, the improved connection algorithm provided in the embodiment is added when the connection algorithm is enumerated. The optimization of the database can be performed in the following steps:

[0081] In step S502, the optimizer is entered, and the optimization of the connection operation is started.

[0082] In step S504, it is judged whether the two side sub-tables participating in the connection operation meet the preset optimization condition; the optimization condition requires that the estimated return row number of the sub-table A is less than the cardinality estimation threshold row_threshold, and the sub-table B is a sub-query, and the estimated execution cost is greater than the execution cost threshold cost_threshold.

[0083] In the case that the base estimate threshold row_threshold is set to 10 and the execution cost threshold cost_threshold is set to 1, if the following conditions are met: for table A, the estimated row number row = 8 < row_threshold; and for the subquery, the estimated cost cost = 7 > cost_threshold; then it is considered that the above optimization condition is met.

[0084] In step S506, a join plan (named FilterJoinPath) is created and its execution cost is calculated. The execution cost includes the sum of the following parts:

[0085] (1) The cost of scanning table A

[0086] (2) The cost of materializing the returned data of table A and establishing a cache. The cost of this step is additional compared to the existing join algorithm. The cost of this step can be recorded as cost X.

[0087] (3) The returned data in A is pushed down to the subquery B as a filter condition, and then the execution cost of B is calculated. Because of the introduction of the additional filter condition, most of the records in the simple table scan in B are filtered out, resulting in improved query efficiency of B and saved execution cost Y. When Y is greater than X, the method of the present embodiment will greatly improve the execution efficiency of the SQL join operation, and the execution efficiency gradually improves with the degree to which Y is greater than X.

[0088] (4) The execution cost of performing a loop-nested join with the returned data of B as an outer table and the cached data of A as an inner table.

[0089] In step S508, FilterJoinPath is added to the candidate queue, and the execution costs of other plans are compared to select the execution plan with the minimum cost. The pseudo code of this step is as follows:

[0090] add_path(joinrel, create_nestloop_path(a, b)); / add the execution plan of the loop-nested algorithm

[0091] add_path(joinrel, create_hashjoin_path(a, b)); / add the execution plan of the hash join algorithm

[0092] add_path(joinrel, create_mergejoin_path(a, b)); / add the execution plan of the sorted merge join algorithm

[0093] add_path(joinrel, create_filterjoin_path(a, b)); / add the join algorithm provided by this embodiment

[0094] set_cheapest(joinrel); / select the optimal algorithm from the above 4 join algorithms as the final execution plan.

[0095] Step S510, enter the executor.

[0096] When the optimizer selects the candidate queue provided by this embodiment as the final join algorithm according to the cost, a final execution plan data structure is generated.

[0097] This embodiment also provides a machine-readable storage medium and a computer device. Figure 6 is a schematic diagram of a machine-readable storage medium 60 according to an embodiment of the present application, Figure 7 is a schematic diagram of a computer device 70 according to an embodiment of the present application.

[0098] The machine-readable storage medium 60 has a machine-executable program 61 stored thereon, and the machine-executable program 61, when executed by a processor, implements the execution method of the database connection operation of any of the above embodiments.

[0099] The computer device 70 can include a memory 720, a processor 710, and a machine-executable program 61 stored on the memory 720 and running on the processor 710, and the processor 710, when executing the machine-executable program 61, implements the execution method of the database connection operation of any of the above embodiments.

[0100] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a list of executable instructions for implementing logic functions, which can be specifically implemented in any machine-readable storage medium for use by an instruction execution system, device or apparatus, such as a computer-based system, a system including a processor, or other system that can fetch and execute instructions from the instruction execution system, device or apparatus, or in conjunction with these instructions execution system, device or apparatus.

[0101] For the description of the present embodiment, the machine-readable storage medium 60 can be any means for storing, communicating, propagating or transporting a program for use by or in connection with an instruction execution system, apparatus or device. More specific examples (a non-exhaustive list) of the computer-readable medium include the following: an electrical connection having one or more wires (electrical apparatus), a portable computer diskette (magnetic apparatus), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, and a portable compact disc read-only memory (CDROM). In addition, the computer-readable medium 40 can even be paper or another suitable medium upon which the program is printed, since the program can be electronically captured, for example by optically scanning the paper or other suitable medium, then electronically converted into a form which is suitable for use by the computer system, and then stored in computer memory.

[0102] It should be understood that parts of the application can be implemented in hardware, software, firmware or combinations thereof. In the above embodiments, several steps or methods can be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system.

[0103] The computer device 70 can be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smartphone. In some examples, the computer device 70 can be a cloud computing node. The computer device 70 can be described in the general context of computer system-executable instructions, such as program modules, being executed by a computer system. Generally, program modules can include routines, programs, objects, components, logic, data structures, and the like, that perform particular tasks or implement particular abstract data types. The computer device 70 can be implemented in a distributed cloud computing environment where tasks are performed by remote processing devices that are linked through a communications network. In a distributed cloud computing environment, program modules can be located in local or remote computer system storage media including memory storage devices.

[0104] The computer device 70 can include a processor 710 suitable for executing stored instructions, a memory 720 that provides temporary storage for the operations of the instructions during operation. The processor 710 can be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 720 can include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.

[0105] The processor 710 can be connected through the system interconnect (e.g., PCI, PCI-Express, etc.) to an I / O interface (input / output interface) adapted to connect the computer device 70 to one or more I / O devices (input / output devices). The I / O devices can include, for example, a keyboard and a pointing device, where the pointing device can include a touchpad or a touchscreen, etc. The I / O devices can be built-in components of the computer device 70, or can be devices externally connected to the computer device.

[0106] The processor 710 can also be linked through the system interconnect to a display interface adapted to connect the computer device 70 to a display device. The display device can include a display screen that is a built-in component of the computer device 70. The display device can also include a computer monitor, a television, or a projector, etc. that is externally connected to the computer device 70. In addition, a network interface controller (NIC) can be adapted to connect the computer device 70 to a network through the system interconnect. In some embodiments, the NIC can use any suitable interface or protocol (such as Internet Small Computer System Interface, etc.) to transfer data. The network can be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN), or the Internet, etc. Remote devices can be connected to the computer device through the network.

[0107] The flowcharts provided in this embodiment are not intended to indicate that the operations of the methods should be executed in any particular order, or that all of the operations of the methods should be included in every implementation. In addition, the methods can include additional operations. Additional changes can be made to the above-described methods within the scope of the technical ideas provided by the methods of this embodiment.

[0108] At this point, those skilled in the art will recognize that the present application has been described herein with reference to a number of illustrative embodiments and implementations, and that the generic principles and features can be employed to impart the spirit of the application, and with the scope of the application being accorded the broadest scope of which it is entitled to under the law.

Claims

1. A method for performing a database connection operation, comprising: The executor of the database is determined to start executing a pre-selected actual execution plan. The actual execution plan is used to define the connection order and connection method of the join operation. The two sub-tables of the join operation include a first sub-table and a second sub-table. The estimated number of rows returned by the first sub-table is less than a preset cardinality estimation threshold. The second sub-table contains a subquery. Scan the data in the first sub-table, retrieve the data returned by the scan, and obtain the first result set; Save the values ​​in the columns related to the join operation in the first sub-table as supplementary filtering conditions; The data tables participating in the subquery of the second sub-table are filtered using the supplementary filtering conditions, and the subquery is performed using the filtered data to obtain the second result set; The first result set and the second result set are concatenated to obtain the concatenation result.

2. The method for executing a database connection operation according to claim 1, wherein the step of determining that the executor of the database begins to execute a pre-selected actual execution plan includes: Obtain the execution identifier of the actual execution plan; When the execution flag is in the start state, it is determined that the executor begins to execute the actual execution plan.

3. The method for executing a database connection operation according to claim 2, wherein... If the execution flag is in progress, then the step of filtering the data table participating in the subquery of the second sub-table using the supplementary filtering conditions is executed directly.

4. The method for executing a database connection operation according to claim 1, wherein the step of scanning the data of the first sub-table includes: Based on the query conditions of the first sub-table itself, each piece of data in the first sub-table is scanned sequentially; and After obtaining the first result set, the first result set is cached.

5. The method for executing a database connection operation according to claim 4, wherein, The step of caching the first result set also includes: Modify the execution flag of the actual execution plan to the "in progress" status.

6. The method for executing a database connection operation according to claim 1, wherein, The step of filtering the data table participating in the subquery of the second sub-table using the supplementary filtering conditions includes: Read records one by one from the data table involved in the subquery of the second sub-table; Determine whether the read record involves columns related to the join operation; If so, replace the filter condition of the column with the supplementary filter condition and perform filtering.

7. The method for executing a database connection operation according to claim 6, wherein, The step prior to determining that the executor of the database will begin executing the pre-selected actual execution plan includes: The database optimizer initiates optimizations for connection operations; Determine whether the two sub-tables involved in the connection operation meet the preset optimization conditions; If so, create the actual execution plan.

8. The method for executing a database connection operation according to claim 7, wherein, Following the step of creating the actual execution plan, the following is also included: The optimizer calculates the connection cost for each candidate queue including the actual execution plan. If the actual execution plan has the lowest connection cost, then the actual execution plan is selected.

9. A machine-readable storage medium having a machine-executable program stored thereon, the machine-executable program, when executed by a processor, implementing the execution method of a database connection operation according to any one of claims 1 to 8.

10. A computer device comprising a memory, a processor, and a machine-executable program stored in the memory and running on the processor, wherein the processor, when executing the machine-executable program, implements a method for performing a database connection operation according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Data query processing method, device and system and computer readable storage medium

    CN111367954A

  • Execution method of database connection operation, storage medium and computer equipment

    CN115048409A