Method and device for quickly increasing columns on openGauss database without blocking queries

By detecting the conditions for adding new columns in the openGauss database and lowering the lock level to level 7, and using the open_tables object to capture column metadata snapshots, the problem of column addition operations blocking concurrent queries is resolved, achieving efficient concurrent column addition and query operations, and improving the database's concurrent processing capabilities and data consistency.

CN120670428APending Publication Date: 2025-09-19BEIJING VASTDATA TECH
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510843914.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-23
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

In the openGauss database, column addition operations require a level 8 lock, which blocks concurrent queries and affects the database's concurrent processing capabilities. Existing technologies have poor adaptability in concurrent query scenarios and fail to effectively address the column metadata consistency issues at different stages of query operations.

Method used

Under specific conditions, the object lock level is lowered to level 7 by detecting the options of the newly added columns, and a snapshot of the column metadata is captured using the open_tables object to ensure semantic consistency during query operations. During the planning and execution phases of the extended query, the snapshot version of the column metadata is used for expansion during the parsing process to avoid blocking of lock levels and enable concurrent execution of column addition and query.

Benefits of technology

Implement zero-blocking column addition operations in high-concurrency query scenarios, improve throughput, reduce resource consumption, ensure data consistency, comply with ACID standards, and improve database operation and maintenance efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120670428A_ABST
    Figure CN120670428A_ABST
Patent Text Reader

Abstract

The invention relates to a method and a device for quickly increasing columns on an openGauss database without blocking queries. The method comprises the following steps: detecting an option of a newly added column, and triggering a rapid column adding process when a condition is met; during the period of increasing the column operation, 7-level locks are applied to the target table and associated toast table and partition table objects, and 1-level locks are kept for concurrent query operation, so that the compatibility of lock levels is realized to avoid mutual blocking; the method comprises the following steps: freezing a column metadata snapshot during query through an opentables object, and processing column projection and condition calculation based on a snapshot version in semantic processing, planning and execution stages of query to ensure data consistency; and the planner and the executor allocate memories and parse tuples based on the snapshot version, so that memory cross-border or data dislocation caused by concurrent column change is avoided. According to the technical scheme, concurrent execution of the column operation and the query operation can be increased, the database maintenance efficiency is improved, the blocking risk is reduced, and the query consistency is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of database operation, and in particular to a method, device, and electronic device for quickly adding columns without blocking queries on an openGauss database. Background Art

[0002] During database operation, you can add columns to an existing table by executing the ALTER TABLE ... ADD COLUMN... statement.

[0003] Taking the openGauss database as an example, its column addition operation mainly adopts the following two technical paths: The first is the rewrite method, and the specific implementation process is: create a temporary table, read and insert the old table data into the temporary table, synchronously set the value of the newly added column, and finally replace the original table with the temporary table to complete the column addition; the second is the non-rewrite method, which is applicable when specific constraints are met. The system calculates the default value of the newly added column and stores it in the system table. There is no need to modify the old table data. Subsequent queries directly obtain the default value from the system table to fill the newly added column.

[0004] It's worth noting that regardless of which column addition method is used, the openGauss database applies a level 8 lock (the highest level in the database's locking mechanism) to the target table. This lock level imposes strong mutual exclusion, leading to the following issues: if there are concurrent queries against the target table, the column addition operation will be blocked; conversely, during the execution of the column addition operation, queries against the table will also be blocked, severely impacting the database's concurrent processing capabilities.

[0005] In addition, although some methods for adding columns to databases have been developed, for example, the Chinese patent application "Database Management Method, Apparatus, and Device" (CN117785842A) discloses a database management method that can effectively improve the execution speed of a database when adding columns and reduce the impact of adding columns on the database's response speed. However, this method still has certain flaws in its application. For example, it directly processes table objects without fully developing and utilizing the locking mechanism; it does not propose specific optimization measures for different query stages, and does not consider how to ensure that query operations are based on consistent column metadata during column addition, which may lead to inconsistent column metadata seen at different stages of query semantic processing; although it can improve the execution speed when adding columns, it has poor adaptability in concurrent query scenarios, and there are no targeted measures to ensure that columns can be added quickly and without blocking queries in the case of a large number of concurrent queries. Summary of the Invention

[0006] To address these issues, this application proposes a new method for quickly adding columns to the openGauss database. This method, when certain conditions are met, can efficiently add columns in scenarios with a large number of concurrent related queries, without blocking any of the concurrent related queries.

[0007] In summary, the main implementation strategies of the present invention are as follows: Detecting conditions for rapidly adding columns: Detecting the option to add columns requires that only one column be added to the end of the table, and that the default value specified when adding the column is NULL or a simple expression that can be calculated as a constant. At the same time, the type of the newly added column does not trigger the rewrite mode.

[0008] Lower the object lock level during column addition: When adding a column, a level 7 lock is applied to the table object and related toast tables, partition tables, etc. Because queries use level 1 locks, level 7 locks and level 1 locks do not block each other, enabling concurrent execution of queries and column addition operations.

[0009] Expanding the query semantic processing phase: Because adding columns and querying no longer block each other, column additions can occur at any stage of query semantic processing. The latest table column metadata must be obtained when the table is first opened. Subsequent parsing of expressions such as projection columns and conditions is based on the column metadata determined at the time of table opening.

[0010] Extending query planning and execution: Similarly, column additions may occur during query planning and execution. Therefore, optimizations should be performed during these phases to ensure that tuples are read and parsed based on the same version of column metadata throughout the process.

[0011] In order to achieve the above objectives, this application provides the following technical solutions: A first aspect of the present application provides a method for quickly adding columns in an openGauss database without blocking queries, the method comprising: S1. Check column addition conditions: Check the options of the newly added column and trigger the rapid column addition process when the following conditions are met: New columns are placed at the end of the table; The default value of the newly added column is NULL or a simple expression that can be evaluated as a constant; The data type of the newly added column will not trigger the rewrite operation of the storage engine; S2. Reduce object lock levels: During the column add operation, a level 7 lock is applied to the target table and its associated toast and partitioned table objects, while a level 1 lock is maintained for concurrent query operations. This ensures lock level compatibility and prevents mutual blocking. S3. Extended query semantic processing phase: When a table is first opened, the open_tables object is used to capture the current table's column metadata. Subsequent query projection column parsing and conditional expression calculations are based on this column metadata to ensure semantic consistency. S4. Extended query planning and execution phase: The planner estimates query costs based on the snapshot version's column statistics. When scanning physical tuples, the executor strictly parses data according to the snapshot version's column structure to avoid memory out-of-bounds or data misalignment caused by column changes.

[0012] Furthermore, the specific implementation of lowering the object lock level in step S2 of the method of the present application includes: After detecting that the newly added column meets the trigger conditions, a level 7 shared lock is applied to the table object, the built-in subsidiary tables of the partitioned table, and the partitioned objects; The database lock management mechanism ensures that level 7 locks and level 1 locks of query operations are not blocked.

[0013] Furthermore, the specific implementation of the expanded query semantic processing stage in step S3 of the present method includes: During the query semantic parsing phase, an open_tables object is created to store a snapshot of the table's column metadata. When a query involves a newly added column, if the default value of the column is not explicitly referenced, the read operation of the physical column is skipped.

[0014] Furthermore, the column metadata of the current table captured by the open_tables object in step S3 of the method of the present application is in the form of a key-value pair, where the Key is the table OID and the Value is the column metadata snapshot.

[0015] Furthermore, step S3 of the method of the present application also includes: for each table involved in the query statement, first search for the open_tables object through the table's OID; if it exists, directly obtain the saved column metadata; if it does not exist, obtain the column metadata from the metadata cache or system table, and save a snapshot to the open_tables object.

[0016] Furthermore, the specific implementation of the extended query planning and execution phase in step S4 of the present method includes: Planning phase: Lock the number of columns when allocating memory to ensure that the statistics obtained are based on the number of columns obtained when allocating memory; Execution phase: When scanning tuples, default values ​​are dynamically filled based on the column structure of the snapshot version to avoid data parsing anomalies caused by newly added columns.

[0017] A second aspect of the present application provides a device for rapidly adding columns without blocking queries on an openGauss database, the device comprising: Condition detection module: used to detect the options of the newly added columns and trigger the rapid column addition process when the conditions are met; Object lock management module: used to apply level 7 locks to the target table and its associated toast table and partition table objects during the column addition operation, while maintaining level 1 locks for concurrent query operations, achieving lock level compatibility to avoid mutual blocking; Query semantic processing extension module: This module is used to capture the column metadata of the current table through the open_tables object when the table is first opened. The projection column parsing and conditional expression calculation of subsequent queries are based on this column metadata to ensure semantic consistency. Query planning and execution extension module: Evaluates query costs based on snapshot version column statistics; when scanning physical tuples, parses data strictly according to the snapshot version column structure to avoid memory out-of-bounds or data misalignment caused by column changes.

[0018] The device implements the steps of the aforementioned method for quickly adding columns to the openGauss database when running.

[0019] Furthermore, in the device of the present application, the condition detection module detects the following conditions of the newly added column: New columns are placed at the end of the table; The default value of the newly added column is NULL or a simple expression that can be evaluated as a constant; The data type of the newly added column does not trigger the rewrite operation of the storage engine.

[0020] A third aspect of the present application provides an electronic device, comprising: a memory and a processor; Memory: used to store computer programs; Processor: used to execute the computer program to implement the steps of the aforementioned method for quickly adding columns to the openGauss database.

[0021] A fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program implements the steps of the aforementioned method for quickly adding a column to an openGauss database.

[0022] In summary, the solution of the present invention has the following advantages: (1) Efficient concurrency: Through lock downgrade and metadata version isolation, column addition operations can be performed without blocking in high-concurrency query scenarios, significantly improving throughput.

[0023] (2) Low resource consumption: Avoid rewriting all table data. Default values ​​for newly added columns are only stored in the system table. Old data is dynamically filled in, optimizing storage and I / O efficiency.

[0024] (3) Strong consistency guarantee: Snapshot-based query semantics ensure consistent data visibility, avoid dirty reads or phantom reads, and comply with ACID standards.

[0025] (4) Rapid development: Make full use of the existing lock management, column metadata management, and column addition functions of the openGauss database, and quickly add columns based on these functions.

[0026] (5) Improve database operation and maintenance efficiency: Through lightweight design, while ensuring database stability, the flexibility of table structure changes and operation and maintenance efficiency are greatly improved.

[0027] Other features and advantages of the present invention will be described in detail in the following description, or may be understood through implementation of the relevant technical solutions of this application. The objectives and other advantages of this application may be achieved through the technical features and technical means clearly indicated in the description, claims, and drawings, and may be obtained through the implementation of these technical contents. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] To more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings involved in the description of the embodiments. It should be noted that the drawings only illustrate some embodiments of the present application. Those skilled in the art can deduce other relevant drawings based on these drawings without engaging in creative work.

[0029] Figure 1 This is a flowchart of the overall implementation of the method for quickly adding columns to the openGauss database of the present invention.

[0030] Figure 2 This is a structural diagram of the device for quickly adding columns to the openGauss database according to the present invention.

[0031] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0032] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the described embodiments are only some embodiments of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0033] In this document, the term "including" and any variations thereof (such as "including," "comprising," etc.) are open-ended expressions and should be understood as meaning "including but not limited to," meaning that the listed contents are not exhaustive and may include other contents not explicitly mentioned. The term "based on" should be understood as meaning "based at least in part on," meaning that the basis or condition referred to may not be the only factor and may also involve other relevant factors. The term "one embodiment" should be understood as meaning "at least one embodiment," meaning that the described embodiment is not the only possible implementation method and that other similar embodiments may exist.

[0034] In this application, the terms "a" and "a plurality" are used to modify related elements or features in an illustrative, non-restrictive manner. Unless the context clearly indicates otherwise, "a" should be understood as meaning "at least one," and "a plurality" should be understood as meaning "at least two." Those skilled in the art should interpret these terms appropriately based on the semantics and logical relationships of the context to ensure that they encompass the possibility of "one or more."

[0035] Figure 1 The figure shows the overall implementation process of the method for quickly adding columns to the openGauss database provided by this application, including the following steps: S1. Check column addition conditions: Check the options of the newly added column and trigger the rapid column addition process when the following conditions are met: New columns are placed at the end of the table; The default value of the newly added column is NULL or a simple expression that can be evaluated as a constant; The data type of the newly added column will not trigger the rewrite operation of the storage engine; S2. Reduce object lock levels: During the column add operation, a level 7 lock is applied to the target table and its associated toast and partitioned table objects, while a level 1 lock is maintained for concurrent query operations. This ensures lock level compatibility and prevents mutual blocking. S3. Extended query semantic processing phase: When a table is first opened, the open_tables object is used to capture the current table's column metadata. Subsequent query projection column parsing and conditional expression calculations are based on this column metadata to ensure semantic consistency. S4. Extended query planning and execution phase: The planner estimates query costs based on the snapshot version's column statistics. When scanning physical tuples, the executor strictly parses data according to the snapshot version's column structure to avoid memory out-of-bounds or data misalignment caused by column changes.

[0036] In order to more clearly illustrate the technical solution of the present application, the following will further illustrate it through embodiments of specific scenarios.

[0037] This invention expands and modifies the query semantic processing, planning, and execution modules of the openGauss database, as well as the module for adding columns, to implement the plan binding function through the following steps: 1. Expand the module that adds columns and use level 7 lock on the table object when certain conditions are met.

[0038] First, before adding a column, the options for adding the column are checked. If the following conditions are met, a level 7 lock is used: (1) Only add one column to the end of the table.

[0039] (2) When adding a column, the default value specified is NULL or a simple default value expression that can be calculated as a constant.

[0040] (3) The type of the newly added column will not trigger the rewrite method.

[0041] Secondly, when the conditions for a level 7 lock are met, the tables, built-in subsidiary table objects of the partition, partition objects, etc. involved in adding columns are also downgraded from the original level 8 lock to a level 7 lock. Since queries are level 1 locks, the level 7 lock and the level 1 lock will not block each other, thus achieving the effect of non-blocking queries and column additions.

[0042] 2. Expand the query semantic processing module to ensure that each table is based on the same version of column metadata during query execution (1) During query semantic parsing, an open_tables object is added. This object is a key-value set, where the key is the table's OID and the value is a copy of the table's column metadata.

[0043] (2) For each table involved in the query statement, when opening it for the first time, first search open_tables by the table's OID. If the table already exists in open_tables, directly obtain the column metadata stored in open_tables; if it does not exist, obtain the table's column metadata from the metadata cache or system table according to the original process and save a copy to open_tables.

[0044] (3) Since there is only one copy of column metadata for each table in open_tables, when resolving references to table columns in projection columns and conditional expressions during semantic processing, each table is parsed based on the same copy of column metadata. This prevents inconsistencies caused by seeing column metadata before and after adding columns at different stages of semantic processing for the same query.

[0045] 3. Expand the query planning and execution modules to ensure that all planning and tuple parsing using column metadata during this period are based on the same version of column metadata to allocate memory and parse tuples, avoiding memory out-of-bounds and consistency issues.

[0046] (1) The planner needs to obtain statistics for each table column to evaluate the cost of the scan operator. However, allocating memory to store table column statistics and obtaining statistics are separate steps. After the column lock is downgraded, concurrent non-blocking column addition operations may occur. If the number of columns used to obtain statistics exceeds the number of columns based on which memory was allocated, a memory out-of-bounds error may occur. This module needs to be modified to ensure that the statistics obtained are based on the number of columns obtained when memory was allocated.

[0047] (2) During execution, the scan operator scans the physical tuples of the table. At this time, the tuples need to be parsed based on the table's column metadata and saved to the corresponding memory structure. After adding a column lock downgrade, concurrent non-blocking column addition operations may occur throughout the execution, which may lead to memory out-of-bounds situations and the returned column values ​​exceeding the number of columns required by the operator. The execution-related logic is modified to allocate memory structures to store tuple parsing structures and parse tuples based on the same column metadata.

[0048] Specific implementation example: 1> Users can quickly add columns when executing queries Assume there is a table table1(c1 int, c2 int) Session 1: Begin; Select * from table1; Session 2: Alter table table1 add column c3 int default 123; Before the current solution was implemented, session 2's operations would be blocked by session 1. After this solution is implemented, session 1 no longer blocks session 2. 2> The user can execute the query normally while executing the rapid increase column Assume there is a table table1(c1 int, c2 int) Session 1: Begin; Select * from table1; Session 2: Alter table table1 add column c3 int default 123; Before the current solution was implemented, the operations of session 2 would be blocked by session 1. After this solution is implemented, session 1 no longer blocks session 2.

[0049] Figure 2 The present application provides a method for rapidly adding columns to an openGauss database, the method comprising: Condition detection module: used to detect the options of the newly added columns and trigger the rapid column addition process when the conditions are met; Object lock management module: used to apply level 7 locks to the target table and its associated toast table and partition table objects during the column addition operation, while maintaining level 1 locks for concurrent query operations, achieving lock level compatibility to avoid mutual blocking; Query semantic processing extension module: This module is used to capture the column metadata of the current table through the open_tables object when the table is first opened. The projection column parsing and conditional expression calculation of subsequent queries are based on this column metadata to ensure semantic consistency. Query planning and execution extension module: Evaluates query costs based on snapshot version column statistics; when scanning physical tuples, parses data strictly according to the snapshot version column structure to avoid memory out-of-bounds or data misalignment caused by column changes.

[0050] When the above device is running, the steps of the method for quickly adding columns to the openGauss database disclosed in this application are implemented.

[0051] The flowcharts and block diagrams in the accompanying drawings illustrate possible implementations of the apparatus, methods, and computer program products according to various embodiments of the present application, including architecture, functions, and operations. In these figures, each box may represent a module, a program segment, or a portion of a code, which contains one or more executable instructions for implementing a specified logical function. It should be noted that each box in the block diagram and / or flowchart, and the combination of these boxes, can be implemented using a dedicated hardware-based system to implement the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.

[0052] like Figure 3 As shown, an embodiment of the present application further discloses an electronic device, comprising: a processor 310, a communication interface 320, a memory 330 for storing a computer program executable by the processor, and a communication bus 340. The processor 310, the communication interface 320, and the memory 330 communicate with each other via the communication bus 340. The processor 310 executes the executable computer program to implement the steps of the above-mentioned method for rapidly adding a column to the openGauss database.

[0053] It is understood that, in addition to the memory and processor, the electronic device may also include an input device (e.g., a keyboard), an output device (e.g., a display), and other communication modules. These input devices, output devices, and other communication modules all communicate with the processor via an I / O interface (i.e., an input / output interface).

[0054] The operation of the present application can be implemented by writing computer program code using one or more programming languages ​​or a combination thereof. The programming languages ​​include but are not limited to the following types: Object-oriented programming languages, such as Java, Smalltalk, C++, etc.; A conventional procedural programming language, such as "C" or a similar programming language.

[0055] The execution methods of the program code include but are not limited to: Executes entirely on the user's computer; Partially executed on the user's computer and partially on a remote computer; Executed as a standalone software package; Executes entirely on the remote computer or server.

[0056] In scenarios involving a remote computer, the remote computer can be connected to the user's computer via any type of network, including but not limited to a local area network (LAN) or a wide area network (WAN). Additionally, the remote computer can be connected to an external computer via an Internet service provider, such as the Internet.

[0057] Furthermore, the present application also discloses a computer-readable storage medium. When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device can perform the various steps of the method for quickly adding columns to an openGauss database disclosed in the present application.

[0058] In the context of this application, computer-readable storage media refers to tangible media that can store computer program code and related data. Specific examples include, but are not limited to, the following: (1) Portable computer disk: A removable magnetic storage medium such as a floppy disk.

[0059] (2) Hard disk: includes fixed storage devices such as mechanical hard disks and solid-state hard disks.

[0060] (3) Random Access Memory (RAM): Volatile storage medium used for temporary storage of data and program code.

[0061] (4) Read-only memory (ROM): A non-volatile storage medium used to store fixed programs and data.

[0062] (5) Erasable Programmable Read-Only Memory (EPROM) or Flash Memory: A non-volatile storage medium that supports multiple erasing and programming.

[0063] (6) Fiber optic storage device: storage medium based on fiber optic technology.

[0064] (7) Compact Disc Read-Only Memory (CD-ROM): A read-only medium that stores data in the form of an optical disc.

[0065] (8) Optical storage devices: storage media based on optical principles, such as DVDs and Blu-ray discs.

[0066] (9) Magnetic storage devices: storage media based on magnetic principles, such as magnetic tapes and disks.

[0067] (10) Any suitable combination of the above: for example, combining multiple storage media to meet different storage requirements.

[0068] These computer-readable storage media can be used to store the program code and related data described in this application to support the operation of the program and the persistent storage of data.

[0069] In particular, according to embodiments of the present application, the processes described in the flowcharts can be implemented as computer software programs. For example, embodiments of the present application relate to a computer program product comprising a computer program carried on a non-transitory computer-readable medium. The computer program includes program code for executing the method disclosed in the present application for rapidly adding columns to an openGauss database. When the computer program is executed by a processing device, the above-described functions defined in the embodiments of the present application can be implemented.

[0070] Although the above discussion contains several specific implementation details, these details should not be interpreted as limiting the scope of this application. The above description is only a preferred embodiment of the present application and an illustration of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in this application is not limited to the technical solutions formed by the specific combination of the above technical features. At the same time, this application should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concepts.

[0071] Those skilled in the art should also understand that they may modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein with equivalents, without departing from the spirit and scope of the technical solutions of the embodiments of the present application. Such modifications or replacements will not cause the essence of the corresponding technical solutions to deviate from the core spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for quickly adding columns in an openGauss database without blocking queries, characterized in that: The method comprises: S1. Check column addition conditions: Check the options of the newly added column and trigger the rapid column addition process when the following conditions are met: New columns are placed at the end of the table; The default value of the newly added column is NULL or a simple expression that can be evaluated as a constant; The data type of the newly added column will not trigger the rewrite operation of the storage engine; S2. Reduce object lock levels: During the column add operation, a level 7 lock is applied to the target table and its associated toast and partitioned table objects, while a level 1 lock is maintained for concurrent query operations. This ensures lock level compatibility and prevents mutual blocking. S3. Extended query semantic processing phase: When a table is first opened, the open_tables object is used to capture the current table's column metadata. Subsequent query projection column parsing and conditional expression calculations are based on this column metadata to ensure semantic consistency. S4. Extended query planning and execution phase: The planner estimates query costs based on the snapshot version's column statistics. When scanning physical tuples, the executor strictly parses data according to the snapshot version's column structure to avoid memory out-of-bounds or data misalignment caused by column changes.

2. The method according to claim 1, characterized in that The specific implementation of lowering the object lock level in step S2 includes: After detecting that the newly added column meets the trigger conditions, a level 7 shared lock is applied to the table object, the built-in subsidiary tables of the partitioned table, and the partitioned objects; The database lock management mechanism ensures that level 7 locks and level 1 locks of query operations are not blocked.

3. The method according to claim 1, characterized in that The specific implementation of the extended query semantic processing phase in step S3 includes: During the query semantic parsing phase, an open_tables object is created to store a snapshot of the table's column metadata. When a query involves a newly added column, if the default value of the column is not explicitly referenced, the read operation of the physical column is skipped.

4. The method according to claim 1, wherein The column metadata of the current table captured by the open_tables object in step S3 is in the form of key-value pairs, where the Key is the table OID and the Value is the column metadata snapshot.

5. The method according to claim 4, characterized in that Step S3 also includes: for each table involved in the query statement, first search for the open_tables object by the table's OID; if it exists, directly obtain the saved column metadata; if it does not exist, obtain the column metadata from the metadata cache or system table and save a snapshot to the open_tables object.

6. The method according to claim 1, characterized in that The specific implementation of the extended query planning and execution phase in step S4 includes: Planning phase: Lock the number of columns when allocating memory to ensure that the statistics obtained are based on the number of columns obtained when allocating memory; Execution phase: When scanning tuples, default values ​​are dynamically filled based on the column structure of the snapshot version to avoid data parsing anomalies caused by newly added columns.

7. A device for rapidly adding columns without blocking queries on an openGauss database, characterized in that: The device comprises: Condition detection module: used to detect the options of the newly added columns and trigger the rapid column addition process when the conditions are met; Object lock management module: used to apply level 7 locks to the target table and its associated toast table and partition table objects during the column addition operation, while maintaining level 1 locks for concurrent query operations, achieving lock level compatibility to avoid mutual blocking; Query semantic processing extension module: This module is used to capture the column metadata of the current table through the open_tables object when the table is first opened. The projection column parsing and conditional expression calculation of subsequent queries are based on this column metadata to ensure semantic consistency. Query planning and execution extension module: Evaluates query costs based on snapshot version column statistics; when scanning physical tuples, parses data strictly according to the snapshot version column structure to avoid memory out-of-bounds or data misalignment caused by column changes.

8. The device according to claim 7, characterized in that The condition detection module detects the following conditions of the newly added columns: New columns are placed at the end of the table; The default value of the newly added column is NULL or a simple expression that can be evaluated as a constant; The data type of the newly added column does not trigger the rewrite operation of the storage engine.

9. An electronic device, characterized in that: include: memory and processor; Memory: used to store computer programs; Processor: configured to execute the computer program to implement the steps of the method for quickly adding a column without blocking queries on an openGauss database as described in any one of claims 1 to 6.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for quickly adding a column without blocking queries on an openGauss database are implemented as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Database management method, device and equipment

    CN117785842A

  • Method and system for creating local partition index on line under Opengauss platform

    CN114661718A

  • Distributed database processing method and device, electronic equipment and readable medium

    CN116204330A

  • Hybrid distributed graph data storage and calculation method

    CN117112692A

  • Data processing method and device

    CN118210829A