Database operation statement processing method and related product
By identifying and deduplication only the key columns in the execution plan of the database operation statement, the unnecessary deduplication problem of other target columns in the database operation is solved, and the efficiency and resource utilization of database operations are improved.
Patent Information
- Application Number
- CN202411709249.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-02-14
AI Technical Summary
In database operations, when deduplication of columns with unique and non-empty properties, other target columns are still deduplicated, resulting in excessive consumption of database resources.
By determining whether there are key columns of the data source table in the database operation statement, if so, modify the execution plan so that only the key columns are deduplicated, reducing the target columns that need to be deduplicated in the deduplicated node.
Without affecting the execution results of the database operation statement, reduce the target columns in the deduplication node that need to be deduplicated, avoid wasting database resources, and improve execution efficiency.
Smart Images

Figure CN119441305A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a method for processing database operation statements and related products. Background Art
[0002] In current common database technologies, when faced with keywords such as distinct that have deduplication properties, all target columns corresponding to distinct are usually deduplicated in the execution plan. However, in some cases, deduplication of all table data can be completed by deduplicating certain columns with unique and non-empty properties. At this time, deduplication of other target columns of the table will cause unnecessary consumption of database resources. Summary of the invention
[0003] In view of the above problems, the present invention proposes a method for processing database operation statements and related products that overcome the above problems or at least partially solve the above problems.
[0004] An object of the present invention is to optimize the execution plan of a database operation statement that meets the conditions.
[0005] A further object of the present invention is to simplify the target columns that need to be deduplicated in the deduplication nodes in the execution plan.
[0006] In particular, the present invention provides a method for processing a database operation statement, comprising:
[0007] Get database operation statements;
[0008] Determine whether the database operation statement needs to deduplicate the result set;
[0009] If yes, then obtain the target column and data source table involved in deduplication in the database operation statement, and determine whether there is a key column of the data source table in the target column. The key column is a column in the data source table with unique properties and non-null constraints;
[0010] When the target column contains a key column of the data source table, modify the execution plan of the database operation statement so that the database operation statement only deduplicates the key column.
[0011] Optionally, the step of determining whether the target column contains a key column of the data source table includes:
[0012] Classify the target columns according to the data source table to obtain the target column set corresponding to each data source table;
[0013] Determine one by one whether there is a corresponding key column of the data source table in each target column set.
[0014] Optionally, the key columns include primary key columns;
[0015] The steps of determining whether each target column set has a corresponding key column of the data source table include:
[0016] Get the primary key column in the data source table;
[0017] Determine whether there is a primary key column in the target column set corresponding to the data source table;
[0018] If so, it is determined that the target column set contains the key columns of the data source table.
[0019] Optionally, the key columns include unique index columns;
[0020] The steps of determining whether each target column set has a corresponding key column of the data source table include:
[0021] Get the unique index column in the data source table;
[0022] Determine whether there is a non-null constraint on the unique index column;
[0023] If so, determine whether there is a unique index column in the target column set corresponding to the data source table;
[0024] If so, it is determined that the target column set contains the key columns of the data source table.
[0025] Optionally, the step of modifying the execution plan of the database operation statement so that the database operation statement only deduplicates key columns includes:
[0026] Get the deduplicated nodes in the execution plan corresponding to the database operation statement;
[0027] In the deduplication node, delete target columns other than the key columns in the target column set corresponding to the data source table.
[0028] Optionally, the step of determining whether the database operation statement needs to deduplicate the result set includes:
[0029] Determine whether there are deduplication keywords in the database operation statement;
[0030] If so, it is determined that the database operation statement needs to deduplicate the result set.
[0031] Optionally, the deduplication keywords include: distinct and set deduplication keywords.
[0032] According to another aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned methods for processing database operation statements are implemented.
[0033] According to another aspect of the present invention, a computer program product is provided, which includes a computer program, and when the computer program is executed by a processor, the steps of any one of the above-mentioned methods for processing database operation statements are implemented.
[0034] According to another aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements the steps of any of the above-mentioned database operation statement processing methods when executing the machine executable program.
[0035] The method for processing database operation statements of the present invention first obtains the database operation statement; determines whether the database operation statement needs to deduplicate the result set; if so, obtains the target column and data source table involved in deduplication in the database operation statement, and determines whether there is a key column of the data source table in the target column, the key column being a column with deduplication properties in the data source table; when there is a key column of the data source table in the target column, modifies the execution plan of the database operation statement so that the database operation statement only deduplicates the key column. Through this method, the target columns that need deduplication operations in the deduplication node can be reduced without affecting the execution results of the database operation statement, thereby avoiding the waste of database resources and improving execution efficiency.
[0036] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0038] Figure 1 is a flowchart of a method for processing database operation statements according to an embodiment of the present invention;
[0039] Figure 2 is a flowchart of a method for processing database operation statements according to another embodiment of the present invention;
[0040] Figure 3 is a schematic diagram of a computer program product according to an embodiment of the present invention;
[0041] Figure 4 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and
[0042] Figure 5is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0043] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.
[0044] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0045] The present invention provides a method for processing database operation statements. Figure 1 FIG. 1 is a flow chart of a method for processing a database operation statement according to an embodiment of the present invention. Figure 1 As shown, the method for processing the database operation statement at least includes the following steps S101 to S105.
[0046] Step S101, obtaining database operation statements. An optional example is SQL (Structured Query Language). SQL statements have multiple functions such as data manipulation and data definition. This language has interactive characteristics and can provide great convenience for users. In this step, the way to receive database operation statements can generally be active input by the user, or automatically generated by the database program during operation due to business needs. Those skilled in the art can decide the way to receive database operation statements according to actual conditions.
[0047] Step S102, determining whether the database operation statement needs to deduplicate the result set.
[0048] In some optional embodiments, the step of determining whether a database operation statement needs to deduplicate the result set may generally include: determining whether there are deduplication keywords in the database operation statement; if so, determining that the database operation statement needs to deduplicate the result set. The deduplication keywords generally include: distinct and set deduplication keywords and other keywords containing deduplication properties. Distinct is generally used in SQL to remove duplicate rows in query results and only return unique values. Its working principle is to compare on a specific column or expression. If the value in a row is different from any previous row, the row will be included in the result set; otherwise, the row will be discarded. The set deduplication keywords generally include: intersection deduplication keywords union, union deduplication keywords intersect, and difference deduplication keywords except, etc., which are keywords used for operations between sets. The union keyword is used to merge the result sets of two or more query statements and remove duplicate rows. The intersect keyword is used to return the intersection of two query result sets, that is, the rows that exist in both result sets, and intersect will remove duplicate rows. The except keyword is used to return the rows that exist in the first query result set but not in the second query result set. Except will remove duplicate rows.
[0049] In addition, the deduplication keyword can also be a keyword such as unique. Such keywords can be applied to SQL query statements for deduplication processing in some current databases, so that a deduplication node appears in the execution plan of the SQL query statement to perform deduplication processing on the target column contained in the deduplication keyword.
[0050] It should be noted that this method does not limit the specific type of deduplication keywords. As long as the deduplication keywords can cause a deduplication node to appear in the execution plan of the database operation statement to perform deduplication processing on the target column contained in the deduplication keywords, technical personnel in this field can determine the specific type of deduplication keywords according to actual conditions.
[0051] Therefore, step S102 may generally further include: obtaining an execution plan corresponding to the database operation statement, and determining whether there is a deduplication node in the execution plan; if so, determining that the database operation statement needs to deduplicate the result set.
[0052] Step S103, if the judgment in step S102 is yes, obtain the target column and data source table participating in deduplication in the database operation statement. Wherein, whether the target column participates in deduplication can be determined by judging whether the target column is referenced by the deduplication keyword.
[0053] Step S104, determine whether the target column contains a key column of the data source table. If the key column does not exist in the target column set corresponding to a data source table, it is still necessary to continue to deduplicate the target columns in the target column set and continue to determine the target column set corresponding to the next data source table.
[0054] In some optional embodiments, the step of determining whether there is a key column of the data source table in the target column may generally include: classifying the target column according to the data source table to obtain a target column set corresponding to each data source table; and determining whether there is a key column of the corresponding data source table in each target column set. Since the database operation statement may not query only one data source table, it is necessary to classify the target column and the data source table involved in deduplication, so as to obtain a target column set corresponding to each data source table, and then determine them one by one.
[0055] Step S105: if the result of step S104 is yes, modify the execution plan of the database operation statement so that the database operation statement only deduplicates the key columns.
[0056] In some optional embodiments, step S105 may generally include: obtaining a deduplication node in the execution plan corresponding to the database operation statement; deleting other target columns other than the key column in the target column set corresponding to the data source table in the deduplication node. When it is determined that there is a key column of the data source table in the target column, after the key column is deduplicated in the deduplication node, the row of data can be determined to be unique. At this time, continuing to deduplicate other columns in the same data source table will not affect the result. Therefore, in the case of a key column, deduplication operations on other target columns in the same data source table (that is, other target columns other than the key column in the target column set corresponding to the data source table) are redundant operations. In order to reduce the consumption of database resources, you can choose to delete other target columns other than the key column in the target column set corresponding to the data source table in the deduplication node, thereby reducing redundant operations.
[0057] Through this method, the target columns that need to be deduplicated in the deduplication node can be reduced without affecting the execution results of the database operation statements, thereby avoiding the waste of database resources and improving execution efficiency.
[0058] In some optional embodiments, the key column may generally include a primary key column. The step of determining whether there is a key column of the corresponding data source table in each target column set may generally include: obtaining the primary key column in the data source table; determining whether there is a primary key column in the target column set corresponding to the data source table; if there is, determining that there is a key column of the data source table in the target column set. The primary key column refers to a column in a database table that is used to uniquely identify each row of records in the table. And the characteristics of the primary key column generally include: uniqueness, that is, the value of each primary key is unique in the table, ensuring that each row of data can be uniquely identified; non-emptiness, that is, the value of the primary key is not allowed to be empty, and each row must have a valid primary key value; stability, that is, once defined, the value of the primary key cannot be changed in the table, ensuring the stability of the data. After the primary key column is deduplicated in the deduplication node, the row of data can be determined to be unique, and at this time, continuing to dedupe other columns in the same data source table will not affect the result. Therefore, in the case of a primary key column, deduplication operations on other target columns in the same data source table are redundant operations. Its execution plan can be optimized to avoid redundant operations.
[0059] In some other optional embodiments, the key column may also include a unique index column. The step of determining whether there is a key column of the corresponding data source table in each target column set one by one may generally include: obtaining the unique index column in the data source table; determining whether there is a non-null constraint on the unique index column; if so, determining whether there is a unique index column in the target column set corresponding to the data source table; if so, determining whether there is a key column of the data source table in the target column set. Among them, a unique index column generally refers to an index column with a unique property in the data source table, and there can be multiple unique indexes in the same table, but since the unique index column is allowed to contain null values, it is necessary to determine whether there is a non-null constraint on the unique index column at present, for example, the data source table structure adds a non-null constraint to the column, or the current database operation statement filters the null values in the unique index column through some conditions. If there is a non-null constraint on the unique index column, then after the primary key column is deduplicated in the deduplication node, the row of data can be determined to be unique, and continuing to deduplicate other columns in the same data source table will not affect the result. Therefore, in the case where there is a unique index column and the unique index column has a non-null constraint, deduplication operations on other target columns in the same data source table are redundant operations. Its execution plan can be optimized to avoid redundant operations.
[0060] In addition, if the target column set corresponding to a data source table contains both a primary key column and a unique index column with a non-null constraint, you can choose to keep the primary key column and delete other target columns in the corresponding target column set, or you can choose to keep only the unique index column with a non-null constraint. A preferred processing method is to keep the primary key column and delete other target columns in the corresponding target column set. Those skilled in the art can decide on the optimization plan according to actual conditions.
[0061] Figure 2 FIG. 1 is a flow chart of a method for processing a database operation statement according to another embodiment of the present invention. Figure 2 As shown, the method for processing the database operation statement at least includes the following steps S201 to S208.
[0062] Step S201, obtaining a database operation statement.
[0063] Step S202, determining whether there are duplicate removal keywords in the database operation statement.
[0064] Step S203, when the judgment in step S202 is yes, obtain the target column and data source table involved in deduplication in the database operation statement.
[0065] Step S204: classify the target columns according to the data source table to obtain a target column set corresponding to each data source table.
[0066] Step S205 , determining whether there is a corresponding key column of the data source table in each target column set.
[0067] Step S206, when the judgment in step S205 is yes, obtain the deduplicated nodes in the execution plan corresponding to the database operation statement.
[0068] Step S207: Delete other target columns except the key column in the target column set corresponding to the data source table in the deduplication node.
[0069] Through this method, the target columns that need to be deduplicated in the deduplication node can be reduced without affecting the execution results of the database operation statements, thereby avoiding the waste of database resources and improving execution efficiency.
[0070] In order to clearly illustrate the processing flow of this method, some optional embodiments are proposed as follows:
[0071] Embodiment 1:
[0072] select distinct pk,id from t1 formula 1
[0073] When the SQL statement shown in Formula 1 is obtained, it is first determined whether there is a deduplication keyword. Since distinct exists in the SQL statement shown in Formula 1, it is determined to be yes; then the target column and data source table participating in deduplication in the database operation statement are obtained. From "distinct pk,id", it can be determined that the target columns participating in deduplication are the pk (Primary Key) column and id column of the t1 table, and the corresponding data source table is the t1 table; since the key column of the t1 table (that is, the pk column) exists in the target column participating in deduplication, this method can be used for optimization.
[0074] The specific optimization operation is to obtain the deduplication node in the execution plan corresponding to the SQL statement shown in Formula 1, and delete other target columns except the key column in the target column set corresponding to the data source table in the deduplication node.
[0075] In some databases, the SQL statement shown in Formula 1 originally corresponds to the following partial execution plan:
[0076] HashAggregate
[0077] Group Key:pk,id
[0078] Seg Scan on t1
[0079] The Group Key contains the deduplication node. The original execution plan needs to deduplicate the pk column and the id column. Since the pk column is the primary key column, it participates in the deduplication operation, and the data in the t1 table will not be repeated. Therefore, the id column is deleted so that it does not participate in the deduplication operation. The execution plan after this method can be optimized as follows:
[0080] HashAggregate
[0081] Group Key:pk
[0082] Seg Scan on t1
[0083] Compared with the original execution plan, the optimized execution plan deletes the id column in the deduplication node, so that the database does not need to perform deduplication processing based on the id column during execution, and only needs to process the pk column, thereby reducing the consumption of database resources and improving query efficiency and database performance.
[0084] Embodiment 2:
[0085] select distinct t1.pk,t2.uni,t1.id,t2.id from t1 left join t2 on t1.id < t2.id where t2.uni is not null Formula 2
[0086] When obtaining the SQL statement shown in Formula 2, first determine whether there is a distinct keyword. Since there is a distinct in the SQL statement shown in Formula 2, it is determined to be yes;
[0087] Next, obtain the target columns and data source tables involved in deduplication in the database operation statement. From "distinct t1.pk,t2.uni,t1.id,t2.id", it can be determined that the target columns involved in deduplication are the pk (Primary Key) column and id column of table t1, and the uni (unique) column and id column of table t2;
[0088] Subsequently, classify to obtain the set of target columns corresponding to table t1 as the pk (Primary Key) column and id column, and the set of target columns corresponding to table t2 as the uni (unique) column and id column;
[0089] Next, judge one by one whether there is a key column of the corresponding data source table in each set of target columns. For table t1, since its primary key column (pk column) is in the set of target columns, the execution plan corresponding to table t1 can be optimized. The original part of the execution plan corresponding to the SQL statement shown in Formula 2 is as follows:
[0090] Unique
[0091] Increnental Sort
[0092] Sort Key:t1.pk, t2.uni,tl.id, t2.id
[0093] Presorted Key:tl.pk
[0094] Nested Loop
[0095] Join Filter:(t1.id < t2.id)
[0096] Index Scan using tl_pkey on t1
[0097] Materialize
[0098] seg Scan on t2
[0099] Filter:(UnI IS NOT NULL)
[0100] The Sort Key includes the deduplication node. The original execution plan requires deduplication of the pk column and the id column in the t1 table. Since the pk column is the primary key column, it participates in the deduplication operation, and there will be no duplication of data in the t1 table. Therefore, delete the other columns in the target column set corresponding to the t1 table, that is, the t1.id column, so that it does not participate in the deduplication operation.
[0101] For table t2, since it has a uni column and is further restricted by "where t2.uniis not null" in the SQL statement, the uni column has a non-null constraint, so the uni column can also be called the key column of table t2. Since the key column uni exists in the target column set corresponding to table t2, the execution plan corresponding to table t2 can be optimized;
[0102] The original execution plan required deduplication of the uni column and id column in the t2 table. Since the uni column is a unique and non-null key column, it participates in the deduplication operation, and there will be no duplication of data in the t2 table. Therefore, delete other columns in the target column set corresponding to the t2 table, that is, the t2.id column, so that it does not participate in the deduplication operation.
[0103] Finally, the execution plan processed by this method can be optimized as follows:
[0104] Unique
[0105] Increnental Sort
[0106] Sort Key:t1.pk,t2.uni
[0107] Presorted Key:tl.pk
[0108] Nested Loop
[0109] Join Filter:(t1.id <t2.id)
[0110] Index Scan using tl_pkey on t1
[0111] Materialize
[0112] seg Scan on t2
[0113] Filter:(UnI IS NOT NULL)
[0114] Compared with the original execution plan, the optimized execution plan deletes the t1.id column and t2.id column in the deduplication node, so that the database does not need to perform deduplication based on the id columns of the two tables during execution, and only needs to process the key columns, thereby reducing the consumption of database resources and improving query efficiency and database performance.
[0115] Embodiment three:
[0116] select*from t1 union select*from t2 formula 3
[0117] When the SQL statement shown in Formula 2 is obtained, it is first determined whether there is a deduplication keyword. Since the SQL statement shown in Formula 2 contains the intersection deduplication keyword union, it is determined to be yes.
[0118] Next, we obtain the target columns and data source tables involved in deduplication in the database operation statements. Since the existence of union will deduplicate the result sets of the two query branches, the target columns of the two query branches will be deduplicated. Assume that both tables t1 and t2 include pk (Primary Key), id, and val columns. Then we classify the target columns corresponding to table t1 as t1.pk, t1.id, and t1.val, and the target columns corresponding to table t2 as t2.pk, t2.id, and t2.val.
[0119] Then, we determine whether the corresponding key columns of the data source table exist in each target column set. For table t1, since its primary key column (pk column) is in the target column set, we can optimize the execution plan corresponding to table t1. The original execution plan corresponding to the SQL statement shown in Formula 3 is:
[0120] Group Key:t1.pk,t1.id,t1.val,t2.pk,t2.id,t2.val
[0121] The Group Key includes a deduplication node. The original execution plan requires deduplication of the pk column, id column, and val column in the t1 table. Since the pk column is the primary key column, it participates in the deduplication operation, and there will be no duplication of data in the t1 table. Therefore, delete the other columns in the target column set corresponding to the t1 table, namely the t1.id column and the t1.val column, so that they do not participate in the deduplication operation.
[0122] Similarly, for table t2, you need to delete other columns in the target column set corresponding to table t2, namely, the t2.id column and the t2.val column, so that they do not participate in the deduplication operation.
[0123] Finally, the partial execution plan processed by this method can be optimized as follows:
[0124] Group Key:t1.pk,t2.pk
[0125] Compared with the original execution plan, the optimized execution plan deletes columns other than t1.pk and t2.pk in the deduplication node, so that the database does not need to perform deduplication based on the id and val columns of the two tables during execution. Only the key columns need to be processed, thereby reducing the consumption of database resources and improving query efficiency and database performance.
[0126] The flow chart provided by the present embodiment is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical thinking provided by the present embodiment method, additional changes may be made to the above method.
[0127] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0128] This embodiment also provides a computer program product 10 , a computer readable storage medium 20 , and a computer device 30 . Figure 3 is a schematic diagram of a computer program product 10 according to an embodiment of the present invention, Figure 4 is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention, Figure 5 is a schematic diagram of a computer device 30 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which implements the steps of any of the above-mentioned methods for processing database operation statements when executed by a processor 32. The computer-readable storage medium 20 stores the above-mentioned computer program 11, which implements the steps of any of the above-mentioned methods for processing database operation statements when executed by a processor 32. The computer device 30 may include a memory 31, a processor 32, and the computer program 11 stored in the memory 31 and running on the processor 32.
[0129] The computer program 11 for performing the operation of the present invention may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-related instruction, a microcode, a firmware instruction, a state setting data, a configuration data of an integrated circuit, or a source code or an object code written in any combination of one or more programming languages and process programming languages. The computer program 11 may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network (including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider via the Internet). In some embodiments, in order to perform various aspects of the present invention, an electronic circuit including, for example, a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA) may execute computer-readable program instructions by utilizing the state information of the computer-readable program instructions to personalize the electronic circuit.
[0130] For the purposes of the description of the present embodiment, the computer program product 10 is a related product that includes the computer program 11. For the purposes of the description of the present embodiment, the computer readable storage medium 20 is a tangible device capable of retaining and storing the computer program 11, which may be any device that can contain, store, communicate, propagate or transmit the program 11 for use with or in conjunction with an instruction execution system, device or apparatus. More specific examples (a non-exhaustive list) of the computer readable storage medium 20 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the foregoing.
[0131] The computer device 30 may be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, the computer device 30 may be a cloud computing node. The computer device 30 may be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module may include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device 30 may be implemented in a distributed cloud computing environment where remote processing devices linked via a communication network perform tasks. In a distributed cloud computing environment, program modules may be located on a local or remote computing system storage medium including a storage device.
[0132] The computer device 30 may include a processor 32 adapted to execute stored instructions, and a memory 31 providing temporary storage space for the operation of the instructions during operation. The processor 32 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 31 may include a random access memory (RAM), a read-only memory, a flash memory, or any other suitable storage system.
[0133] The computer device 30 may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows data to be input and output with external devices that may be connected to the computer device. The network adapter / interface may provide communication between the computer device and a network, which is typically shown as a communication network.
[0134] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A method for processing a database operation statement, comprising: Obtaining the database operation statement; Determine whether the database operation statement needs to deduplicate the result set; If yes, then obtain the target column and the data source table involved in deduplication in the database operation statement, and determine whether there is a key column of the data source table in the target column, where the key column is a column in the data source table with a unique property and a non-null constraint; In the case where the target column contains a key column of the data source table, the execution plan of the database operation statement is modified so that the database operation statement only deduplicates the key column.
2. The method for processing database operation statements according to claim 1, wherein: The step of judging whether the target column contains a key column of the data source table comprises: Classify the target columns according to the data source tables to obtain a target column set corresponding to each of the data source tables; It is determined one by one whether there is a corresponding key column of the data source table in each target column set.
3. The method for processing database operation statements according to claim 2, wherein: The key columns include primary key columns; The step of determining whether each target column set has a corresponding key column of the data source table comprises: Obtain the primary key column in the data source table; Determine whether the primary key column exists in the target column set corresponding to the data source table; If so, it is determined that the key column of the data source table exists in the target column set.
4. The method for processing database operation statements according to claim 3, wherein: The key column includes a unique index column; The step of determining whether each target column set has a corresponding key column of the data source table comprises: Obtain the unique index column in the data source table; Determine whether the unique index column has a non-null constraint; If so, determining whether the unique index column exists in the target column set corresponding to the data source table; If so, it is determined that the key column of the data source table exists in the target column set.
5. The method for processing database operation statements according to claim 2, wherein: The step of modifying the execution plan of the database operation statement so that the database operation statement only deduplicates the key column comprises: Obtaining the deduplicated nodes in the execution plan corresponding to the database operation statement; In the deduplication node, other target columns other than the key column in the target column set corresponding to the data source table are deleted.
6. The method for processing database operation statements according to claim 1, wherein: The step of determining whether the database operation statement needs to deduplicate the result set comprises: Determine whether there is a deduplication keyword in the database operation statement; If so, it is determined that the database operation statement needs to deduplicate the result set.
7. The method for processing database operation statements according to claim 6, wherein: The de-duplication keywords include: distinct and set de-duplication keywords.
8. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method for processing a database operation statement according to any one of claims 1 to 7 are implemented.
9. A computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method for processing a database operation statement according to any one of claims 1 to 7.
10. A computer device comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, wherein the processor implements the steps of the method for processing database operation statements according to any one of claims 1 to 7 when executing the machine executable program.