An opengauss nestloop connection execution method

By marking the Nestloop execution plan with the Inner Unique tag in the OpenGauss database, the slow execution speed of the Nestloop join operator is solved, and more efficient association queries are achieved.

CN116628026BActive Publication Date: 2025-10-17广州海量数据库技术有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310567030.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-19
Publication Date
2025-10-17
Estimated Expiration
2043-05-19

AI Technical Summary

Technical Problem

In the OpenGauss database, the Nestloop join operator executes slowly, causing associated queries to take a long time and becoming a performance bottleneck.

Method used

During the planning phase of the query SQL statement, determine whether the inner and outer table join conditions and unique index requirements are met, and mark the Nestloop execution plan that meets the conditions with the Inner Unique mark to reduce the number of loop executions.

Benefits of technology

By reducing the number of loop executions of the Nestloop execution plan, CPU resources are saved, execution performance is improved, judgment overhead is reduced, and query efficiency is significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116628026B_ABST
    Figure CN116628026B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of database, provide a kind of Nestloop connection execution method in opengauss, the method of the present application comprises: input query SQL statement, judge whether the input query SQL statement meets the requirement of scene application;Nestloop execution plan is generated according to the input query SQL statement, Inner Unique mark is stamped for the Nestloop execution plan generated for the query SQL statement meeting the requirement of scene application;The generated Nestloop execution plan is executed.The present application judges whether the Nestloop execution plan meets the requirement of application scene in the planner stage, Inner Unique mark is stamped for the Nestloop execution plan meeting the requirement of application scene, can significantly reduce the number of loop execution of Nestloop execution plan in execution stage, significantly save CPU resource, save execution time consumption, to improve the execution performance of Nestloop operator.By judging whether the query SQL statement and Nestloop execution plan meet the requirement of application scene, more accurate condition is realized, reduce the cost of judgment, reduce the occurrence of performance degradation.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database, and particularly relates to a Nestloop connection execution method in opengauss. BACKGROUND

[0002] Join is a common query execution method in the field of database, which is used for association query between two tables or multiple tables. In the opengauss database, the commonly used connection operators mainly include Nestloop, merge join and Hash Join. In the daily application of the database, the association query is used a lot, and the execution speed of the connection operator has an important influence on the overall performance of the database, especially the efficiency of the association query.

[0003] For example, Nestloop (nested loop) is the most basic connection execution operator, and the following describes a specific typical application scenario of Nestloop. When the query sql statement is Select*from table_a,table_bwhere table_a.key_a=table_b.key_b, the key_b on the table_b is established as a unique index / primary key index, the database generates an execution plan containing the Nestloop operator, which is referred to as Nestloop (test_a, test_b) hereinafter. The test_a is referred to as an outer table, and the test_b is referred to as an inner table. It is assumed that there are m records in the test_a and n records in the test_b. When the Nestloop operator is executed, each tuple a in the test_a needs to be obtained and scanned in the test_b. For each record b in the test_b, the connection condition test_a.key_a=table_b.key_b is used for judgment. If the connection condition is met, the tuple (a, b) at this time is returned, and the returned tuple (a, b) is added to the result set. The total execution times are m*n times. If m and n are large, the product will be large, which leads to a long query time. Due to the nested loop characteristics, the execution result is the Cartesian product of the inner and outer tables, which is easy to form a performance bottleneck and significantly increase the query time.

[0004] Therefore, how to improve the efficiency of the association query, especially the execution speed of the connection operator, has become a technical problem to be solved. SUMMARY

[0005] In view of this, in order to overcome the shortcomings of the prior art, the present application aims to provide a Nestloop connection execution method in opengauss.

[0006] The present application provides a Nestloop connection execution method in opengauss, comprising:

[0007] Step S1: input a query SQL statement, and determine whether the input query SQL statement meets the requirements of a scenario application;

[0008] Step S2: generating a Nestloop execution plan according to the input query SQL statement, and marking the Nestloop execution plan generated for the query SQL statement meeting the requirements of the scenario application with an Inner Unique label;

[0009] Step S3: executing the Nestloop execution plan generated in step S2.

[0010] Preferably, as the Nestloop connection execution method in the opengauss, in step S1, determining whether the input query SQL statement meets the requirements of a scenario application comprises:

[0011] determining whether the query SQL statement can generate a Nestloop execution plan;

[0012] determining whether the join condition in the query SQL statement meets the requirements of a scenario application;

[0013] determining whether the query SQL statement meets the Inner Unique condition.

[0014] Preferably, as the Nestloop connection execution method in the opengauss, in step S1, determining whether the query SQL statement can generate a Nestloop execution plan comprises:

[0015] determining, according to the semantics of the query SQL statement, whether there is a join relationship of two or more data tables in the query SQL statement, and determining that the query SQL can generate a Nestloop execution plan when there is a join relationship of two or more tables in the query SQL statement.

[0016] Preferably, as the Nestloop connection execution method in the opengauss, in step S1, determining whether the join condition in the query SQL statement meets the requirements of a scenario application comprises:

[0017] when the join condition of the query SQL statement is empty, determining that the join condition of the query SQL statement does not meet the requirements of a scenario application;

[0018] when the join condition of the query SQL statement is a non-equality judgment condition, determining that the join condition of the query SQL statement does not meet the requirements of a scenario application;

[0019] When the join condition of the query SQL statement does not contain the column of the inner table, the join condition of the query SQL statement is determined as not meeting the scenario application requirement.

[0020] Preferably, as the Nestloop connection execution method in the opengauss, in step S1, it is determined whether the query SQL statement meets the Inner Unique condition, comprising:

[0021] When the join condition of the query SQL statement is matched, for each outer table tuple in the outer table, at most one inner table tuple in the inner table can meet the join condition, and the query SQL statement is determined as meeting the Inner Unique condition.

[0022] Preferably, as the Nestloop connection execution method in the opengauss, in step S1, when the join condition of the query SQL statement is matched, for each outer table tuple in the outer table, at most one inner table tuple in the inner table can meet the join condition, and the query SQL statement is determined as meeting the Inner Unique condition, comprising:

[0023] When the inner table is a normal table, there is a column related to the inner table in the join condition, and a unique index or a primary key is established on the column related to the inner table, the query SQL statement is determined as meeting the Inner Unique condition.

[0024] When the inner table is a normal table, there are multiple columns related to the inner table in the join condition, and a unique index or a primary key is established on one or more columns related to the inner table, the query SQL statement is determined as meeting the Inner Unique condition.

[0025] When the inner table is a subquery, and the top-level result of the subquery is a grouping aggregation, and the grouping key is completely consistent with the column related to the inner table in the join condition, the query SQL statement is determined as meeting the Inner Unique.

[0026] Preferably, as the Nestloop connection execution method in the opengauss, in step S2, the Nestloop execution plan generated for the query SQL statement meeting the scenario application is marked with an Inner Unique label, comprising: adding a member named Inner Unique label in the data structure describing the Nestloop execution plan, and assigning the value of the Inner Unique label as true when the query SQL statement meets the scenario application requirement.

[0027] Preferably, as the Nestloop connection execution method in the opengauss, step S3 comprises:

[0028] Step S31: traversing the outer table and the inner table respectively to obtain an outer table tuple and an inner table tuple;

[0029] Step S32: judging whether the obtained inner table tuple and the obtained outer table tuple meet the connection condition;

[0030] Step S33: adding the outer table tuple and the inner table tuple meeting the connection condition to the result set, and judging whether there is an Inner Unique mark in the Nestloop execution plan.

[0031] Preferably, as the Nestloop connection execution method in opengauss of the present application, step S32 comprises: when the obtained inner table tuple and the obtained outer table tuple do not meet the connection condition, re-obtaining another inner table tuple in the inner table, judging whether the re-obtained another inner table tuple and the outer table tuple obtained in step S31 meet the connection condition.

[0032] Preferably, as the Nestloop connection execution method in opengauss of the present application, step S33 comprises:

[0033] When there is no Inner Unique mark in the Nestloop execution plan, re-obtaining another inner table tuple in the inner table, judging whether the re-obtained inner table tuple and the outer table tuple obtained in step S31 meet the connection condition, adding the outer table tuple and the inner table tuple meeting the connection condition to the result set, and judging whether there is an Inner Unique mark in the Nestloop execution plan;

[0034] When there is an Inner Unique mark in the Nestloop execution plan, traversing the outer table and the inner table respectively to re-obtain an outer table tuple and an inner table tuple, judging whether the re-obtained inner table tuple and the obtained outer table tuple meet the connection condition, adding the outer table tuple and the inner table tuple meeting the connection condition to the result set, and judging whether there is an Inner Unique mark in the Nestloop execution plan.

[0035] Finally, the present application further provides a computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned Nestloop connection execution method in opengauss when executing the program.

[0036] The Nestloop connection execution method in opengauss of the present application has the following beneficial effects:

[0037] 1. By judging whether the Nestloop execution plan meets the requirements of the application scenario in the planner stage, marking the Nestloop execution plan that meets the requirements of the application scenario with Inner Unique, the number of loop executions of the Nestloop execution plan can be significantly reduced in the execution stage, CPU resources can be significantly saved, execution time can be saved, and the execution performance of the Nestloop operator can be improved.

[0038] 2. By judging whether the query SQL statement and the Nestloop execution plan meet the requirements of the application scenario, a more accurate condition is realized, the judgment overhead is reduced, and the occurrence of performance degradation is reduced. BRIEF DESCRIPTION OF DRAWINGS

[0039] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.

[0040] Figure 1 A flowchart of a Nestloop connection execution method in an opengauss according to an exemplary embodiment of the present application.

[0041] Figure 2 A flowchart of step S3 of the Nestloop connection execution method in the opengauss according to an exemplary embodiment of the present application.

[0042] Figure 3 A specific scene example schematic diagram of a Nestloop connection execution method in the prior art.

[0043] Figure 4 A specific scene example schematic diagram of the Nestloop connection execution method in the opengauss according to an exemplary embodiment of the present application.

[0044] Figure 5 A structural schematic diagram of the device provided by the present application. DETAILED DESCRIPTION

[0045] The embodiments of the present application will be described in detail below with reference to the drawings.

[0046] It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict; and all other embodiments obtained by those skilled in the art on the basis of the embodiments in the present disclosure without creative labor are within the scope of protection of the present disclosure.

[0047] It is noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein can be embodied in a wide variety of forms and that any specific structure and / or function described herein is merely illustrative. Based on the teachings herein one skilled in the art should appreciate that an aspect described herein can be implemented independently of any other aspects and that an aspect described herein can be implemented both as any number of software and / or hardware structures and as any number of processes and / or operations. For example, an aspect can be implemented as a software routine running on a general purpose computer or workstation, a purpose-built computer or workstation, a software routine running on a mobile device, a software routine running on a remote computing device, a software routine running on a computing device in a distributed computing environment, a software routine running on a computing device in a cloud computing environment, a software routine running on a computing device in a virtual computing environment, a software routine running on a computing device in a virtual machine, a software routine running on a computing device in a virtual container, a software routine running on a computing device in a virtual network computing environment, a software routine running on a computing device in a virtual reality computing environment, a software routine running on a computing device in a virtual augmented reality computing environment, a software routine running on a computing device in a virtual mixed reality computing environment, a software routine running on a computing device in a virtual holographic reality computing environment, a software routine running on a computing device in a virtual artificial reality computing environment, a software routine running on a computing device in a virtual extended reality computing environment, a software routine running on a computing device in a virtual virtual reality computing environment, a software routine running on a computing device in a virtual virtual augmented reality computing environment, a software routine running on a computing device in a virtual virtual mixed reality computing environment, a software routine running on a computing device in a virtual virtual holographic reality computing environment, a software routine running on a computing device in a virtual virtual artificial reality computing environment, a software routine running on a computing device in a virtual virtual extended reality computing environment, a software routine running on a computing device in a virtual virtual virtual reality computing environment, a software routine running on a computing device in a virtual virtual virtual augmented reality computing environment, a software routine running on a computing device in a virtual virtual virtual mixed reality computing environment, a software routine running on a computing device in a virtual virtual virtual holographic reality computing environment, a software routine running on a computing device in a virtual virtual virtual artificial reality computing environment, a software routine running on a computing device in a virtual virtual virtual extended reality computing environment, a software routine running on a computing device in a virtual virtual virtual virtual reality computing environment, a software routine running on a computing device in a virtual virtual virtual virtual augmented reality computing environment, a software routine running on a computing device in a virtual virtual virtual virtual mixed reality computing environment, a software routine running on a computing device in a virtual virtual virtual virtual holographic reality computing environment, a software routine running on a computing device in a virtual virtual virtual virtual artificial reality computing environment, a software routine running on a computing device in a virtual virtual virtual virtual extended reality computing environment, and the like.

[0048] The technical principle of the present application is as follows:

[0049] The present application makes a judgment in the planning stage of the SQL statement, whether the executed SQL statement is the typical scene defined by the present application, if yes, mark Inner Unique in the Nestloop execution plan. In the execution stage, if it is found that the Nestloop execution plan has Inner Unique mark, after the outer table tuple is matched to the first inner table tuple of the inner table through the connection condition, for this outer table tuple, this loop can be terminated, because no other records in the inner table can be matched, so the total execution times can be reduced. The definition of the typical scene of the present application meets the following conditions:

[0050] a. Meet the Nestloop operator use scene;

[0051] b. The connection condition of Nestloop is an equal condition;

[0052] c. For the connection condition, the column involved can be derived that for each outer table tuple of the outer table, at most only one tuple in the inner table can meet the connection condition and match it.

[0053] The following terms involved in each embodiment are explained as follows:

[0054] opengauss: a relational database, providing extreme performance for multi-core architecture, full-link business, data security, AI-based tuning and efficient operation and maintenance capabilities.

[0055] Nestloop: a connection operator in the opengauss database, used for associated queries between tables.

[0056] Query SQL statement: a structured language for operating a database, according to which the data can be processed and the result set information can be returned to the client.

[0057] Figure 1 A flow chart of a Nestloop connection execution method in an opengauss according to an exemplary embodiment of the present application.

[0058] As shown in Figure 1 , the method of the present embodiment comprises:

[0059] Step S1 of the method of the present embodiment comprises: inputting a query SQL statement, and judging whether the input query SQL statement meets the requirements of the scenario application; specifically, in step S1, whether the input query SQL statement meets the requirements of the scenario application is judged in the following manner:

[0060] It is judged whether the query SQL statement can generate a Nestloop execution plan, and according to the semantics of the query SQL statement, it is judged whether there is a connection relationship of two or more data tables in the query SQL statement. When there is a connection relationship of two or more tables in the query SQL statement, it is determined that the query SQL can generate a Nestloop execution plan. In actual application, the Nestloop execution plan is the most basic one among the execution plans that can complete the connection relationship operation. In the method of the present embodiment, the database planner will generate a Nestloop execution plan as one of the optional execution plans by default.

[0061] It is judged whether the connection condition in the query SQL statement meets the requirements of the scenario application. When the connection condition of the query SQL statement is empty, the connection condition of the query SQL statement is determined to not meet the requirements of the scenario application. When the connection condition of the query SQL statement is a non-equality judgment condition, the connection condition of the query SQL statement is determined to not meet the requirements of the scenario application. When the connection condition of the query SQL statement does not contain the column of the inner table, the connection condition of the query SQL statement is determined to not meet the requirements of the scenario application.

[0062] It is judged whether the query SQL statement meets the Inner Unique condition. When the connection matching is performed according to the connection condition of the query SQL statement, for each outer table tuple in the outer table, there is at most one inner table tuple in the inner table that can meet the connection condition. The query SQL statement is determined to meet the Inner Unique condition, specifically:

[0063] When the inner table is a normal table, there is a column related to the inner table in the connection condition, and a unique index / primary key is established on the inner table, the query SQL statement is determined to meet the Inner Unique condition;

[0064] When the inner table is a normal table, there are multiple columns related to the inner table in the connection condition, and a unique index / primary key is established on one or more columns related to the inner table, the query SQL statement is determined to meet the Inner Unique condition.

[0065] When the inner table is a subquery, and the top-level result of the subquery is a grouped aggregation, and the grouping key is completely consistent with the column of the inner table involved in the connection condition, the query SQL statement is determined to meet the Inner Unique;

[0066] Step S2 of the embodiment method comprises: generating a Nestloop execution plan according to the input query SQL statement, marking the Nestloop execution plan generated for the query SQL statement meeting the scenario application with an Inner Unique label, in actual application, the database system needs to describe the Nestloop execution plan at the code level, and the data structure for describing the Nestloop generally includes data members such as the inner table, the outer table, the connection condition, the type of Join operation (such as Left join, Right join, Inner join), and the like, in the data structure for describing the Nestloop execution plan, the embodiment method adds a member named Inner Unique label, when the query SQL statement meets the scenario application requirement, the value of the Inner Unique label is assigned to true, and when the query SQL statement does not meet the scenario application requirement, the value of the Inner Unique label is assigned to false. When the value of the Inner Unique label is true, it indicates that the generated Nestloop execution plan meets the scenario application requirement defined by the method, and the Nestloop execution plan can be optimized in the execution stage of the database executor.

[0067] Step S3 of the embodiment method comprises: executing the Nestloop execution plan generated in step S2. Figure 2 As shown in the flowchart of step S3 of the embodiment method, Figure 2 Step S3 of the embodiment method is implemented in the following manner:

[0068] Step S31: respectively traverse the outer table and the inner table to obtain an outer table tuple and an inner table tuple; in actual application, if the outer table tuple cannot be obtained, the traversal of the outer table is ended, and the execution of the Nestloop execution plan is ended;

[0069] Step S32: determine whether the obtained inner table tuple and the obtained outer table tuple meet the connection condition, when the obtained inner table tuple and the obtained outer table tuple do not meet the connection condition, another inner table tuple in the inner table is re-obtained, and it is determined whether the obtained another inner table tuple and the outer table tuple obtained in step S31 meet the connection condition;

[0070] Step S33: add the outer table tuple and the inner table tuple meeting the connection condition to the result set, and determine whether there is an Inner Unique mark in the Nestloop execution plan; when there is no Inner Unique mark in the Nestloop execution plan, reacquire another inner table tuple in the inner table, determine whether the reacquired inner table tuple meets the connection condition with the outer table tuple acquired in step S31, add the outer table tuple and the inner table tuple meeting the connection condition to the result set, and determine whether there is an Inner Unique mark in the Nestloop execution plan; when there is an Inner Unique mark in the Nestloop execution plan, traverse the outer table and the inner table respectively, reacquire an outer table tuple and an inner table tuple, determine whether the reacquired inner table tuple meets the connection condition with the acquired outer table tuple, add the outer table tuple and the inner table tuple meeting the connection condition to the result set, and determine whether there is an Inner Unique mark in the Nestloop execution plan.

[0071] After finding the hit connection condition, it is originally needed to continue to traverse the inner table to determine whether there is still a combination of the inner table tuple and the outer table tuple meeting the hit connection condition. After optimization of the present application, if the Inner Unique mark is added to the Nestloop execution plan, it can be known that for each tuple in the outer table, at most only one inner table tuple meets the connection condition and matches it, so after finding the first tuple meeting the connection condition, the loop of the current tuple of the outer table can be ended, and the loop of the next tuple of the outer table is entered, so that the number of loops is greatly reduced.

[0072] The method of the present embodiment can judge whether the Nestloop execution plan meets the requirements of the application scenario in the planner stage, add the Inner Unique mark to the Nestloop execution plan meeting the requirements of the application scenario, significantly reduce the number of loop executions of the Nestloop execution plan in the execution stage, significantly save the CPU resources, save the execution time, and thus improve the execution performance of the Nestloop operator. By judging whether the query SQL statement and the Nestloop execution plan meet the requirements of the application scenario, a more accurate condition is realized, the judgment cost is reduced, and the performance degradation is reduced.

[0073] The method of the embodiment is used in a Nestloop (test_a, test_b), that is, a Nestloop execution plan, for an inner table test_b, the table has a unique index / primary key established on a column key_b, and a connection condition table_a.key_a = table_b.key_b contains all columns of the unique index / primary key. Assuming that there are m records in test_a and n records in test_b, the number of loop times of each tuple of the outer table test_a in the inner table test_b can be reduced (originally n times) according to this feature. On average, it can be reduced by half, that is, the total execution times can be reduced from m*n to m*1 / 2*n.

[0074] The following is described by using a specific scene as an example:

[0075] The data contained in the outer table and the inner table is as shown in Figure 3 The connection condition is: outer table.key = inner table.key. In the prior art, the total execution times are 3*5 = 15 times.

[0076] The schematic diagram of execution by using the method of the embodiment is as shown in Figure 4 The loop execution times are reduced to 6 times, which is more than 50% less than the method in the prior art.

[0077] As shown in Figure 5 The application further provides a device, including a processor 110, a communication interface 120, a memory 130 for storing a processor-executable computer program, and a communication bus 140. The processor 110, the communication interface 120, and the memory 130 complete communication with each other through the communication bus 140. The processor 110 realizes the Nestloop connection execution method in opengauss described above by running the executable computer program.

[0078] The computer program in the memory 130 can be implemented in the form of a software functional unit and sold or used as an independent product. Based on such understanding, the technical solutions of the application essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device) to execute all or part of the steps of the embodiments of the application. The foregoing storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0079] The system embodiments described above are only illustrative, wherein the units illustrated as separate components can or can not be physically separated, and the components illustrated as units can or can not be physical units, i.e., can be located in one place, or can be distributed to multiple network units. Part or all of the modules can be selected based on actual needs to achieve the purposes of the embodiments. Those skilled in the art can understand and implement without creative labor.

[0080] Through the description of the above embodiments, those skilled in the art can clearly understand that the embodiments can be realized by means of software plus necessary universal hardware platforms, and of course can also be realized by hardware. Based on such understanding, the above technical solutions can be embodied in the form of software products, and the computer software products can be stored in a computer readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and include a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods of the embodiments or some parts of the embodiments.

[0081] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, any skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A Nestloop connection execution method in opengauss, characterized in that: The method comprises: Step S1: Input a query SQL statement and determine whether the input query SQL statement meets the scenario application requirements; Step S2: Generate a Nestloop execution plan based on the input query SQL statement, and mark the Nestloop execution plan generated by the query SQL statement that meets the scenario application with an Inner Unique mark; Step S3: Execute the Nestloop execution plan generated in step S2; In step S1, it is determined whether the input query SQL statement meets the scenario application requirements, including: Determine whether the query SQL statement can generate a Nestloop execution plan; Determine whether the connection conditions in the query SQL statement meet the application requirements of the scenario; Determine whether the query SQL statement meets the Inner Unique condition; In step S1, determining whether the query SQL statement meets the Inner Unique condition includes: When performing join matching based on the join condition of the query SQL statement, for each outer table tuple in the outer table, at most one inner table tuple in the inner table can meet the join condition, and the query SQL statement is determined to meet the InnerUnique condition; In step S1, when performing join matching based on the join condition of the query SQL statement, for each outer table tuple in the outer table, at most one inner table tuple in the inner table can meet the join condition, and the query SQL statement is determined to meet the Inner Unique condition, including: When the inner table is a common table, the join condition involves a column of the inner table, and a unique index / primary key is established in the inner table, the query SQL statement is determined to meet the Inner Unique condition; When the inner table is a common table, the join condition involves multiple columns of the inner table, and a unique index / primary key is established on one or more columns of the inner table, the query SQL statement is determined to meet the Inner Unique condition; When the inner table is a subquery, and the top-level result of the subquery is a grouped aggregate, and the grouping key is exactly the same as the column involved in the inner table in the join condition, the query SQL statement is determined to be Inner Unique.

2. The Nestloop connection execution method in opengauss according to claim 1, characterized in that In step S1, it is determined whether the query SQL statement can generate a Nestloop execution plan, including: According to the semantics of the query SQL statement, it is determined whether there is a connection relationship between two or more data tables in the query SQL statement. When there is a connection relationship between two or more tables in the query SQL statement, it is determined that the query SQL can generate a Nestloop execution plan.

3. The Nestloop connection execution method in opengauss according to claim 2, characterized in that In step S1, it is determined whether the connection conditions in the query SQL statement meet the scenario application requirements, including: When the connection condition of the query SQL statement is empty, the connection condition of the query SQL statement is determined to be not in compliance with the scenario application requirements; When the connection condition of the query SQL statement is a non-equality judgment condition, the connection condition of the query SQL statement is determined to be not in compliance with the scenario application requirements; When the connection condition of the query SQL statement does not include the column of the inner table, the connection condition of the query SQL statement is determined to be not in compliance with the scenario application requirement.

4. The Nestloop connection execution method in opengauss according to claim 1, characterized in that In step S2, the Nestloop execution plan generated for the query SQL statement that meets the scenario application requirements is marked with an Inner Unique tag, including: adding a member named Inner Unique tag in the data structure describing the Nestloop execution plan, and when the query SQL statement meets the scenario application requirements, assigning the value of the Inner Unique tag to true.

5. The Nestloop connection execution method in opengauss according to claim 1, characterized in that: Step S3 includes: Step S31: traverse the outer table and inner table respectively to obtain an outer table tuple and an inner table tuple; Step S32: Determine whether the obtained inner table tuple and the obtained outer table tuple meet the connection condition; Step S33: Add the outer table tuples and inner table tuples that meet the join conditions to the result set, and determine whether there is an Inner Unique flag in the Nestloop execution plan.

6. The Nestloop connection execution method in opengauss according to claim 5, characterized in that: Step S32 includes: when the obtained inner table tuple and the obtained outer table tuple do not meet the connection condition, re-obtain another inner table tuple in the inner table, and determine whether the obtained another inner table tuple and the outer table tuple obtained in step S31 meet the connection condition.

7. The Nestloop connection execution method in opengauss according to claim 1, characterized in that: Step S33 includes: If the Inner Unique flag does not exist in the Nestloop execution plan, another inner table tuple in the inner table is retrieved again, and it is determined whether the retrieved inner table tuple and the outer table tuple obtained in step S31 meet the join condition. The outer table tuple and the inner table tuple that meet the join condition are added to the result set, and it is determined whether the Inner Unique flag exists in the Nestloop execution plan. When the Inner Unique flag exists in the Nestloop execution plan, traverse the outer table and inner table respectively, re-obtain an outer table tuple and an inner table tuple, determine whether the re-obtained inner table tuple and the obtained outer table tuple meet the join conditions, add the outer table tuple and inner table tuple that meet the join conditions to the result set, and determine whether the Inner Unique flag exists in the Nestloop execution plan.

Citation Information

Patent Citations

  • Optimized execution method and device of SQL (Structured Query Language) statement, electronic equipment and medium

    CN115687392A