Table expansion method and device of database, storage medium and electronic equipment

By using trigger technology during the database table expansion process, a second data table is created and triggers are set on it, which solves the table locking problem during open source database table expansion, realizes a smooth table expansion operation without any noticeable impact, and avoids long-term business downtime.

CN116186024BActive Publication Date: 2026-02-06CHINA TELECOM CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211521147.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-30
Publication Date
2026-02-06
Estimated Expiration
2042-11-30

AI Technical Summary

Technical Problem

When expanding tables in open-source databases, large amounts of data can lead to prolonged business downtime, and existing technologies have not effectively solved the blocking problem caused by table locking.

Method used

By employing trigger technology, a second data table is created and various types of triggers are set on it. The triggers execute predetermined operations under certain conditions, copying the data from the first data table to the second data table. The second data table is then updated based on the extension instructions and the execution results of the triggers, thus avoiding locking the first data table.

Benefits of technology

This ensures that online business operations are not affected during the table expansion process, that users are unaware of the table expansion operation, that business downtime is shortened, and that the blocking problem caused by table locking is resolved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116186024B_ABST
    Figure CN116186024B_ABST
Patent Text Reader

Abstract

The application discloses a table expansion method and device of a database, a storage medium and an electronic device. The method comprises the following steps: obtaining a first data table to be expanded and a target data table structure; creating a second data table based on the target data table structure, wherein the second data table is an empty table; creating multiple types of triggers in the second data table, wherein the triggers are used to execute predetermined operations when a trigger condition is met; receiving an expansion instruction, and copying data of the first data table into the second data table in response to the expansion instruction; detecting the predetermined operations executed by the triggers in the data copying process; and updating the second data table according to a first execution result of the expansion instruction and the predetermined operations executed by the triggers. The application solves the technical problem of blocking online business operations and even causing long-time offline of the business due to the locking of the source table based on the table locking in the related art.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of databases, and in particular, to a table expansion method and device of a database, a storage medium, and an electronic device. BACKGROUND

[0002] With the popularity of information systems, more and more business data is structured and stored in databases. As the system runs, new business requirements often arise, often requiring the expansion of database table fields to meet new business needs. In traditional Oracle databases, table fields can be modified and expanded online, but for most open source databases, this function is not perfect, and the table expansion operation often requires locking the source table, blocking online business operations. If the data volume of the table to be expanded is large, it will cause long-term business downtime.

[0003] At present, there is no effective solution to the above problems. SUMMARY

[0004] The embodiments of the present application provide a table expansion method and device of a database, a storage medium, and an electronic device, to at least solve the technical problem of blocking online business operations due to locking the source table based on the related art in table expansion, and even causing long-term business downtime.

[0005] According to an aspect of an embodiment of the present application, a table expansion method of a database is provided, including: obtaining a first data table to be expanded and a target data table structure, wherein the target data table structure is the data table structure of the first data table after expansion; creating a second data table based on the target data table structure, wherein the second data table is an empty table; creating multiple types of triggers in the second data table, wherein the triggers are used to execute predetermined operations when the trigger conditions are met; receiving an expansion instruction, and in response to the expansion instruction, copying data of the first data table to the second data table; detecting the predetermined operation executed by the trigger during the data copying process; and updating the second data table according to the first execution result of the expansion instruction and the predetermined operation executed by the trigger.

[0006] Optionally, updating the second data table according to the first execution result of the expansion instruction and the predetermined operation executed by the trigger includes: in response to the expansion instruction, calling a row-level shared lock to perform a locking operation on each row of data in the first data table; detecting an operation instruction received from a target object during the data copying process, triggering a target trigger corresponding to the operation instruction, executing a predetermined operation corresponding to the target trigger, and updating the second data table based on the second execution result of the target trigger and the first execution result.

[0007] Optionally, the method further comprises: in the process of copying the data, if no operation instruction from the target object is detected, updating the second data table based on the first execution result.

[0008] Optionally, updating the second data table based on the second execution result of the target trigger and the first execution result comprises: obtaining a start time of executing the expansion instruction and an end time at which all data of the first data table is copied; determining all types of triggers triggered in the start time to the end time, and writing the second execution result of all types of triggers into the second data table.

[0009] Optionally, after updating the second data table based on the second execution result of the target trigger and the first execution result, the method further comprises: obtaining a first table name corresponding to the first data table; renaming a table name of the second data table as the first table name, and replacing the first table name in the first data table with a preset character.

[0010] Optionally, after renaming the table name of the second data table as the first table name and replacing the first table name in the first data table with the preset character, the method further comprises: searching the preset character and the first table name; determining a data table corresponding to the first table name, deleting a plurality of types of triggers in the data table, and deleting a data table corresponding to the preset character.

[0011] Optionally, the plurality of types of triggers comprise: a deletion trigger, an update trigger, and an insertion trigger.

[0012] According to another aspect of the embodiments of the present application, a database table expansion apparatus is further provided, comprising: an obtaining module, configured to obtain a first data table to be expanded and a target data table structure, wherein the target data table structure is a data table structure after expansion of the first data table; a first creating module, configured to create a second data table based on the target data table structure, wherein the second data table is an empty table; a second creating module, configured to create a plurality of types of triggers in the second data table, wherein the triggers are used to execute a predetermined operation when a trigger condition is met; an updating module, configured to receive an expansion instruction, copy data of the first data table into the second data table in response to the expansion instruction, detect a predetermined operation executed by the triggers in the process of copying the data, and update the second data table based on a first execution result of the expansion instruction and the predetermined operation executed by the triggers.

[0013] According to another aspect of the embodiments of the present application, a nonvolatile storage medium is further provided, comprising a stored program, wherein when the program is running, the nonvolatile storage medium controls a device in which the nonvolatile storage medium is located to execute any one of the database table expansion methods.

[0014] According to another aspect of the embodiments of the present application, an electronic device is also provided, which includes a processor, a memory for storing processor-executable instructions, wherein the processor is configured to execute the instructions to implement any of the table expansion methods of the database.

[0015] In the embodiments of the present application, the trigger is set, and the related operation is triggered according to the trigger. The first data table to be expanded and the target data table structure are obtained, wherein the target data table structure is the data table structure after the expansion of the first data table. The second data table is created based on the target data table structure, wherein the second data table is an empty table. The triggers of multiple types are created in the second data table, wherein the triggers are used to execute the predetermined operation when the trigger condition is met. The expansion instruction is received, and the data of the first data table is copied into the second data table in response to the expansion instruction. The predetermined operation executed by the trigger during the data copying process is detected. The second data table is updated according to the first execution result of the expansion instruction and the predetermined operation executed by the trigger, so that the online operation is not affected during the expansion, and the technical effect of ensuring that the user is smooth and unaware of the expansion operation is achieved, thereby solving the technical problem of blocking the online business operation and even causing the business to be offline for a long time due to the locking of the source table based on the table locking in the related art during the expansion. BRIEF DESCRIPTION OF DRAWINGS

[0016] The accompanying drawings, which are included to provide a further understanding of the present application, constitute a part of the present application and illustrate the illustrative embodiments of the present application and its description, which serve to explain the present application, and do not constitute improper limitations on the present application. In the drawings:

[0017] Figure 1 is a flow diagram of an optional table expansion method of a database according to an embodiment of the present application;

[0018] Figure 2 is a schematic diagram of the expansion of the data table field in an embodiment of the present application;

[0019] Figure 3 is a structural schematic diagram of a table expansion device of a database according to an embodiment of the present application. DETAILED DESCRIPTION

[0020] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should be within the scope of protection of the present application.

[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and in the above drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not have to be limited to only those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0022] After studying these open source databases, it is found that the principle of table expansion is to create a new table containing new field information, then copy the data of the old table into it, finally delete the old table and rename the new table as the old table, and finally complete the replacement. The reason for locking is that the data copying operation process needs to avoid new or modified operations on the data of the old table, so as to ensure that the data of the new and old tables is completely consistent, and to avoid data errors in the table expansion process. Therefore, as long as the data consistency problem of the new and old tables is solved, the table locking problem in the table expansion process is also solved, and the business downtime in the operation process can be avoided.

[0023] According to an embodiment of the present application, a database table expansion method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described herein can be executed in an order different from that shown herein.

[0024] Figure 1 The database table expansion method according to an embodiment of the present application, as shown in Figure 1 includes the following steps:

[0025] Step S102, obtaining a first data table to be expanded and a target data table structure, wherein the target data table structure is the data table structure after the first data table is expanded;

[0026] Step S104, creating a second data table based on the target data table structure, wherein the second data table is an empty table;

[0027] Step S106, creating multiple types of triggers in the second data table, wherein the triggers are used to execute predetermined operations when the trigger conditions are met; receiving an expansion instruction, and in response to the expansion instruction, copying the data of the first data table into the second data table;

[0028] In step S108, a predetermined operation performed by the trigger is detected in the process of copying the data, and the second data table is updated according to the first execution result of the expansion instruction and the predetermined operation performed by the trigger.

[0029] In the table expansion method of the database, the trigger is set, the related operation triggered by the trigger is performed, the first data table to be expanded and the target data table structure are obtained, the target data table structure is the data table structure of the first data table after expansion, the second data table is created based on the target data table structure, the second data table is an empty table, a plurality of types of triggers are created in the second data table, the trigger is used to perform a predetermined operation when the trigger condition is met, the expansion instruction is received, the data of the first data table is copied into the second data table in response to the expansion instruction, the predetermined operation performed by the trigger is detected in the process of copying the data, and the second data table is updated according to the first execution result of the expansion instruction and the predetermined operation performed by the trigger, thereby realizing the technical effect that the online operation is not affected during the table expansion, ensuring that the user is smooth and unaware of the table expansion operation, and solving the technical problems that the source table is locked based on the table locking in the related art during the table expansion, the online business operation is blocked, and even the business is offline for a long time.

[0030] In some embodiments of the present application, the second data table is updated according to the first execution result of the expansion instruction and the predetermined operation performed by the trigger, which can be realized by the following method: in response to the expansion instruction, the row-level shared lock is called to perform the locking operation on each row of data in the first data table; in the process of copying the data, the operation instruction from the target object is detected, the target trigger corresponding to the operation instruction is triggered, the predetermined operation corresponding to the target trigger is performed, and the second data table is updated based on the second execution result of the target trigger and the first execution result.

[0031] It can be understood that in the process of copying the data, the second data table is updated based on the first execution result in the case that the operation instruction from the target object is not detected.

[0032] In some embodiments of the present application, the second data table is updated based on the second execution result of the target trigger and the first execution result, which includes: obtaining the starting time of executing the expansion instruction and the termination time when all the data of the first data table is copied; determining all types of triggers triggered in the starting time to the termination time, and writing the second execution result corresponding to all types of triggers into the second data table.

[0033] In an example embodiment of the present application, after the second data table is updated based on the second execution result of the target trigger and the first execution result, the first table name corresponding to the first data table can be obtained; the table name of the second data table is named as the first table name, and the first table name in the first data table is replaced by a preset character.

[0034] As an optional implementation, after naming the table name of the second data table as the first table name and replacing the first table name in the first data table with the preset character, the preset character and the first table name can be searched; the data table corresponding to the first table name is determined, the multiple types of triggers in the data table are deleted, and the data table corresponding to the preset character is deleted. That is, after the second data table is named as the second table name, the first data table and the trigger set by the second data table can be deleted.

[0035] It should be noted that the multiple types of triggers include but are not limited to: a deletion trigger, an update trigger and an insertion trigger.

[0036] It is easy to note that in order to achieve the above purpose, the present application combines the database trigger technology and designs a database field expansion method. The scheme involves the following entities:

[0037] 1. Old table, that is, the first data table: refers to the original table structure of the online business, that is, the data table to be expanded, which must have a primary key or a unique key.

[0038] 2. New table, that is, the second data table: refers to the table structure after the table field expansion and modification, which is the target structure of the table expansion operation.

[0039] 3. Trigger: a programmable database object that can monitor the addition, deletion and modification of a table. When the above operations are performed, the corresponding program action is triggered.

[0040] In an optional embodiment, the overall data table expansion process is as follows:

[0041] 1. First, create a new table, and the table structure is the data table structure after expansion.

[0042] 2. Create three triggers in the following order: deletion trigger, update trigger and insertion trigger. They are used to apply the incremental data modification on the original data table to the new table.

[0043] 3. Start copying data, copy all data from the old table to the new table. During the data copying process, the trigger continues to apply the incremental modification on the old table to the new table. The copying process holds a row shared lock (i.e. a row-level shared lock, which can only read data, but cannot modify data.) on the data row. If it is found that a certain piece of data already exists during the copying process, the existing data is used as the reference, that is, the data synchronized by the trigger is used as the reference.

[0044] 4. Interchange the table names of the old and new tables, and complete the operation through the rename operation, i.e. rename the old table as _old and rename the new table as the old table name. The rename operation is an atomic operation and cannot be divided. The operation process locks the old table, which is the only step in which the table needs to be locked in the method, but since the operation only involves metadata modification, the speed is relatively fast, and the table is only locked for a few seconds.

[0045] 5. Delete the trigger and delete the old table.

[0046] The above table expansion method will be described in combination with a specific embodiment. Specifically, the table expansion of the database can be implemented according to the following flow:

[0047] 1) First, connect to the mysql using the account password, obtain the state information of the specified table, check whether there is a trigger, and check whether the table has a primary key or a unique key.

[0048] 2) According to the table definition of the modified table, a new temporary table named _tb_new is created, the alter operation is performed on the table to add fields, and whether the operation is successful is verified.

[0049] 3) Then, three triggers are created for the source table, as follows:

[0050] create trigger table_del after delete on db.table for each row deleteignore from db.table_new where db.table_new.id<=>OLD.id#If there is no data in the new table, ignore the delete operation in the source table

[0051] create trigger table_updt after update on db.table for each rowreplace into db.table_new(id,...)values(new.id,...)#When the source table executes update, the corresponding data is written into the new table in the replace into mode

[0052] create trigger table_insert after insert on db.table for each rowreplace into db.table_new(id,...)values(new.id,...)#When the source table executes insert operation, the corresponding data is written into the new table in the replace into mode

[0053] 4) After the trigger is created, the insert low_priority ignore into db.table_new(id,..) select id,... from table lock in share mode statement is executed to copy the source table data to the new table.

[0054] 5) After the copy is completed, the rename table db.table to db.table_old, db.table_new to db.table statement is executed to modify the source table to table_old format and the new table table_new to the original name of the source table.

[0055] 6) Finally, the Old table is deleted, and then the three triggers are deleted. Here, the online table structure modification is completed, and the entire process only temporarily locks the table during the rename table process, and does not lock the table at other times. Figure 2 is a schematic diagram of data table field expansion in an embodiment of the present application, as shown in the Tabel to Table_new data replication process, the trigger can synchronize the data in Table_new, and the data structure of Table_new can be modified. Figure 2

[0056] It is easy to note that the data consistency guarantee scheme in the table expansion process of the present application is used to replace the simple locking scheme of some open source databases, greatly shortens the business offline time in the table expansion process, and is based on the trigger implementation of most databases, has strong universality, and does not depend on a specific database.

[0057] Figure 3 is a database table expansion apparatus according to an embodiment of the present application, as shown in the apparatus includes: Figure 3

[0058] The obtaining module 30 is configured to obtain a first data table to be expanded and a target data table structure, wherein the target data table structure is a data table structure after the first data table is expanded.

[0059] The first creating module 32 is configured to create a second data table based on the target data table structure, wherein the second data table is an empty table.

[0060] The second creating module 34 is configured to create multiple types of triggers in the second data table, wherein the trigger is configured to execute a predetermined operation when a trigger condition is met.

[0061] ​​The updating module 36 is configured to receive an expansion instruction, copy data of the first data table into the second data table in response to the expansion instruction, detect a predetermined operation performed by the trigger during the data copying, and update the second data table according to a first execution result of the expansion instruction and the predetermined operation performed by the trigger.

[0062] The database expansion apparatus includes an obtaining module 30 configured to obtain a first data table to be expanded and a target data table structure, wherein the target data table structure is a data table structure of the first data table after expansion; a first creating module 32 configured to create a second data table based on the target data table structure, wherein the second data table is an empty table; a second creating module 34 configured to create multiple types of triggers in the second data table, wherein the triggers are configured to perform predetermined operations when trigger conditions are met; and an updating module 36 configured to receive an expansion instruction, copy data of the first data table into the second data table in response to the expansion instruction, detect a predetermined operation performed by the trigger during the data copying, and update the second data table according to a first execution result of the expansion instruction and the predetermined operation performed by the trigger. Thus, the online operation is not affected during the expansion, and the user is not aware of the expansion operation, thereby solving the technical problem of blocking the online business operation and even causing the business to be offline for a long time due to the locking of the source table based on the table locking in the related art.

[0063] According to another aspect of the embodiments of the present application, a nonvolatile storage medium is also provided, which includes a stored program. When the program is executed, the device in which the storage medium is located performs any one of the database expansion methods.

[0064] Specifically, the storage medium is configured to store program instructions of the following functions to implement the following functions:

[0065] The first data table to be expanded and a target data table structure are obtained, wherein the target data table structure is a data table structure of the first data table after expansion; a second data table is created based on the target data table structure, wherein the second data table is an empty table; multiple types of triggers are created in the second data table, wherein the triggers are configured to perform predetermined operations when trigger conditions are met; an expansion instruction is received, data of the first data table is copied into the second data table in response to the expansion instruction; a predetermined operation performed by the trigger during the data copying is detected; and the second data table is updated according to a first execution result of the expansion instruction and the predetermined operation performed by the trigger.

[0066] Optionally, storage media can include one or both of volatile and non-volatile memory, removable and non-removable memory, erasable and non-erasable memory, writeable and non-writeable memory, and / or the like. Examples of non-volatile storage media include, but are not limited to, NVRAM, flash memory, disk, magnetic media, and / or the like. Examples of volatile storage media include, but are not limited to, RAM, register storage, and / or the like.

[0067] An electronic device according to embodiments of the present application includes at least one processor, and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the table expansion method of any one of the above.

[0068] Optionally, the electronic device can further include a transmission device and an input / output device, wherein the transmission device is connected with the processor, and the input / output device is connected with the processor.

[0069] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, specially designed application specific integrated circuits (ASICs), field programmable gate arrays (FPGAs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0070] Program code for carrying out methods of the present application can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program code, when executed by the processor or controller, enables the functions / acts specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on a machine, partially on a machine, fully on a machine, partially on a machine and partially on a remote machine or entirely on a remote machine or server.

[0071] In the context of this application, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include a lined- up electrical connection, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0072] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.

[0073] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.

[0074] The computer system can include clients and servers. This relationship can be. The servers are typically remote from the clients with the interactions typically happening over a communication network. The relationship of client and server arises by interplay of both the programs in their respective computers and the client and server are in a client-server relationship. The server can be a cloud server, a server of a distributed system or a server incorporating blockchain.

[0075] The above-mentioned sequence numbers of the embodiments of the present application are only for description, and do not represent the advantages or disadvantages of the embodiments.

[0076] In the above-mentioned embodiments of the present application, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.

[0077] In the several embodiments provided by the present application, it should be understood that the disclosed technology can be implemented in other ways. Of course, the embodiment described above is only illustrative. For example, the division of units can be a logical function division, and actual implementation can have another division manner. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interface, unit or module, and can be electrical or other forms.

[0078] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or distributed on multiple units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.

[0079] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically, or two or more units can be integrated into one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0080] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or say the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.

[0081] The above is only the preferred embodiment of the present application, and it should be pointed out that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should be considered as the protection scope of the present application.

Claims

1. A method for expanding a database table, characterized in that, include: Obtain the first data table to be expanded and the target data table structure, wherein the target data table structure is the data table structure after the first data table is expanded; A second data table is created based on the target data table structure, wherein the second data table is an empty table; Multiple types of triggers are created in the second data table, wherein the triggers are used to perform a predetermined operation when a trigger condition is met; The system receives an expansion instruction and, in response to the expansion instruction, copies data from the first data table to the second data table; detects a predetermined operation performed by the trigger during the data copying process; and updates the second data table based on the first execution result of the expansion instruction and the predetermined operation performed by the trigger, wherein, in response to the expansion instruction, a row-level shared lock is invoked to lock each row of data in the first data table; detects an operation instruction received from a target object during the data copying process, triggers the target trigger corresponding to the operation instruction, executes the predetermined operation corresponding to the target trigger, and updates the second data table based on the second execution result of the target trigger and the first execution result, wherein the system obtains the start time of executing the expansion instruction and the end time when all data in the first data table has been copied; determines all types of triggers triggered between the start time and the end time, and writes the second execution results corresponding to all types of triggers into the second data table.

2. The table expansion method according to claim 1, characterized in that, The method further includes updating the second data table based on the first execution result if no operation instruction from the target object is detected during the data copying process.

3. The table expansion method according to claim 1, characterized in that, After updating the second data table based on the second execution result of the target trigger and the first execution result, the method further includes: Get the name of the first table corresponding to the first data table; The name of the second data table is renamed to the name of the first table, and the name of the first table in the first data table is replaced with a preset character.

4. The table expansion method according to claim 3, characterized in that, After renaming the second data table to the first table name and replacing the first table name in the first data table with preset characters, the method further includes: Search the preset characters and the first table name; Determine the data table corresponding to the first table name, delete the triggers of various types in the data table, and delete the data table corresponding to the preset character.

5. The table expansion method according to any one of claims 1 to 4, characterized in that, The various types of triggers include: delete triggers, update triggers, and insert triggers.

6. A database table expansion device, characterized in that, include: The acquisition module is used to acquire the first data table to be expanded and the target data table structure, wherein the target data table structure is the data table structure after the first data table is expanded. The first creation module is used to create a second data table based on the target data table structure, wherein the second data table is an empty table; The second creation module is used to create various types of triggers in the second data table, wherein the triggers are used to perform a predetermined operation when a trigger condition is met; An update module is configured to receive an expansion instruction, and in response to the expansion instruction, copy data from the first data table to the second data table; detect a predetermined operation performed by the trigger during the data copying process; and update the second data table based on the first execution result of the expansion instruction and the predetermined operation performed by the trigger, wherein, in response to the expansion instruction, a row-level shared lock is invoked to lock each row of data in the first data table; detect an operation instruction received from a target object during the data copying process, trigger a target trigger corresponding to the operation instruction, execute the predetermined operation corresponding to the target trigger, and update the second data table based on the second execution result of the target trigger and the first execution result, wherein the start time of executing the expansion instruction and the end time when all data in the first data table has been copied are obtained; determine all types of triggers triggered between the start time and the end time, and write the second execution results corresponding to all types of triggers into the second data table.

7. A non-volatile storage medium, characterized in that, The storage medium includes a stored program, wherein, when the program is executed, it controls the device where the storage medium is located to perform the table expansion method of the database according to any one of claims 1 to 5.

8. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the database expansion method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Database expansion method and device

    CN110858194A

  • Database capacity expansion method and device, computer equipment and storage medium

    CN114398344A