Database table structure modification method and device, electronic device and storage medium
By building a target data table containing the original basic data and incremental data, and adding locks when appropriate, the problem of read and write operations mutually exclusive when database structure modification is solved, high availability and data consistency of the database are achieved, and performance jitter is reduced.
Patent Information
- Application Number
- CN202411783770.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2044-12-06
AI Technical Summary
When existing database systems modify the database structure, read and write operations are mutually exclusive, resulting in the inability to perform structural modifications during peak periods or large business volumes, affecting the availability of the database and the consistency of data.
By constructing the first target data table, including the basic data of the original database table before modification and the incremental data generated during the modification process, and adding a lock when it detects that the read operation or the amount of data reaches a preset value, ensure that the modification process of the metadata is completed at the millisecond or second level.
It realizes that read and write operations can continue when the database structure is modified, ensuring the availability of the database and data consistency, and reducing performance jitter caused by online modification of the database table structure.
Smart Images

Figure CN119248808B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for modifying a database table structure, an electronic device and a storage medium. Background Art
[0002] In many database systems, the modification of database structure and the read and write operations of the database are mutually exclusive, and after the database structure is modified, all old data must be migrated to the new structure, which causes a lot of performance consumption for a period of time. Therefore, most database system administrators can only modify the database structure at night or when the business volume is very small.
[0003] Therefore, a method is needed to ensure that the read and write operations of the database can continue when the database structure is modified, so as to ensure both the availability of the database and the consistency of the data. Summary of the invention
[0004] In view of the above problems, the present invention provides a method and device for modifying a database table structure, an electronic device and a storage medium.
[0005] According to a first aspect of the present invention, there is provided a method for modifying a database table structure, comprising: in response to a modification instruction for an original database table structure, constructing a first target data table according to a first data group and a second data group, the first data group comprising basic data in the original database table before modification, and the second data group comprising incremental data generated in the original database table during the modification process, wherein the first target data table and the original database table have different table structures; in case a read operation on the first target data table is detected, adding a first lock to the first target data table, and / or in case the amount of data in the second data group satisfies a preset numerical condition, adding a second lock to the first target data table; and modifying metadata in the first target data table to which the first lock and / or the second lock are added to obtain a second target data table.
[0006] Optionally, the first target data table includes a first lock, a second lock and multiple other locks except the first lock and the second lock; the first lock and the second lock are mutually exclusive, and the first lock and the other multiple locks coexist; the second lock and the first lock and the other multiple locks are mutually exclusive.
[0007] Optionally, the first lock is a multi-version shared lock, and the second lock is a multi-version exclusive lock.
[0008] Optionally, the first data group includes pre-image data of basic data in the original database table, and the pre-image data is generated in response to an operation of modifying the structure of the original database table.
[0009] Optionally, constructing a first target data table based on the first data group and the second data group includes: constructing a third target data table having a table structure different from that of the original database table according to a modification target preset by the user, wherein the third target data table does not have any data rows; constructing a basic target data table based on the first data group and the third target data table; and constructing a first target data table based on the basic target data table according to the second data group and the corresponding incremental data operation log.
[0010] Optionally, the preset numerical condition includes that the number of corresponding incremental data operation logs is less than or equal to 5.
[0011] A second aspect of the present invention provides a database table structure modification device, comprising: a construction module, for responding to a modification instruction for an original database table structure, and constructing a first target data table according to a first data group and a second data group, the first data group including basic data in the original database table before modification, and the second data group including incremental data generated in the original database table during the modification process, wherein the table structures of the first target data table and the original database table are different; a locking module, for adding a first lock to the first target data table when a read operation on the first target data table is detected, and / or adding a second lock to the first target data table when the data volume of the second data group meets a preset numerical condition; a modification module, for modifying metadata in the first target data table to which the first lock and / or the second lock are added, to obtain a second target data table.
[0012] A third aspect of the present invention provides an electronic device, comprising: one or more processors; a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the above method.
[0013] The fourth aspect of the present invention further provides a computer-readable storage medium on which a computer program or instruction is stored, and the steps of the above method are implemented when the above computer program or instruction is executed by a processor.
[0014] The fifth aspect of the present invention also provides a computer program product, including a computer program or instructions, which implement the steps of the above method when executed by a processor.
[0015] The present invention can prevent data inconsistency from occurring during data migration and modification by adding a first lock and a second lock on the first target data table, thereby ensuring data integrity and accuracy. By presetting numerical conditions to determine when to add the second lock, that is, when to start modifying the metadata, it can be flexibly adjusted according to the system load and performance requirements to adapt to different workloads, while controlling the entire metadata modification process at the millisecond or second level, thereby reducing database performance jitter caused by online modification of the database table structure. When the database structure is modified to the last step, the newly added lock type is used to monopolize the metadata information until the database structure operation transaction is committed, thereby ensuring the consistency of data reading. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above contents and other objects, features and advantages of the present invention will become more apparent through the following description of embodiments of the present invention with reference to the accompanying drawings.
[0017] Figure 1 An application scenario diagram of a method for modifying a database table structure according to an embodiment of the present invention is shown.
[0018] Figure 2 A flow chart of a method for modifying a database table structure according to an embodiment of the present invention is shown.
[0019] Figure 3 A flowchart of a method for constructing a first target data table according to an embodiment of the present invention is shown.
[0020] Figure 4 A structural block diagram of a database table structure modification device according to an embodiment of the present invention is shown.
[0021] Figure 5 A block diagram of an electronic device suitable for implementing a method for modifying a database table structure according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0022] Below, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of embodiments of the present invention. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of concepts of the present invention.
[0023] The terms used herein are only for describing specific embodiments and are not intended to limit the present invention. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0024] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0025] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0026] In the concept of implementing the present invention, when modifying the database structure, the problems that need to be solved include that the database read and write operations can also continue when modifying the database structure, which must ensure both the availability of the database and the consistency of the data. In the implementation process, the main difficulties faced are several important scenarios: First, after the operation of modifying the database structure begins, concurrent write operations on database objects are still ongoing and will continue to generate incremental data. If the traditional exclusive lock method is used, the concurrent performance of the database and the normal use of the business will be greatly blocked; second, at the end of the database structure modification process, the metadata information needs to be modified and the query plan method needs to be modified synchronously, but the database object version is read in a way that does not add lock queries, so the consistency of metadata information queries cannot be guaranteed; third, modifying the database structure requires upgrading and migrating the data, which consumes a lot of system resources.
[0027] Figure 1 An exemplary application scenario 100 to which the method for modifying the database table structure according to an embodiment of the present invention can be applied is shown. It should be noted that: Figure 1 The examples shown are merely examples of application scenarios to which the embodiments of the present invention can be applied, to help those skilled in the art understand the technical content of the present invention, but do not mean that the embodiments of the present invention cannot be used in other devices, systems, environments or scenarios.
[0028] like Figure 1 As shown, the application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is used to provide a medium for a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, the network 104, and the server 105. The network 104 may include various connection types, such as wired and / or wireless communication links, etc.
[0029] The user may use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications may be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, and / or social platform software, etc. (only for example).
[0030] The first terminal device 101, the second terminal device 102, and the third terminal device 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0031] The server 105 may be a server that provides various services, such as a background management server (only as an example) that provides support for websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0032] It should be noted that the database table structure modification method provided in the embodiment of the present invention can generally be executed by the server 105. Accordingly, the database table structure modification device provided in the embodiment of the present invention can generally be set in the server 105. The database table structure modification method provided in the embodiment of the present invention can also be executed by a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105. Correspondingly, the database table structure modification device provided in the embodiment of the present invention can also be set in a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105.
[0033] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.
[0034] The following will be based on Figure 1 The scene described by Figure 2~Figure 5 The method for modifying the database table structure of the disclosed embodiment is described in detail.
[0035] Figure 2 A flow chart of a method for modifying a database table structure according to an embodiment of the present invention is shown.
[0036] like Figure 2 As shown, the method includes operations S201 to S203.
[0037] In operation S201, in response to an instruction to modify the structure of an original database table, a first target data table is constructed based on a first data group and a second data group, wherein the first data group includes basic data in the original database table before the modification, and the second data group includes incremental data generated in the original database table during the modification process, wherein the first target data table and the original database table have different table structures.
[0038] According to an embodiment of the present invention, the original database table structure refers to a table in the database that already exists before any modification is made, and the table contains the data structure and data that need to be modified or expanded. The modification instruction refers to a series of operation commands for changing the original database table structure, such as adding, deleting or modifying columns or fields, changing data types, adding or deleting indexes, etc. The first data group refers to all the data that already exists in the original database table before the table structure is modified. These data are basic data and will be used to build a new target data table. The second data group refers to the new data generated during the table structure modification process. These data may be generated by the insertion of new data, the update or deletion of existing data, or the incremental data generated by the user's operation on the database during the construction of the new table in the first data group, that is, the second data group contains all the incremental changes made to the original database table during the modification process. The first target data table is a new table created according to the table structure modification instruction, and its structure is different from the original database table. This new table will contain the modified data structure and is used to store the data of the first data group and the second data group. For example, the first target data table has three more columns than the original database table structure, that is, there has been a change in the database table structure, that is, the table structure has been modified; or the first target data table is different from the original database table in terms of columns or fields, data types, indexes, constraints, etc., and the structure can be adjusted according to the actual needs of the user, such as changes in business needs, performance optimization or other factors.
[0039] According to an embodiment of the present invention, when an instruction to modify the table structure of a data table is received, a first target data table is constructed based on a data table with different structures preset by a user and a first data group and a second data group. For example, a database structure storage shard is added to store data of the first target data table, and then the first data group and the second data group are used to construct corresponding data shards of the first target data table in the form of data pages.
[0040] In operation S202, when a read operation on the first target data table is detected, a first lock is added to the first target data table, and / or when the data volume of the second data group meets a preset numerical condition, a second lock is added to the first target data table.
[0041] According to an embodiment of the present invention, a read operation refers to an act of querying or retrieving data, which allows a user to view the data in a table but not to modify it. When a read operation on the first target data table is detected, the database will add a lock to manage concurrent access. The first lock is a lock that allows multiple transactions to read data simultaneously but does not allow modification of data. When a read operation occurs, the first lock is added to the first target data table to ensure that the data is not modified by other transactions when it is read. The second lock is a lock that prevents other transactions from reading or modifying data. When the amount of data in the second data group meets a preset numerical condition, a second lock is added to the first target data table to ensure data consistency and integrity. The preset numerical condition is a threshold set by the database administrator to determine when to apply the second lock. For example, when a threshold is reached during the processing of the second data group, i.e., incremental data, a second lock is added to the first target data table.
[0042] According to an embodiment of the present invention, the first lock is added only when a read operation is detected. Assuming that no user has performed a read operation on the database during the entire online modification of the data table structure, there will be no first lock added from beginning to end.
[0043] In operation S203, metadata in the first target data table to which the first lock and / or the second lock is added is modified to obtain a second target data table.
[0044] According to an embodiment of the present invention, metadata refers to information about the content, structure, source and other characteristics of data. In a database table, metadata may include column names, data types, constraints, etc., and modification of metadata may involve changing these attributes or definitions. The second target data table refers to a data table that has been modified with metadata based on the first target data table. It is also the target database table after the user performs online modification of the database table structure. It has a different structure and corresponding metadata from the metadata table.
[0045] In some specific embodiments of the present invention, the first lock responds to the user's read operation on the data in the data table, and the second lock is a necessary condition in the stage of modifying the metadata, which can be understood as adding the second lock before modifying the metadata, or the metadata of the first target data table will not be modified without the second lock. Further, during the operation of modifying the metadata, the database table must have the second lock, and the existence of the first lock does not affect the metadata modification operation.
[0046] In some specific embodiments of the present invention, after obtaining the second target data table, it also includes a release operation on the second lock and a new target access path generated based on the second target data table to update an operation execution plan for the data in the second target data table. The operation execution plan refers to the method used by the database to read database object information, such as full table scan, index scan, etc. Updating the database object may change the execution plan of the database read operation.
[0047] Furthermore, it also includes modifying the corresponding data page to adapt to the modified metadata when the metadata is modified. When the metadata information is determined to have changed during the update operation of the database object, the data object that needs to be updated is upgraded to the latest database object structure. In the prior art, after the metadata is changed, the database object (usually the user table) will be exclusively locked, and then the entire table data will be upgraded and migrated to the new storage space. Although the metadata information of the present invention is changed, as long as the table data object is not changed, the old data will be not changed as much as possible. Only when the old data object is updated, the old data object is updated to the data object of the latest version of the database structure, so as to minimize the performance jitter caused by the database structure modification operation.
[0048] According to an embodiment of the present invention, by adding a first lock and a second lock on the first target data table, data inconsistency can be prevented during data migration and modification, thereby ensuring data integrity and accuracy. By presetting numerical conditions to determine when to add the second lock, that is, when to start modifying the metadata, it can be flexibly adjusted according to the system load and performance requirements to adapt to different workloads, while controlling the entire metadata modification process at the millisecond or second level, thereby reducing database performance jitter caused by online modification of the database table structure. When the database structure is modified to the last step, the newly added lock type is used to monopolize the metadata information until the database structure operation transaction is committed, thereby ensuring the consistency of data reading.
[0049] According to an embodiment of the present invention, the first target data table includes a first lock, a second lock and multiple other locks except the first lock and the second lock; the first lock and the second lock are mutually exclusive, and the first lock coexists with the other multiple locks; the second lock and the first lock and the other multiple locks are mutually exclusive.
[0050] According to an embodiment of the present invention, multiple locks other than the first lock and the second lock refer to locks on the data table caused by other user operations, which may or may not exist during the modification of the data table. The mutual exclusivity of the first lock and the second lock can control concurrent access to the first target data table. The first lock can be shared with other locks of other operations. The first lock is added when a read operation is detected to ensure that the data will not be modified at the same time when reading the data. However, the addition of the second lock means that metadata modification is required. At this time, no read, write, etc. operations are allowed to protect metadata information to avoid version reading problems. In addition, the lock strategy can reduce the risk of deadlock. Since the first lock is only mutually exclusive with the second lock, this hierarchical structure of the lock can avoid circular waiting that may be caused by multi-granularity lock operations, thereby reducing the probability of deadlock.
[0051] According to an embodiment of the present invention, the first lock is a multi-version shared lock, and the second lock is a multi-version exclusive lock.
[0052] According to an embodiment of the present invention, the first lock is a multi-version shared lock (MS), and the second lock is a multi-version exclusive lock (MX). The MS lock allows version read operations to be performed in parallel with other read and write operations. The MS lock is compatible with multiple locks, such as intention shared locks (IS), intention exclusive locks (IX), shared locks (S), and exclusive locks (X). This means that without modifying the database structure, the version read operation can be performed in parallel with other transactions, thereby improving the concurrency performance of the database. Only mutual exclusion with the MX lock ensures that all locks are blocked before the metadata is modified to avoid data inconsistency.
[0053] According to an embodiment of the present invention, the first data group includes pre-image data of basic data in the original database table, and the generation of the pre-image data is in response to an operation of modifying the structure of the original database table.
[0054] According to an embodiment of the present invention, the before-image data refers to a snapshot or copy of the data that the system will save before performing a data modification operation. The before-image of this data is used to restore the data to the state before the modification when the transaction fails or needs to be rolled back, thereby ensuring the atomicity and consistency of the transaction. The first data group includes the before-image data of the data in the original database table. When calling the first data group to build a first target data table with a new structure, if the corresponding data has before-image data, then the before-image data will be called. The generation of the before-image data is related to the instruction to modify the database table structure. According to the modification instruction, it is determined which basic data will change or be affected, and then the before-image data page of this data page will be generated. If there is no change or impact, then the before-image data will not be generated, that is, there is no need to generate the before-image pages of all data pages of the entire data table.
[0055] In some specific embodiments of the present invention, when the write operation of the database object detects that an online modification of the database structure is in progress, a temporary data shard will be temporarily opened to store the previous image data. The write operation will generate the previous image data page of the data page affected by the online modification of the database structure operation and save it in the temporary data shard. When building the first target data table, all database object data will be scanned to build the corresponding storage shard of the first target data table. During the scanning process, if the data page has a previous image saved in the temporary data shard, the data page in the temporary data shard will be used to build the newly added database structure, otherwise, the unchanged data page shard will be used to build it.
[0056] For example, the original database table has data page 1, data page 2, and data page 3. According to the modification instruction, the online modification of the table structure will only affect the data of data page 2. Then the previous image data page of data page 2, i.e., data page 2', will be generated and stored in the temporary data shard created temporarily. At this time, the first data group will consist of data page 1, data page 2', and data page 3.
[0057] According to the embodiments of the present invention, the pre-image data and incremental data ensure that the data generated during the entire database structure modification process will not be lost and will not affect the normal use of the database business. If an error occurs during the modification process, the data can also be rolled back. In addition, the pre-image data is generated only for the data that affects the modified structure, while the original data will be used for the data that has no impact or no change, which can avoid excessive system pressure caused by a large amount of pre-image data.
[0058] Figure 3 A flowchart of a method for constructing a first target data table according to an embodiment of the present invention is shown.
[0059] like Figure 3 As shown, constructing a first target data table according to the first data group and the second data group includes operations S301 to S303.
[0060] Operation S301 : constructing a third target data table having a table structure different from that of the original database table according to a modification target preset by a user, wherein the third target data table does not have any data row.
[0061] Operation S302: construct a basic target data table according to the first data group and the third target data table.
[0062] Operation S303: construct a first target data table based on the basic target data table according to the second data group and the corresponding incremental data operation log.
[0063] In operation S301, the modification target preset by the user is what modification the user wants to make to the original database table structure, such as adding a new column, deleting an existing column, modifying the data type of a column, changing the index of the table, etc. The third target data table is a new data table with a structure different from the original database table, which is constructed according to the user's modification requirements and is an empty table with a specific structure but without any data. Furthermore, corresponding data storage shards can be opened accordingly.
[0064] In operation S302, after the third target data table is constructed, the basic data in the original database table is first imported, that is, the basic target data table is constructed through the first data group. For example, the first data group is called or copied in the form of a data page to the storage slice corresponding to the third target data table, thereby realizing the construction of the basic target data table.
[0065] In operation S303, the incremental data in the second data group will generate incremental data operation logs during the modification process, and the incremental data operation logs record the specific operations of these data changes. A temporary shard of incremental data can be opened to store incremental data and its corresponding incremental data operation log. Among them, the incremental data and the corresponding incremental data operation log in the temporary shard of incremental data are added and updated in real time according to the actual user's operation. In the process of constructing the first target data table for the second data group, the data page will be constructed according to the incremental data operation log, or it can be understood as a modification of the data in the basic target data table constructed by the first data group, so as to obtain the first target data table.
[0066] According to an embodiment of the present invention, an empty third target data table is first created, then a basic target data table is constructed based on the first data group, and finally a first target data table is constructed based on the second data group and the incremental data operation log. The first target data table is constructed in stages, which can make the data migration process more orderly and efficient. By creating an empty third target data table and gradually introducing data, the integrity and consistency of the data can be better controlled, especially in a multi-step data migration process.
[0067] According to an embodiment of the present invention, the preset numerical condition includes that the number of corresponding incremental data operation logs is less than or equal to 5.
[0068] According to an embodiment of the present invention, during operation S303 to construct the first target data table, since users may continuously operate on the database, incremental data is continuously generated, but the incremental data is also consumed at the same time, and the consumption rate is generally much faster than the rate at which the incremental data is generated. When it is monitored that the incremental data operation logs are less than or equal to 5, a second lock will be added to the first target data table for subsequent metadata modification operations.
[0069] According to an embodiment of the present invention, when the number of incremental data operation logs is small, the modification operations on the first target data table are also relatively small. At this time, adding a second lock can quickly complete the metadata modification, reduce the transaction execution time, and improve the overall transaction processing efficiency. The entire metadata modification operation is at the millisecond level, which can greatly reduce the system jitter caused by the modification of the database table structure.
[0070] Based on the above database table structure modification method, the present invention also provides a database table structure modification device. Figure 4 The device is described in detail.
[0071] Figure 4 A structural block diagram of a database table structure modification device according to an embodiment of the present invention is shown.
[0072] like Figure 4 As shown, the database table structure modification device 400 of this embodiment includes a construction module 410 , a locking module 420 and a modification module 430 .
[0073] The construction module 410 is used to respond to the modification instruction of the original database table structure and construct a first target data table according to the first data group and the second data group, wherein the first data group includes the basic data in the original database table before the modification, and the second data group includes the incremental data generated in the original database table during the modification process, wherein the table structures of the first target data table and the original database table are different. In one embodiment, the construction module 410 can be used to perform the operation S201 described above, which will not be described in detail here.
[0074] The locking module 420 is used to add a first lock to the first target data table when a read operation on the first target data table is detected, and / or to add a second lock to the first target data table when the amount of data in the second data group meets a preset numerical condition. In one embodiment, the locking module 420 can be used to perform the operation S202 described above, which will not be described in detail here.
[0075] The modification module 430 is used to modify the metadata in the first target data table to which the first lock and / or the second lock are added to obtain the second target data table. In one embodiment, the modification module 430 can be used to perform the operation S203 described above, which will not be described in detail here.
[0076] According to an embodiment of the present invention, by adding a first lock and a second lock on the first target data table, data inconsistency can be prevented during data migration and modification, ensuring data integrity and accuracy. By presetting numerical conditions to determine when to add the second lock, that is, when to start modifying the metadata, it can be flexibly adjusted according to the system load and performance requirements to adapt to different workloads, while controlling the entire metadata modification process at the millisecond or second level, reducing database performance jitter caused by online modification of the database table structure. When the database structure is modified to the last step, the newly added lock type is used to exclusively control the metadata information until the database structure operation transaction is committed, ensuring the consistency of data reading.
[0077] According to an embodiment of the present invention, any multiple modules of the construction module 410, the locking module 420 and the modification module 430 can be combined into one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present invention, at least one of the construction module 410, the locking module 420 and the modification module 430 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in any appropriate combination of any of them. Alternatively, at least one of the construction module 410, the locking module 420 and the modification module 430 can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding function can be executed.
[0078] Figure 5 A block diagram of an electronic device suitable for implementing a method for modifying a database table structure according to an embodiment of the present invention is shown.
[0079] Figure 5 A block diagram of an electronic device suitable for implementing the method described above according to an embodiment of the present invention is shown. Figure 5 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0080] like Figure 5As shown, the electronic device 500 according to an embodiment of the present invention includes a processor 501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 502 or the program loaded from the storage part 508 to the random access memory (RAM) 503. The processor 501 may include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (for example, an application-specific integrated circuit (ASIC)), etc. The processor 501 may also include an onboard memory for caching purposes. The processor 501 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.
[0081] In RAM 503, various programs and data required for the operation of electronic device 500 are stored. Processor 501, ROM 502 and RAM 503 are connected to each other via bus 504. Processor 501 performs various operations of the method flow according to the embodiment of the present invention by executing the programs in ROM 502 and / or RAM 503. It should be noted that the program can also be stored in one or more memories other than ROM 502 and RAM 503. Processor 501 can also perform various operations of the method flow according to the embodiment of the present invention by executing the programs stored in the one or more memories.
[0082] According to an embodiment of the present invention, the electronic device 500 may further include an input / output (I / O) interface 505, which is also connected to the bus 504. The electronic device 500 may further include one or more of the following components connected to the input / output (I / O) interface 505: an input portion 506 including a keyboard, a mouse, etc.; an output portion 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 508 including a hard disk, etc.; and a communication portion 509 including a network interface card such as a LAN card, a modem, etc. The communication portion 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the input / output (I / O) interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that the computer program read therefrom is installed into the storage portion 508 as needed.
[0083] According to an embodiment of the present invention, the method flow according to an embodiment of the present invention can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the processor 501, the above-mentioned functions defined in the system of the embodiment of the present invention are executed. According to an embodiment of the present invention, the system, equipment, device, module, unit, etc. described above can be implemented by a computer program module.
[0084] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiment; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present invention is implemented.
[0085] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium. For example, it may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device.
[0086] For example, according to an embodiment of the present invention, the computer-readable storage medium may include the ROM 502 and / or the RAM 503 described above and / or one or more memories other than the ROM 502 and the RAM 503 .
[0087] An embodiment of the present invention also includes a computer program product, which includes a computer program, which contains program code for executing the method provided by the embodiment of the present invention. When the computer program product is run on an electronic device, the program code is used to enable the electronic device to implement the database operation status determination method provided by the embodiment of the present invention.
[0088] When the computer program is executed by the processor 501, the above functions defined in the system / device of the embodiment of the present invention are executed. According to the embodiment of the present invention, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0089] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 509, and / or installed from the removable medium 511. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0090] According to an embodiment of the present invention, the program code for executing the computer program provided by the embodiment of the present invention can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0091] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box may also occur in an order different from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions. It can be understood by those skilled in the art that the features recorded in the various embodiments of the present invention can be combined and / or combined in various ways, even if such a combination or combination is not explicitly recorded in the present invention. In particular, without departing from the spirit and teachings of the present invention, the features recorded in the various embodiments of the present invention can be combined and / or combined in various ways. All these combinations and / or combinations fall within the scope of the present invention.
[0092] The embodiments of the present invention are described above. However, these embodiments are only for the purpose of illustration, and are not intended to limit the scope of the present invention. Although each embodiment is described above, it does not mean that the measures in each embodiment cannot be used in combination advantageously. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.
Claims
1. A method for modifying a database table structure, characterized in that: The database table structure modification method comprises: In response to an instruction to modify the structure of an original database table, a first target data table is constructed according to a first data group and a second data group, wherein the first data group includes basic data in the original database table before modification, and the second data group includes incremental data generated in the original database table during the modification process, wherein the first target data table and the original database table have different table structures; When a read operation on the first target data table is detected, a first lock is added to the first target data table, and when the amount of data of the second data group meets a preset numerical condition, a second lock is added to the first target data table; The metadata in the first target data table to which the first lock and the second lock are added is modified to obtain a second target data table.
2. The method for modifying the database table structure according to claim 1, characterized in that: The first target data table includes a first lock, a second lock, and multiple other locks except the first lock and the second lock; The first lock and the second lock are mutually exclusive, and the first lock and the other multiple locks coexist; The second lock is mutually exclusive with the first lock and the other multiple locks.
3. The method for modifying the database table structure according to claim 1, characterized in that: The first lock is a multi-version shared lock, and the second lock is a multi-version exclusive lock.
4. The method for modifying the database table structure according to claim 1, characterized in that: The first data group includes pre-image data of basic data in the original database table, and the pre-image data is generated in response to an operation of modifying the structure of the original database table.
5. The method for modifying the database table structure according to claim 1 or 4, characterized in that: The constructing a first target data table according to the first data group and the second data group comprises: According to the modification target preset by the user, construct a third target data table having a table structure different from that of the original database table, wherein the third target data table has no data rows; constructing a basic target data table according to the first data group and the third target data table; The first target data table is constructed based on the basic target data table according to the second data group and the corresponding incremental data operation log.
6. The method for modifying the database table structure according to claim 5, characterized in that: The preset numerical condition includes that the number of the incremental data operation logs is less than or equal to 5.
7. A database table structure modification device, characterized in that: The database table structure modification device comprises: a construction module, configured to construct a first target data table according to a first data group and a second data group in response to a modification instruction for an original database table structure, wherein the first data group includes basic data in the original database table before modification, and the second data group includes incremental data generated in the original database table during the modification process, wherein the first target data table and the original database table have different table structures; a locking module, configured to add a first lock to the first target data table when a read operation on the first target data table is detected, and to add a second lock to the first target data table when the data volume of the second data group meets a preset numerical condition; The modification module is used to modify the metadata in the first target data table to which the first lock and the second lock are added to obtain the second target data table.
8. An electronic device comprising: one or more processors; a memory for storing one or more computer programs, It is characterized in that the one or more processors execute the one or more computer programs to implement the steps of the database table structure modification method according to any one of claims 1 to 6.
9. A computer-readable storage medium having executable instructions stored thereon, characterized in that: When the instruction is executed by the processor, the processor implements the database table structure modification method described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements the method for modifying the database table structure according to any one of claims 1 to 6.
Citation Information
Patent Citations
Table structure online change method and device, electronic equipment and storage medium
CN115422188A
Data storage method and device and electronic equipment
CN116383195A