Hash partition table management method and system based on openGauss database
By employing a linear hash partitioning algorithm in the openGauss database, the problem of insufficient scalability of traditional hash partitioning tables in dynamic data environments is solved, achieving efficient and stable partition management, optimizing resource utilization and maintenance complexity, and improving the scalability and performance of the system.
Patent Information
- Application Number
- CN202511014061.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-23
- Publication Date
- 2025-11-07
AI Technical Summary
Traditional hash partitioned tables lack scalability in dynamic data environments, resulting in large performance fluctuations, significant resource waste, and high maintenance complexity, failing to meet the needs of the big data era.
A linear hash partitioning algorithm based on the openGauss database is adopted. By constructing the relationship between the initial number of partitions n and the power order m, the target partition number is calculated using modulo operation. This enables data insertion, deletion, addition and reduction of partitions, affecting only a single partition and avoiding full table scans.
It enables smooth expansion of hash partition tables, improves performance stability and resource utilization, reduces maintenance complexity, adapts to dynamic data changes, and enhances system scalability and user experience.
Smart Images

Figure CN120910048A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database management, and in particular to a hash partition table management method based on an openGauss database. BACKGROUND
[0002] With the explosive growth of data, traditional hash partition tables are not capable of coping with dynamic data. For example, in the scenario of an openGauss database requiring efficient queries, once the traditional hash partition table reaches the capacity threshold, it must be fully reconstructed. This one-size-fits-all expansion method will cause a sudden drop in service performance, seriously affecting system response speed. Especially in a high-concurrency environment, such sudden performance fluctuations will cause request accumulation and even trigger system avalanches. How to achieve smooth expansion of hash partition tables and avoid service interruption has become an important issue in data structure optimization.
[0003] Many database systems have to pre-allocate excess space or set complex sharding strategies to alleviate the expansion impact in order to cope with the performance problems caused by hash table expansion. This not only causes a serious waste of storage resources, but also greatly increases the maintenance complexity of the system. In actual operation and maintenance, administrators need to repeatedly adjust parameters to balance space utilization and query performance, which not only consumes manpower but also is difficult to achieve ideal results.
[0004] Chinese Patent No. CN119739720A discloses a method and device for inserting data into a specified partition of an openGauss database. This scheme specifies the target partition in advance during the data insertion stage, skips unnecessary partition routing calculation, and improves the insertion performance of the partition table. The main disadvantage of this scheme in practical application is: 1. It is targeted at specific scenarios where known data should be inserted into a specific partition, such as data generated on the same day in a partition table divided by day. However, in actual application, data insertion scenarios are complex and diverse, and not all data insertion can explicitly know the target partition. For data insertion requests that cannot determine the target partition in advance, this method cannot take advantage of it and still needs to rely on traditional partition routing calculation, which greatly limits its scope of application. 2. It focuses on optimization during the data insertion stage and does not involve the dynamic expansion mechanism of the partition table itself. When facing data volume growth leading to dynamic adjustment of the number of partitions, it cannot provide an effective solution. For example, when the partition table needs to increase or decrease partitions to adapt to changes in data size, this method cannot achieve smooth expansion and contraction through linear hash partitioning algorithm as in Attachment 3, and cannot meet the long-term expansion needs of the database in a dynamic data environment.
[0005] Therefore, how to provide a low-overhead dynamic expansion method for hash tables has become a technical problem to be solved. SUMMARY
[0006] In view of the above, in order to overcome the deficiencies of the prior art, the present application aims to provide a hash partition table management method and system based on an openGauss database.
[0007] According to a first aspect of the present application, a hash partition table management method based on an openGauss database is provided, the method comprising the following steps:
[0008] By constructing the relationship between the initial number of partitions n and the power order m, the hash partition table is initialized;
[0009] When inserting or deleting data, the target partition number v is calculated, and data insertion or deletion operation is performed on the target partition;
[0010] When increasing the partition, the target partition number v that needs to move out data is calculated, and the data is moved from the target partition to the increased partition;
[0011] When reducing the partition, the target partition number v that needs to move in data is calculated, and the data of the deleted partition is moved into the target partition.
[0012] Optionally, in the hash partition table management method based on the openGauss database of the present application, when initializing the hash partition table, each partition of the partition table is independently stored and managed, wherein the relationship between the initial number of partitions n and the power order m is: 2 (m-1) <n≤2 m Wherein, m is the power order, and n is the initial number of partitions.
[0013] Optionally, in the hash partition table management method based on the openGauss database of the present application, when inserting or deleting data, the target partition number v is calculated according to the data hash code k and the power order m through modulo operation, and data insertion or deletion operation is performed on the target partition according to the target partition number v.
[0014] Optionally, in the hash partition table management method based on the openGauss database of the present application, when inserting or deleting data, the target partition number is calculated as follows:
[0015] The data hash code k is taken as the dividend, and 2 m is taken as the modulus to perform modulo operation, if the modulo operation result is less than n, the modulo operation result is taken as the target partition number v;
[0016] If the operation result is greater than or equal to n, the data hash code k is taken as the dividend, and 2 (m-1) is taken as the modulus to perform modulo operation, and the modulo operation result is taken as the target partition number v.
[0017] Optionally, the hash partition table management method based on the openGauss database of the present invention adds a partition to the partition table by initializing the database when adding a partition, provided that the number of partitions after the addition (n+1) is less than or equal to 2. m Scan partition n-2 (m-1) For objects within the partition, recalculate the target partition number v from which the data needs to be moved out based on the object's data hash code k. Move the data from the target partition to the newly added partition. If adding the partition fails, move the data from the target partition to partition n-2. (m-1) Inside.
[0018] Optionally, in the hash partition table management method based on the openGauss database of the present invention, when adding partitions, if the number of partitions after the addition (n+1) is greater than 2... m Scan partition n-2 m For objects within the partition, recalculate the target partition number v from which the data needs to be moved out based on the object's data hash code k. Move the data from the target partition to the newly added partition. If adding the partition fails, move the data from the target partition to partition n-2. m Inside.
[0019] Optionally, in the hash partition table management method based on the openGauss database of the present invention, when reducing the number of partitions, if the number of partitions after reduction (n-1) is greater than 2... (m-1) Scan the objects in partition n-1, recalculate the target partition number v from which the data needs to be moved out based on the data hash code k of the object, and move the data from the target partition to partition n-2. (m-1) -1 within.
[0020] Optionally, in the hash partition table management method based on the openGauss database of the present invention, when reducing the number of partitions, if the number of partitions after reduction (n-1) is less than or equal to 2... (m-1) Scan the objects in partition n-1, recalculate the target partition number v from which the data needs to be moved out based on the data hash code k of the object, and move the data from the target partition to partition n-2. (m-2) -1 within.
[0021] Optionally, the hash partition table management method based on the openGauss database of the present invention manages the hash partition table by calling the corresponding interface according to the user instruction. The interface includes an interface for inserting data, an interface for deleting data, an interface for adding partitions, and an interface for reducing partitions.
[0022] According to a second aspect of the present invention, a hash partition table management system based on the openGauss database is provided. The system includes a partition table management server, which comprises:
[0023] An initialization module is configured to initialize the hash partition table by constructing a relationship between an initial partition number n and a power order m.
[0024] A data insertion or deletion module is configured to calculate a target partition number v when data is inserted or deleted, and perform data insertion or deletion operation on the target partition.
[0025] A partition increase module is configured to calculate a target partition number v when data needs to be moved out during partition increase, and move data from the target partition to the increased partition.
[0026] A partition decrease module is configured to calculate a target partition number v when data needs to be moved in during partition decrease, and move data of the deleted partition to the target partition.
[0027] According to a third aspect of the present application, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to the first aspect of the present application when executing the program.
[0028] The hash partition table management method and system based on the openGauss database provided by the present application effectively solve the problems of the traditional hash partition table in dynamic expansion, performance stability, resource utilization and maintenance complexity, and significantly improve the performance, stability and scalability of the database system through the innovative linear hash partition algorithm and the optimized partition management strategy. BRIEF DESCRIPTION OF DRAWINGS
[0029] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed in the embodiments will be briefly introduced below. 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.
[0030] Figure 1 An architecture example diagram of a hash partition table management system based on the openGauss database according to an embodiment of the present application;
[0031] Figure 2 An architecture example diagram of a partition table management server of a hash partition table management system based on the openGauss database according to an embodiment of the present application;
[0032] Figure 3 A flow example diagram of a hash partition table management method based on the openGauss database according to an embodiment of the present application;
[0033] Figure 4An example diagram for inserting or deleting data according to the hash partition table management method based on the openGauss database according to the embodiment of the application;
[0034] Figure 5 An example diagram for increasing partitions according to the hash partition table management method based on the openGauss database according to the embodiment of the application;
[0035] Figure 6 An example diagram for reducing partitions according to the hash partition table management method based on the openGauss database according to the embodiment of the application;
[0036] Figure 7 A structural schematic diagram of the device provided by the application. DETAILED DESCRIPTION
[0037] The embodiments of the application will be described in detail below with reference to the accompanying drawings.
[0038] 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 based on the embodiments in the present disclosure without creative labor shall fall within the scope of protection of the present disclosure.
[0039] It should be noted that various aspects of the embodiments described below are within the scope of the appended claims. 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 present disclosure any one of the aspects described herein can be implemented independently of any other aspect and various aspects can be implemented in combination with each other. For example, features described in relation to one aspect can be combined with features described in relation to a different aspect. Like reference numerals can be used to denote like elements throughout the accompanying drawings and detailed description, and any aspect can be included in any embodiment. Any aspect can also be excluded from any embodiment.
[0040] Figure 1 An example diagram of the architecture of a hash partition table management system based on the openGauss database according to the embodiment of the application is shown in FIG. 1, which can include a partition table management server 101, a communication network 102 and / or one or more partition table management clients 103. Figure 1 As shown in FIG. 1, the system can include a partition table management server 101, a communication network 102 and / or one or more partition table management clients 103. Figure 1 For example, the system can include multiple partition table management clients 103.
[0041] The partition table management server 101 can be any appropriate server for storing information, data, programs, and / or any other suitable type of content. In some embodiments, the partition table management server 101 can perform appropriate functions. For example, in some embodiments, the partition table management server 101 can be used to: initialize a hash partition table by constructing a relationship between an initial number of partitions n and a power order m; when data is inserted or deleted, calculate a target partition number v, and perform data insertion or deletion operations on the target partition; when a partition is increased, calculate a target partition number v that needs to move out data, and move data from the target partition to the increased partition; when a partition is reduced, calculate a target partition number v that needs to move in data, and move data of the deleted partition into the target partition.
[0042] Figure 2 As shown in FIG. 1, the partition table management server according to an embodiment of the present application includes: Figure 2
[0043] An initialization module for initializing a hash partition table by constructing a relationship between an initial number of partitions n and a power order m;
[0044] A data insertion or deletion module for calculating a target partition number v when data is inserted or deleted, and performing data insertion or deletion operations on the target partition;
[0045] A partition increase module for calculating a target partition number v that needs to move out data when a partition is increased, and moving data from the target partition to the increased partition;
[0046] A partition reduction module for calculating a target partition number v that needs to move in data when a partition is reduced, and moving data of the deleted partition into the target partition.
[0047] As another example, in some embodiments, the partition table management server 101 can send the hash partition table management method based on the openGauss database to the partition table management client 103 for user use according to the request of the partition table management client 103.
[0048] As an optional example, in some embodiments, the partition table management client 103 is configured to provide a visual partition table management interface configured to receive a user selection input operation based on the openGauss database hash partition table management, and configured to, in response to the selection input operation, obtain and display a partition table management interface corresponding to an option selected by the selection input operation from the partition table management server 101, the partition table management interface at least displaying information based on the openGauss database hash partition table management and operation options for the information based on the openGauss database hash partition table management.
[0049] In some embodiments, the communication network 102 can be any suitable combination of one or more wired and / or wireless networks. For example, the communication network 102 can include any one or more of the following: the Internet, an intranet, a wide-area network (WAN), a local-area network (LAN), a wireless network, a digital subscriber line (DSL) network, a frame relay network, an asynchronous transfer mode (ATM) network, a virtual private network (VPN), and / or any other suitable communication network. The partition table management client 103 can connect to the communication network 102 through one or more communication links (e.g., communication link 104), which can link to the partition table management server 101 via one or more communication links (e.g., communication link 105). The communication links can be any communication links suitable for communicating data among the partition table management client 103 and the partition table management server 101, such as network links, dial-up links, wireless links, hard-wired links, any other suitable communication links, or any suitable combination of such links.
[0050] The partition table management client 103 can include any one or more clients that present interfaces related to the openGauss database hash partition table management in a suitable form for use and operation by a user. In some embodiments, the partition table management client 103 can include any suitable type of device. For example, in some embodiments, the partition table management client 103 can include a mobile device, a tablet computer, a laptop computer, a desktop computer, and / or any other suitable type of client device.
[0051] Although the partition table management server 101 is illustrated as one device, in some embodiments, any suitable number of devices can be used to perform the functions performed by the partition table management server 101. For example, in some embodiments, multiple devices can be used to implement the functions performed by the partition table management server 101. Alternatively, cloud services can be used to implement the functions of the partition table management server 101.
[0052] Based on the above system, the embodiment of the application provides a hash partition table management method based on an openGauss database, which is described below through the following embodiment.
[0053] In the prior art, a partition table is a large table that is decomposed into multiple smaller, more manageable small tables according to a certain rule. Each partition can be independently stored and managed, but still appears as a logical table to the user. The partition table can improve query performance because the query can only scan the relevant partition instead of the entire table, and also simplifies data maintenance, for example, a certain partition can be backed up, restored or cleaned up individually without affecting other data.
[0054] A hash partition table is a technology for uniformly dispersing data to different partitions by calculating the partition corresponding to the data through a hash function, which is used to avoid data skew and hotspot problems. For a certain data, if the data is to be inserted into a hash partition table with n partitions, the algorithm first expresses the data as a hash code k in a uniform format. The ordinary hash algorithm uses k mod n to obtain the number v of the corresponding partition, and stores the data in the partition. When a certain data needs to be found, the hash code k of the data is first calculated, k mod n is used to obtain the number v of the corresponding partition, and the query is only performed in the v partition, thereby reducing the overhead. However, this hash partition algorithm is not suitable for increasing or deleting partitions, because each time the number of partitions n is increased or decreased, since the partition depends on the number of partitions n, the partition k mod n of all objects in the partition needs to be recalculated after the number of partitions n is changed, otherwise the hash partition table will be invalid.
[0055] The application designs a linear hash partition table algorithm, which uses the method of the application to partition, and only affects a single existing partition when increasing or decreasing the partition, thereby avoiding the overhead caused by the change in the number of partitions to the greatest extent. The algorithm uses the property of the modulo operation: if k mod 2 (m-1) =v, then k mod 2 m The result is v or v+2 (m-1) . This property can ensure that only the partitions with partition numbers v or v+2 (m-1) are affected before and after the number of partitions is changed. Wherein mod is the modulo operator, the symbol before is the dividend, and the symbol after is the modulus, and the operation k mod m can obtain the modulus of k divided by m.
[0056] Suppose that the value n is the number of partitions of the current hash partition table, the partition numbers are 0 to n-1, the value m is a power order number used to calculate the modulus 2 m , and the value satisfies 2 (m-1) <n≤2 m ; the value k is the hash code corresponding to the data. The integer m is used to calculate the modulus value 2 m , and this can ensure that the modulus value 2m will be multiplied by 2 or divided by 2, which changes the properties of the above-mentioned modulo operation.
[0057] In the present application, let 2 (m-1) <n≤2 m The reason is as follows:
[0058] Calculate k mod 2 m The number of partitions that can be obtained is greater than or equal to n-1, otherwise some partitions have no data stored, wasting space. Therefore, n≤2 m .
[0059] When the partition number is calculated by k mod 2 m If the partition number is greater than the current partition number n, the data will be stored in the partition number calculated by k mod 2 (m-1) The candidate partition number must be within the current maximum partition number n-1, so 2 (m -1) <n.
[0060] Figure 3 A flowchart of a hash partition table management method based on an openGauss database according to an embodiment of the present application. The hash partition table management method based on an openGauss database of the present embodiment can be executed on a partition table management server. As shown in Figure 3 The hash partition table management method based on an openGauss database includes the following steps:
[0061] First, initialize the hash partition table by constructing the relationship between the initial partition number n and the power order m. As an optional example, in the initialization of the hash partition table, each partition of the partition table is independently stored and managed, wherein the relationship between the initial partition number n and the power order m is: 2 (m-1) <n≤2 m , wherein m is the power order and n is the initial partition number.
[0062] In the present embodiment, when inserting or deleting data, the target partition number v is calculated, and the data insertion or deletion operation is performed on the target partition. It should be noted that in the present embodiment, when inserting or deleting data, the target partition number v is calculated according to the data hash code k and the power order m by modulo operation, and the data insertion or deletion operation is performed on the target partition according to the target partition number v.
[0063] Figure 4 An example diagram of inserting or deleting data according to the hash partition table management method based on an openGauss database according to an embodiment of the present application. As shown in Figure 4 As an optional example, in the present embodiment, when inserting or deleting data, the target partition number is calculated in the following manner:
[0064] The data hash code k is taken as the dividend, 2 m is taken as the modulus to perform a modulo operation, and if the modulo operation result is less than n, the modulo operation result is taken as the target partition number v.
[0065] If the operation result is greater than or equal to n, the data hash code k is taken as the dividend, 2 (m-1) is taken as the modulus to perform a modulo operation, and the modulo operation result is taken as the target partition number v.
[0066] In this embodiment, when a partition is added, the target partition number v from which data needs to be moved out is calculated, and the data is moved out from the target partition to the added partition.
[0067] For example, when the hash code corresponding to the data is k, k mod 2 m is calculated to obtain the target partition number v. If v is greater than or equal to n, there is currently no corresponding partition table, k mod 2 (m-1) is recalculated to obtain the partition number v. Finally, the data is inserted into the partition v or deleted from the partition v.
[0068] Figure 5 An example diagram of adding a partition according to the hash partition table management method based on the openGauss database according to the embodiment of the present application is shown in FIG. 1. Figure 5 As an optional example, when a partition is added, a partition is added in the partition table by initializing the database, when the number of added partitions n+1 is less than or equal to 2 m , objects in the partitions n-2 (m-1) are scanned, the target partition number v from which data needs to be moved out is recalculated according to the data hash code k of the object, the data is moved out from the target partition to the added partition, and when the partition addition fails, the data is moved out from the target partition to the partitions n-2 (m-1) . When the number of added partitions n+1 is greater than 2 m , objects in the partitions n-2 m are scanned, the target partition number v from which data needs to be moved out is recalculated according to the data hash code k of the object, the data is moved out from the target partition to the added partition, and when the partition addition fails, the data is moved out from the target partition to the partitions n-2 m .
[0069] In this embodiment, when a partition is reduced, the target partition number v to which data needs to be moved in is calculated, and the data of the deleted partition is moved into the target partition.
[0070] Figure 6 An example diagram of reducing a partition according to the hash partition table management method based on the openGauss database according to the embodiment of the present application is shown in FIG. 2. Figure 6As shown, as an optional example, in this embodiment, when the number of reduced partitions n-1 is greater than 2 (m-1) , the objects in the partition n-1 are scanned, the target partition number v from which the data needs to be moved out is recalculated according to the data hash code k of the object, and the data is moved out from the target partition to the partition n-2 (m-1) -1. When the number of reduced partitions n-1 is less than or equal to 2 (m-1) , the objects in the partition n-1 are scanned, the target partition number v from which the data needs to be moved out is recalculated according to the data hash code k of the object, and the data is moved out from the target partition to the partition n-2 (m-2) -1.
[0071] It should be noted that in this embodiment, the corresponding interface is called for hash partition table management according to the user instruction, and the interface includes an insert data interface, a delete data interface, an increase partition interface, and a reduce partition interface.
[0072] In actual application, the user uses a partition table data insertion statement to call the insert data interface, and the database receives the user data and inserts it into the corresponding partition of the hash partition table.
[0073] The user uses a partition table data deletion statement to call the delete data interface, and the database receives the characteristics of the data to be deleted by the user and finds the partition to be scanned. After scanning, the data meeting the characteristics is deleted.
[0074] The user uses a partition table partition increase statement to call the increase partition interface. First, the database initializes a new partition and adds it to the partition table; second, the database calculates the target partition number from the new partition number. Finally, the database scans the target partition, recalculates the partition number to which the data belongs, and transfers the data meeting the conditions to the new partition number. The entire process only needs to scan one target partition in the partition table.
[0075] The user uses a partition table partition reduction statement to call the reduce partition interface. First, the database calculates the target partition number from the maximum partition number, as shown in Figure 4 ; second, the database transfers all data in the partition corresponding to the maximum partition number to the target partition; and finally, the partition corresponding to the maximum partition number is deleted. The entire process only affects the deleted partition and a target partition.
[0076] In actual application, the hash partition table management method and system based on the openGauss database of the embodiment has the following beneficial technical effects:
[0077] I. Achieve efficient dynamic expansion capability, significantly improve performance stability
[0078] Using a linear hash partitioning algorithm, adding or removing partitions only affects a single existing partition, eliminating the need for a full table scan. After adding a partition, the number of partitions (n+1) is less than or equal to 2. m At that time, only partition n-2 needs to be scanned. (m-1) For objects within the partition, recalculate the partition number and distribute the objects to the new partition or the original partition; when the number of partitions is reduced, the number of partitions n-1 is greater than 2. (m-1) At that time, only objects in the deleted partition n-1 are scanned, and the objects are inserted into partition n-2. (m-1) Within -1. This partial data migration method minimizes the overhead caused by changes in the number of partitions, significantly reduces performance fluctuations during expansion and contraction, ensures the performance stability of the database during dynamic expansion, effectively avoids service interruptions and performance drops caused by expansion, and greatly improves system availability and user experience.
[0079] II. Optimize resource utilization and reduce maintenance complexity
[0080] The hash partitioning table is initialized by establishing a relationship between the initial number of partitions *n* and the power of *m*. Dynamic expansion is achieved using the characteristics of the linear hash algorithm, eliminating the need for pre-allocating large amounts of idle space. The number of partitions can be dynamically adjusted based on the actual data volume, effectively improving storage resource utilization. Simultaneously, the increased efficiency and flexibility of adding and deleting partitions significantly reduces system maintenance complexity. Administrators no longer need to repeatedly adjust parameters to balance space utilization and query performance, reducing operational workload and error probability, lowering system maintenance costs and complexity, and making database system management and maintenance more efficient and convenient.
[0081] III. Enhance data management flexibility to adapt to dynamic data changes
[0082] The hash partitioning table management method of this invention can better adapt to dynamic changes in data volume. During data insertion and deletion operations, the target partition number v is obtained by calculating the data hash code k and the power order m, and operations are performed only on the target partition, avoiding unnecessary partition scans and improving data management efficiency. Simultaneously, when partitions are added or removed, the target partition number can be flexibly calculated based on the current number of partitions and the power order, quickly completing data redistribution and migration. This allows the hash partitioning table to respond promptly to changes in data volume, maintaining a good data distribution state, avoiding data skew and hotspot issues, further improving database query performance and overall operating efficiency, and providing strong support for processing large-scale dynamic data.
[0083] IV. Improve system scalability to meet big data needs Through the progressive dynamic expansion mechanism, the number of partitions can be flexibly increased or decreased according to actual needs without reconstructing the entire partition table, thereby realizing efficient and flexible expansion of the database system. This expansion method not only applies to the current data volume and business requirements, but also continuously optimizes the partition management strategy as the data volume further grows and the business expands, further improving the performance and capacity of the system to meet the high requirements of database system scalability in the big data era.
[0084] As shown in Figure 7 The application also provides a device, including a processor 210, a communication interface 220, a memory 230 for storing a processor-executable computer program, and a communication bus 240. The processor 210, the communication interface 220, and the memory 230 can communicate with each other through the communication bus 240. The processor 210 can realize the above-mentioned hash partition table management method based on the openGauss database by running the executable computer program.
[0085] The computer program in the memory 230 can be implemented in the form of a software functional unit and sold or used as an independent product. When used, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the present 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 number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of the embodiments of the present application. The aforementioned 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 program code storage media.
[0086] The system embodiments described above are only schematic, and the units shown as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e. they can be located in one place or distributed on multiple network units. Some or all of the modules can be selected to achieve the purpose of the present embodiment based on actual needs. Those skilled in the art can understand and implement it without creative labor.
[0087] Those skilled in the art can clearly understand the implementation of the various embodiments by means of software and necessary general hardware platforms through the description of the above embodiments, and of course, the embodiments can also be implemented by hardware. Based on such understanding, the above technical solutions can be embodied in the form of a software product, and the computer software product can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of the various embodiments or some parts of the embodiments.
[0088] The above merely describes the specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person 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 hash partition table management method based on an openGauss database, characterized in that, The method comprises the following steps: The hash partition table is initialized by constructing the relationship between the initial number of partitions n and the power order m; When data is inserted or deleted, the target partition number v is calculated, and data insertion or deletion operation is performed on the target partition; When a partition is added, the target partition number v from which data needs to be removed is calculated, and the data is removed from the target partition to the added partition; When a partition is reduced, the target partition number v to which data needs to be moved is calculated, and the data of the deleted partition is moved to the target partition.
2. The openGauss database-based hash partition table management method according to claim 1, characterized in that, In initializing the hash partition table, each partition of the partition table is independently stored and managed, wherein the relationship between the initial partition quantity n and the power order m is: 2 (m-1) <n≤2 m wherein m is the power order, and n is the initial partition quantity.
3. The openGauss database-based hash partition table management method according to claim 1, characterized in that, When data is inserted or deleted, the target partition number v is calculated according to the data hash code k and the power order m through a modulo operation, and data insertion or deletion operation is performed on the target partition according to the target partition number v.
4. The openGauss database-based hash partition table management method according to claim 1, characterized in that, When data is inserted or deleted, the target partition number is calculated as follows: The data hash code k is taken as the dividend, 2 m The modulo operation is performed with k as the dividend and n as the modulus. If the modulo operation result is smaller than n, the modulo operation result is taken as the target partition number v. If the operation result is greater than or equal to n, the data hash code k is taken as the dividend, 2 (m-1) The modulus operation is performed with the modulus as the modulus, and the modulus operation result is taken as the target partition number v.
5. The openGauss database-based hash partition table management method according to claim 1, characterized in that, When the number of partitions is increased, a partition is added in the partition table by initializing the database, and when the number of partitions after the increase n+1 is less than or equal to 2 m , objects in the partition n-2 (m-1) are scanned, the target partition number v from which data needs to be moved out is recalculated according to the data hash code k of the object, the data is moved out from the target partition to the added partition, and when the partition increase fails, the data is moved out from the target partition to the partition n-2 (m-1) .
6. The openGauss database-based hash partition table management method according to claim 1, characterized in that, When the number of partitions is increased, when the number of partitions after the increase n+1 is greater than 2 m , the objects in the partition n-2 m are scanned, the target partition number v from which the data needs to be moved out is recalculated according to the data hash code k of the object, the data is moved out from the target partition to the increased partition, and when the partition increase fails, the data is moved out from the target partition to the partition n-2 m .
7. The openGauss database-based hash partition table management method according to claim 1, characterized in that, When reducing the partitions, when the number of reduced partitions n-1 is greater than 2 (m-1) , scanning the objects in the partition n-1, recalculating the target partition number v from which the data needs to be moved out according to the data hash code k of the object, and moving the data from the target partition to the partition n-2 (m-1) -1.
8. The openGauss database-based hash partition table management method according to claim 1, characterized in that, When reducing the partitions, when the number of reduced partitions n-1 is less than or equal to 2 (m-1) , scanning the objects in the partition n-1, recalculating the target partition number v from which the data needs to be moved out according to the data hash code k of the object, moving the data from the target partition to the partition n-2 (m -2) -1.
9. The openGauss database-based hash partition table management method according to claim 1, characterized in that, According to the user instruction, the corresponding interface is called to manage the hash partition table, and the interface includes an insertion data interface, a deletion data interface, an increase partition interface, and a decrease partition interface.
10. An openGauss database-based hash partition table management system, characterized in that, The system comprises a partition table management server, and the partition table management server comprises: An initialization module is configured to initialize the hash partition table by constructing the relationship between the initial number of partitions n and the power order m; A data insertion or deletion module is configured to calculate the target partition number v when data is inserted or deleted, and perform data insertion or deletion operation on the target partition; A partition increase module is configured to calculate the target partition number v from which data needs to be removed when a partition is added, and remove the data from the target partition to the added partition; A partition decrease module is configured to calculate the target partition number v to which data needs to be moved when a partition is reduced, and move the data of the deleted partition to the target partition.
Citation Information
Patent Citations
A method and device for inserting data into a specified partition of an openGauss database
CN119739720A