Overwrite optimization method and apparatus for database partition table
By constructing an auxiliary table partition with the same structure as the specified partition, receiving the overwrite instruction, writing the data to be written to the auxiliary table partition, and performing partition swapping, the problem of low overwrite efficiency in the existing technology is solved, and efficient overwrite operation is achieved.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- BEIJING OCEANBASE TECHNOLOGY CO LTD
- Filing Date
- 2026-01-23
- Publication Date
- 2026-07-30
AI Technical Summary
Existing technologies are inefficient when performing overwrite operations on a specified partition of a database partitioned table. They require deleting old data row by row and then inserting new data, resulting in prolonged occupation of database resources.
By constructing an auxiliary table partition with the same structure as the specified partition, receiving overwrite write commands, writing the data to be written to the auxiliary table partition, and performing partition swapping after the data writing is completed to replace the specified partition, thus avoiding the deletion of old data row by row.
It improves the execution efficiency of overwrite operations, reduces the long-term occupation of database partition tables, and enhances the efficiency and performance of overwrite operations.
Smart Images

Figure CN2026074532_30072026_PF_FP_ABST
Abstract
Description
Methods and apparatus for optimizing overwrite operations on database partitioned tables Technical Field
[0001] This specification relates to the field of database technology, and in particular to a method and apparatus for optimizing overwrite operations on partitioned database tables. Background Technology
[0002] Database partitioned tables can be implemented using database partitioning technology. Logically, a database partitioned table is a single, complete table, but physically it is divided into multiple partitions. By evenly distributing partitions of the same database partitioned table across multiple nodes, each partition can be used independently to provide query services. This significantly improves query performance, simplifies data management and maintenance, and helps to better utilize storage resources.
[0003] In some scenarios, it is necessary to perform an overwrite operation on a specified partition in a database partitioned table, that is, to overwrite the old data in the specified partition with new data. In related technologies, the above-mentioned overwrite operation on a specified partition includes two steps: first, deleting the old data in the specified partition row by row, and then inserting the new data into the specified partition row by row. Summary of the Invention
[0004] In view of this, one or more embodiments of this specification provide a method and apparatus for optimizing overwrite operations on database partitioned tables.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a method for optimizing overwrite operations on a database partitioned table is proposed. The method includes: receiving a partition overwrite instruction, the partition overwrite instruction being used to instruct an overwrite operation on a specified partition in the database partitioned table; determining the partition type and partition rules of the database partitioned table; constructing an auxiliary table according to the determined partition type and partition rules; creating an auxiliary table partition, the auxiliary table partition being a partition corresponding to the specified partition and having the same structure as the specified partition; writing the data to be written as indicated by the partition overwrite instruction into the auxiliary table partition; and after the data writing is completed, performing a partition swap between the specified partition and the auxiliary table partition.
[0007] According to a second aspect of one or more embodiments of this specification, an overwrite optimization apparatus for a database partition table is provided. The apparatus includes: an instruction receiving unit for receiving a partition overwrite instruction, the partition overwrite instruction being used to instruct an overwrite write to a specified partition in the database partition table; a type and rule determination unit for determining the partition type and partition rules of the database partition table; an auxiliary table construction unit for constructing an auxiliary table according to the determined partition type and partition rules; an auxiliary table partition creation unit for creating an auxiliary table partition, the auxiliary table partition being a partition corresponding to the specified partition and having the same structure as the specified partition; a data writing unit for writing the data to be written as indicated by the partition overwrite instruction to the auxiliary table partition; and a partition swapping unit for swapping the specified partition and the auxiliary table partition after the data writing is completed.
[0008] According to a third aspect of one or more embodiments of this specification, a computer program product is provided, comprising a computer program / instructions that, when executed by a processor, implement the steps of the method described in the first aspect.
[0009] According to a fourth aspect of one or more embodiments of this specification, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor performs the executable instructions to implement the method as described in the first aspect.
[0010] According to a fifth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided that stores computer instructions thereon, which, when executed by a processor, implement the steps of the method as described in the first aspect.
[0011] The technical solutions provided in the embodiments of this specification may include the following beneficial effects:
[0012] In the embodiments of this specification, for a received partition overwrite instruction instructing a specified partition in the database partition table to be overwritten, the partition type and partition rules of the database partition table are determined, and an auxiliary table containing an auxiliary table partition with the same structure as the specified partition is constructed accordingly. This allows the data to be written as indicated by the partition overwrite instruction to be directly written to the auxiliary table partition. Furthermore, by swapping the auxiliary table partition and the specified partition, the database partition table can contain a partition with the relevant data already written, without affecting the structure of the database partition table. Therefore, when faced with the need to overwrite a specified partition, this embodiment of the specification utilizes partition swapping technology to exchange the auxiliary table partition containing the data to be written with the specified partition containing the old data. This is equivalent to replacing the specified partition in the database partition table with the auxiliary table partition, thus eliminating the need to wait for the old data in the specified partition to be deleted row by row. This helps improve the execution efficiency of the partition overwrite instruction and efficiently achieves the overwrite of the database partition table. Attached Figure Description
[0013] Figure 1 is a flowchart of an exemplary embodiment of a method for optimizing overwrite operations on a database partitioned table.
[0014] Figure 2 is a schematic diagram of a construction auxiliary table and its contained partitions provided in an exemplary embodiment.
[0015] Figure 3 is a schematic diagram of a construction auxiliary table and its contained partitions provided in another exemplary embodiment.
[0016] Figure 4 is a schematic diagram of data writing to an auxiliary table partition provided by another exemplary embodiment.
[0017] Figure 5 is a schematic diagram of partition switching provided by another exemplary embodiment.
[0018] Figure 6 is a schematic diagram of the structure of a device provided in an exemplary embodiment.
[0019] Figure 7 is a block diagram of an overwrite write optimization apparatus for a database partitioned table provided in an exemplary embodiment. Detailed Implementation
[0020] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0021] It should be noted that the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification in other embodiments. In some other embodiments, the methods may include more or fewer steps than described in this specification. Furthermore, a single step described in this specification may be broken down into multiple steps in other embodiments; and multiple steps described in this specification may be combined into a single step in other embodiments.
[0022] When performing overwrite operations on a specified partition in a database partitioned table, related technologies often use DML (Data Manipulation Language) statements. Specifically, the execution logic of DML statements involves first deleting the original data in the partition row by row, and then inserting new data into the partition row by row. This results in low execution efficiency for the aforementioned overwrite operation.
[0023] Based on the above-mentioned technical problems, at least one embodiment of this specification provides an optimization method for overwrite operations on database partitioned tables. This method can effectively improve the execution efficiency of overwrite operations and avoid prolonged occupation of the database partitioned table in scenarios where overwrite operations are performed on specified partitions of the database partitioned table.
[0024] Please refer to Figure 1, which exemplarily illustrates the flow of the method, including steps S101 to S103.
[0025] In step S101, a partition overwrite instruction is received, which is used to instruct a specified partition in the database partition table to be overwritten.
[0026] Partition overwrite commands can originate from users. This can be understood as the command being issued by the user's account, but in reality, it can be manually triggered by the user or automatically triggered based on user-defined logic (such as being issued periodically or based on event triggers).
[0027] A database partitioned table can be any partitioned table within the database. Specifying a partition can include any partition within that table, as indicated by partition override commands. A database partitioned table is a data table containing partitions, and its structure includes fields, a primary key, partition type, and partition rules. Fields refer to the fields contained in the data table; the primary key refers to the field that serves as the primary key; partition types can include range partitioning, list partitioning, hash partitioning, key partitioning, etc., meaning the database partitioned table uses one of these partition types; partition rules refer to the rules governing how a data row belongs to which partition under the partition type.
[0028] Taking the following SQL (Structured Query Language) statement as an example, the data table contains fields c1 and c2, with c1 as the primary key and range partitioning as the partitioning type. The partitioning rules are as follows: if the value of field c1 in a data row is less than 10, the data row belongs to partition P0; if the value of field c1 in a data row is not less than 10 and less than 20, the data row belongs to partition P1; if the value of field c1 in a data row is not less than 20 and less than 30, the data row belongs to partition P2; and if the value of field c1 in a data row is not less than 30, the data row belongs to partition P3.
[0029] SQL statement:
[0030] The data to be written can come from a data source table. This data source table can be another data table within the database containing the database partition table, or a data file outside the database, or both; this specification does not impose any restrictions on this. A data file outside the database can be called an external table, and its file format can be a data table or other data formats.
[0031] The partition override command can designate one or more partitions in a database partition table as the specified partitions mentioned above. Which partitions are designated as specified partitions depends on the partition type and partitioning rules of both the data source table and the database partition table.
[0032] For example, if the data source table and the database partition table have the same partition type and partition rules, the corresponding partition in the database partition table (e.g., having the same partition ID) can be determined based on the partition of the data to be written in the data source table, and used as the specified partition mentioned above. Typically, such a data source table is another data table within the same database as the database partition table, but it's possible that an external table might also be suitable. In short, in this case, the partition corresponding to the data to be written in the database partition table is known, so these partitions can be specified in the partition overwrite instruction.
[0033] For example, the data source table may not be a partitioned table, or although it is a partitioned table, its partitioning type or rules may differ from those of the database partitioned table. Therefore, the partition corresponding to the data to be written in the database partitioned table is unknown. In this case, the partition overwrite instruction can specify that all partitions in the database partitioned table are the specified partitions, because the data to be written needs to be distributed to each partition according to the partitioning type and rules used by the database partitioned table.
[0034] Take the data tables t1 and t2 created by the following SQL statements as examples:
[0035] SQL statement:
[0036] If t1 is used as the data source table and all data in t1 is used as the data to be written, then P1 and P3 of t2 can be used as auxiliary table partitions. That is, the partition overwrite instruction is the following SQL statement: insert overwrite t2_ins_overwrt partition(p1,p3) select * from t1_ins_overwrt.
[0037] In step S102, the partition type and partition rules of the database partition table are determined.
[0038] In step S103, an auxiliary table is constructed based on the determined partition type and partition rules.
[0039] In step S104, an auxiliary table partition is created. The auxiliary table partition is the partition corresponding to the specified partition, and its structure is consistent with that of the specified partition.
[0040] By determining the partition type and partitioning rules of the database partition table, an auxiliary table can be constructed with reference to these partition types and rules. This ensures that the structure of the auxiliary table partitions is consistent with the specified partitions in the database partition table, thereby ensuring that the auxiliary table partitions and the specified partitions can be swapped without affecting the normal use of the database partition table.
[0041] Please refer to Figure 2, which illustrates the creation process of an auxiliary table and its contained partitions using a hidden table as an example. It can be seen that data partitions 1 (origin_tablet_1) to n (origin_tablet_n) of the database partition table all have corresponding partitions within the hidden table, i.e., data partitions 1 (hidden_tablet_1) to n (hidden_tablet_n). Here, the partition type and partition conditions (i.e., the conditions that data belonging to data partition i must meet as specified in the partitioning rules) of both the target data table's data partition i (origin_tablet_i) and the hidden table's data partition i (hidden_tablet_i) are defined, where i is any integer not less than 1 and not greater than n.
[0042] Please refer to Figure 3, which uses data partition 2 (origin_tablet_2) and data partition n (origin_tablet_n) as examples to illustrate the creation process of auxiliary tables and their contained partitions. In this embodiment, for data partitions 1 (origin_tablet_1) to n (origin_tablet_n) of the database partition table, it is not necessary to create corresponding n data partitions in the hidden table, i.e., as described above, data partitions 1 (hidden_tablet_1) to n (hidden_tablet_n). Instead, only two partitions, data partition 2 (hidden_tablet_2) and data partition 2 (hidden_tablet_n), need to be created. Data partition 2 (origin_tablet_2) has the same structure as data partition 2 (hidden_tablet_2), and data partition n (origin_tablet_n) has the same structure as data partition n (hidden_tablet_n). This example can reduce the workload of constructing auxiliary tables, further improve the efficiency of overwrite, and reduce the space occupied in the database during the overwrite process.
[0043] In an embodiment similar to that shown in Figure 3, the process of constructing the auxiliary table may include: determining the structural information of the specified partition under the determined partition type and partition rules, creating the auxiliary table partition according to the determined structural information, and establishing a mapping relationship between the auxiliary table and the auxiliary table partition.
[0044] The structure information of a specified partition can include: the partition type and partition conditions. Partition conditions refer to the conditions that data belonging to the specified partition must meet, as stipulated in the partitioning rules. For example, in the case of a range partition, the partition condition refers to the range of data values corresponding to that partition; in the case of a hash partition, the partition condition refers to the hash value corresponding to that partition. Of course, the structure information of a specified partition can also include fields and a primary key to ensure that the specified partition and the auxiliary table partition support the same data to be written.
[0045] Because the partition needs to be created based on the structure information of the specified partition, namely the auxiliary table partition mentioned above, the auxiliary table actually only contains this auxiliary table partition and not other partitions. In fact, in subsequent partition swapping operations, only the specified partition and the auxiliary table partition are involved, not other partitions in the auxiliary table. Therefore, the creation operations for these other partitions are omitted. This saves the resources consumed by the creation operations of these other partitions without affecting the implementation of the overwrite scheme in this specification, thus improving the efficiency of the overwrite.
[0046] As mentioned earlier, auxiliary tables can be hidden tables, which are data tables visible within the database system but not to the user. The user can refer to the user who issued the overwrite partition command.
[0047] In step S105, the data to be written, as indicated by the partition overwrite instruction, is written to the auxiliary table partition.
[0048] If the auxiliary table partition includes multiple partitions, the auxiliary table partition corresponding to each row of data to be written can be determined according to the partition type and partition rules of the auxiliary table, and the data can be written to the determined auxiliary table partition.
[0049] For example, if the partition type of the auxiliary table is range partition, then when writing each row of data to be written, it can be determined which partition range the field to which the range partition belongs, and the row of data is written to the determined partition.
[0050] For example, if the partition type of the auxiliary table is hash partition, then when writing each row of data to be written, it is possible to determine which partition the hash value of the field to which the hash partition corresponds to, and then assign the partition determined by that row of data.
[0051] It should be understood that if the data source table and the database partition table have the same partition type and partition rules, that is, if the partitions contained in the data source table correspond one-to-one with the partitions contained in the database partition table, then when writing each row of data to be written, the corresponding partition in the target data table can be determined according to its partition in the data source table. Taking the above SQL statement 3 as an example, if (12,20) in t1 is in partition P1, then it is written to partition P1 of t2; if (34,40) and (45,50) in t1 are in partition P3, then they are written to partition P3 of t2.
[0052] Continuing with the example shown in Figure 3, which uses data partition 2 (origin_tablet_2) and data partition n (origin_tablet_n) as auxiliary table partitions, please refer to Figure 4, which illustrates the process of writing the data to be written to the auxiliary table partitions (such as data partition 2 (hidden_tablet_2), data partition n (hidden_tablet_n), etc.).
[0053] In step S106, after the data writing is completed, the specified partition and the auxiliary table partition are swapped.
[0054] Generally, the partition IDs of partitions in a partition table are positive integers starting from 0 or 1 and incrementing sequentially. For example, in the embodiment shown in Figure 3, the serial numbers are positive integers from 1 to n. When the structure of the specified partition and the auxiliary table partitions is consistent, their partition IDs can have the same serial number. Therefore, the serial number of the partition ID of the specified partition can be obtained, and the partition containing that serial number in the partition ID of the auxiliary table can be found and used as the aforementioned auxiliary table partition; and partition swapping can be performed between the found partition and the specified partition. In particular, when there are multiple specified partitions, the auxiliary table also needs to contain multiple auxiliary table partitions, so a one-to-one correspondence can be achieved between each specified partition and each auxiliary table partition based on the serial number of the partition ID.
[0055] During partition swapping, it is not necessary to swap the data stored in the partitions; only the mapping relationship between the data table and the partition needs to be updated. For example, a first mapping relationship between the database partition table and the specified partition, and a second mapping relationship between the auxiliary table and the auxiliary table partition are obtained respectively. Specifically, a mapping relationship between the database partition table and the auxiliary table partition is established to replace the first mapping relationship; and a mapping relationship between the auxiliary table and the specified partition is established to replace the second mapping relationship.
[0056] Continuing with the example shown in Figure 3, where data partition 2 (origin_tablet_2) and data partition n (origin_tablet_n) are used as auxiliary table partitions, please refer to Figure 5, which illustrates the partition swapping process in this example: data partition 2 (origin_tablet_2) is swapped with data partition 2 (hidden_tablet_2), and data partition n (origin_tablet_n) is swapped with data partition n (hidden_tablet_n). Please refer to Tables 1 and 2 below, which respectively show the mapping relationship before and after the partition swap in this example. It can be seen that before the swap, the data partition 2 (origin_tablet_2) corresponding to the database partition table is updated to data partition 2 (hidden_tablet_2), and before the swap, the data partition n (origin_tablet_n) corresponding to the target data table is updated to data partition n (hidden_tablet_n). Table 1: Mapping Relationship Before Partition Swap Table 2: Mapping Relationships After Partition Swap
[0057] In one embodiment, the auxiliary table may be temporary. Therefore, after the partition swap is completed, the auxiliary table's function is finished, and it can be deleted to save database space.
[0058] It should be understood that if the partitions in the database partition table need to be updated periodically, the auxiliary table can be left undeleted after step S106; only the data within the corresponding partitions in the auxiliary table can be deleted. While this deletion operation occupies the auxiliary table, it does not affect the external services of the database partition table. The auxiliary table is retained, allowing for subsequent overwrites of specified partitions within the database partition table without the need to temporarily create the auxiliary table and wait, thus further improving the efficiency of overwrite operations.
[0059] Figure 6 is a schematic structural diagram of a device provided in an exemplary embodiment. Referring to Figure 6, at the hardware level, the device includes a processor 602, an internal bus 604, a network interface 606, a memory 608, and a non-volatile memory 610, and may also include other hardware required for tasks. One or more embodiments of this specification can be implemented in software, for example, the processor 602 reads the corresponding computer program from the non-volatile memory 610 into the memory 608 and then runs it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0060] Please refer to Figure 7. The overwrite optimization device for database partition tables can be applied to the device shown in Figure 6 to implement the technical solution of this specification. This overwrite optimization device for database partition tables may include: an instruction receiving unit 701, which receives a partition overwrite instruction, the instruction indicating that a specified partition in the database partition table should be overwritten; a type and rule determination unit 702, which determines the partition type and partition rules of the database partition table; an auxiliary table construction unit 703, which constructs an auxiliary table according to the determined partition type and partition rules, wherein the auxiliary table includes an auxiliary table partition with the same structure as the specified partition; an auxiliary table partition creation unit 704, which creates an auxiliary table partition, the partition corresponding to the specified partition, and whose structure is consistent with the specified partition; a data writing unit 705, which writes the data to be written as indicated by the partition overwrite instruction into the auxiliary table partition; and a partition swapping unit 706, which swaps the specified partition and the auxiliary table partition after the data writing is completed.
[0061] Optionally, the auxiliary table partition creation unit 704 is specifically used to: determine the structural information of the specified partition under the determined partition type and partition rules; create the auxiliary table partition according to the determined structural information; and establish a mapping relationship between the auxiliary table and the auxiliary table partition.
[0062] Optionally, the auxiliary table is not visible to the user who issued the partition overwrite command.
[0063] Optionally, the partition swapping unit 706 is specifically used to: obtain the sequence number value contained in the partition ID of the specified partition, and search for the partition whose partition ID contains the sequence number value in the partitions contained in the auxiliary table; and perform partition swapping between the found partition and the specified partition.
[0064] Optionally, the partition switching unit 706 is specifically configured to: obtain a first mapping relationship between the database partition table and the specified partition, and a second mapping relationship between the auxiliary table and the auxiliary table partition; establish a mapping relationship between the database partition table and the auxiliary table partition to replace the first mapping relationship; and establish a mapping relationship between the auxiliary table and the specified partition to replace the second mapping relationship.
[0065] Optionally, the device further includes an auxiliary table deletion unit 707, which deletes the auxiliary table after the partition swap is completed.
[0066] One or more embodiments of this specification also provide a computer program product including a computer program / instructions that, when executed by a processor, implement the steps of the method provided in the first aspect.
[0067] One or more embodiments of this specification also provide a computer-readable storage medium having computer instructions stored thereon that, when executed by a processor, implement the steps of the method as described in the first aspect.
[0068] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which can take the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email sending and receiving device, game console, tablet computer, wearable device, or any combination of these devices.
[0069] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0070] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0071] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0072] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0073] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0074] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this specification. The singular forms “a,” “described,” and “the” used in one or more embodiments of this specification and in the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0075] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0076] It should be understood that although the terms first, second, third, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first information may also be referred to as second information without departing from the scope of one or more embodiments of this specification, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "in response to a determination," or "when," or "in the event of a determination."
[0077] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit the scope of one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of one or more embodiments of this specification should be included within the scope of protection of one or more embodiments of this specification.
Claims
1. A method for optimizing overwrite operations on partitioned tables in a database, the method comprising: Receive a partition overwrite instruction, which is used to instruct a specified partition in the database partition table to be overwritten; Determine the partition type and partition rules of the database partition table; Based on the determined partition type and partition rules, construct an auxiliary table; Create an auxiliary table partition, which is the partition corresponding to the specified partition and has the same structure as the specified partition; Write the data to be written as indicated by the partition overwrite instruction into the auxiliary table partition; After the data writing is completed, the specified partition and the auxiliary table partition are swapped.
2. The method according to claim 1, wherein creating the auxiliary table partition comprises: Determine the structural information of the specified partition under the determined partition type and partition rules; The auxiliary table partition is created based on the determined structural information, and a mapping relationship is established between the auxiliary table and the auxiliary table partition.
3. The method according to claim 1, wherein the auxiliary table is not visible to the user who issued the partition overwrite command.
4. The method according to claim 1, wherein the partition swapping of the designated partition and the auxiliary table partition includes: Obtain the sequence number value contained in the partition ID of the specified partition, and search for the partition whose partition ID contains the sequence number value in the partitions contained in the auxiliary table; Perform a partition swap between the found partition and the specified partition.
5. The method according to claim 1, wherein the partition swapping of the designated partition and the auxiliary table partition comprises: Obtain the first mapping relationship between the database partition table and the specified partition, and the second mapping relationship between the auxiliary table and the auxiliary table partition, respectively; Establish a mapping relationship between the database partition table and the auxiliary table partition to replace the first mapping relationship; In addition, a mapping relationship is established between the auxiliary table and the specified partition to replace the second mapping relationship.
6. The method according to claim 1, further comprising: After the partition swap is completed, the auxiliary table is deleted.
7. A device for optimizing overwrite operations on partitioned tables in a database, the device comprising: The instruction receiving unit receives a partition overwrite instruction, which is used to instruct a specified partition in the database partition table to be overwritten. The type and rule determination unit determines the partition type and partition rules of the database partition table; The auxiliary table construction unit constructs auxiliary tables based on the determined partition type and partition rules; The auxiliary table partition creation unit creates an auxiliary table partition, which is the partition corresponding to the specified partition and has the same structure as the specified partition. The data writing unit writes the data to be written as indicated by the partition overwrite instruction into the auxiliary table partition; The partition swapping unit performs partition swapping between the specified partition and the auxiliary table partition after completing the data writing.
8. An electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor implements the method as described in any one of claims 1 to 6 by executing the executable instructions.
9. A computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1 to 6.
10. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1 to 6.