WO2024041022A1 - 数据库表变更方法、装置、设备和存储介质 - Google Patents

数据库表变更方法、装置、设备和存储介质 Download PDF

Info

Publication number
WO2024041022A1
WO2024041022A1 PCT/CN2023/091258 CN2023091258W WO2024041022A1 WO 2024041022 A1 WO2024041022 A1 WO 2024041022A1 CN 2023091258 W CN2023091258 W CN 2023091258W WO 2024041022 A1 WO2024041022 A1 WO 2024041022A1
Authority
WO
WIPO (PCT)
Prior art keywords
change
target
changed
data
current intermediate
Prior art date
Application number
PCT/CN2023/091258
Other languages
English (en)
French (fr)
Inventor
高晨峰
Original Assignee
京东科技信息技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 京东科技信息技术有限公司 filed Critical 京东科技信息技术有限公司
Publication of WO2024041022A1 publication Critical patent/WO2024041022A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • This application relates to computer technology, for example, to methods, devices, equipment and storage media for changing database tables.
  • This application provides database table changing methods, devices, equipment and storage media to greatly reduce the table lock time for database table changing and improve user experience.
  • this application provides a database table modification method, including:
  • Parse the target change statement determine the name of the table to be changed corresponding to the table to be changed in the target database, and create a current intermediate table with the same structure as the table to be changed based on the name of the table to be changed;
  • the target change statement and the table data in the table to be changed Based on the target change type corresponding to the target change statement, the target change statement and the table data in the table to be changed, perform table data storage and change processing on the current intermediate table, and record that the table to be changed is generated within the data processing time period of the current intermediate table
  • the first data change log
  • the second data change log If it is determined based on the second data change log that the preset table switching condition is met, then based on the target change type type, the second data change log and the current intermediate table, perform lock switching on the table to be changed, and obtain the changed target table.
  • this application also provides a database table changing device, including:
  • the target database acquisition module is configured to obtain the target database to be changed and the target change statement corresponding to the target database;
  • the target change statement parsing module is configured to parse the target change statement, determine the name of the table to be changed corresponding to the table to be changed in the target database, and create a current intermediate table with the same structure as the table to be changed based on the name of the table to be changed;
  • the first change processing module is set to perform table data storage and change processing on the current intermediate table based on the target change type corresponding to the target change statement, the target change statement and the table data in the table to be changed, and record the table data to be changed in the current intermediate table
  • the first data change log generated during the data processing time period of the table
  • the second change processing module is configured to perform data changes on the current intermediate table based on the target change type and the first data change log, and record the second data change log generated by the table to be changed within the data change time period of the current intermediate table;
  • the target table acquisition module is configured to lock and switch the table to be changed based on the target change type, the second data change log and the current intermediate table if it is determined based on the second data change log that the preset table switching conditions are met. target table.
  • embodiments of the present application further provide an electronic device, where the electronic device includes:
  • processors one or more processors
  • memory configured to store one or more programs
  • the one or more processors When the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the above-mentioned database table modification method.
  • the present application also provides a computer-readable storage medium on which a computer program is stored.
  • the program is executed by a processor, the above-mentioned database table modification method is implemented.
  • Figure 1 is a flow chart of a database table modification method provided by an embodiment of the present application.
  • Figure 2 is a flow chart of another database table modification method provided by an embodiment of the present application.
  • Figure 3 is a flow chart of another database table modification method provided by an embodiment of the present application.
  • Figure 4 is a schematic structural diagram of a database table changing device provided by an embodiment of the present application.
  • FIG. 5 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • Figure 1 is a flow chart of a database table modification method provided by an embodiment of the present application. This embodiment can be applied to the situation of modifying a database table with a large amount of data.
  • the method can be executed by a database table changing device, which can be implemented by software and/or hardware and integrated into electronic equipment. As shown in Figure 1, the method includes the following steps:
  • the target database can refer to the database where the data table that needs to be changed is located.
  • the target database can be set based on business requirements.
  • the target change statement may refer to a change modification instruction to a database table.
  • the target change statement may be a Structured Query Language (SQL) statement.
  • SQL Structured Query Language
  • the target change statement can be set based on the table name of the table to be changed, the change type, and the corresponding change content.
  • the target database that needs to be changed and the target change statement corresponding to the target database can be obtained from the change task created by the user.
  • the user can create a change task based on business requirements in the operation interface, where the change task can include the target database link information and target change statement configured by the user.
  • One or more change tasks created by the user are stored in the change task table.
  • a change task can be taken out from the change task table at fixed intervals for processing, and the status of the change task can be modified. It is executing until all change tasks are processed.
  • the corresponding target database can be determined based on the target database link information in the currently retrieved target change task, and the target change statement corresponding to the target database can be obtained.
  • S110 may include: obtaining the currently pending target change task from the change task queue, where the change task queue is used to store multiple change tasks created by the user; based on the target database link information in the target change task, determine The target database to be changed, and obtain the target change statement corresponding to the target database in the target change task.
  • the target change task may refer to the change task that currently needs to be performed.
  • the target change task may be a change task to database table a in database A, or a change task to database table b in database B.
  • the target database link information may refer to link information used to link the target database address, so that the target database that needs to be changed can be obtained based on the target database link information.
  • the target database link information can be: xxxx:mysql:/localhost:1111example.
  • Multiple change tasks created by users can be stored in the change task queue in order of creation time. Using the change task queue, you can immediately remove the next change task from the queue after the current change task is completed, without waiting for a fixed time interval before executing the next change task. This can reduce latency and improve reliability. Obtain the target change task that currently needs to be processed from the change task queue, and determine the target database that needs to be changed based on the target database link information in the target change task. At the same time, obtain the target change corresponding to the target database from the target change task created by the user. statement.
  • the table to be changed may refer to the database table in the target database that needs to be changed.
  • the name of the table to be changed is unique in the database, and the unique corresponding table to be changed can be queried based on the name of the table to be changed.
  • An intermediate table can refer to a temporary table created with the same data structure as the table to be changed.
  • the current intermediate table may refer to the intermediate table obtained at the current moment.
  • the table data and/or table structure in the current intermediate table are dynamically changing. For example, the current intermediate table obtained when creating is an empty table with the same data structure as the table to be changed.
  • the target change statement may include the name of the database table that needs to be changed.
  • the name of the table to be changed can be determined.
  • the corresponding table to be changed can be obtained according to the name of the table to be changed, and a current intermediate table with the same structure as the table to be changed can be created.
  • the current intermediate table is an empty table.
  • the name of the table to be changed is t1.
  • the structure of the table t1 to be changed can be obtained, and based on the structure of the table t1 to be changed, a current table with the same structure is created.
  • the intermediate table t1_tmp has a table name different from the name of the table to be updated.
  • the target change type may refer to the type of change to be made to the change table.
  • Target change types can include table structure changes alter table and table data changes update from based on reference tables, etc.
  • Table structure changes can include adding, modifying, and deleting fields or indexes in the table to be changed.
  • Table data changes based on the reference table may be updating field data in the reference table to corresponding field data in the table to be referenced.
  • the data change log may refer to the binary log file binlog recorded when the user performs change operations on the change table.
  • the first data change log may refer to the data change log binlog recorded when the user operates the table to be changed within the time period during which the current intermediate table is changed according to the target change statement (ie, the first change time period).
  • the target change type corresponding to the table to be changed can be determined based on the target change statement created by the user.
  • base Based on the target change type and table data in the table to be changed, perform data storage and change operations on the current intermediate table created, and record during the data storage and change operations on the current intermediate table (i.e., the first change time period), The first data change log corresponding to the user's change operation on the table to be changed.
  • the user can continue to change the table to be changed, so that the normal operation of services related to the table to be changed will not be affected during the first change period, and it will be recorded in The first data change log of the user's change operation on the table to be changed in the first change time period.
  • the second data change log may refer to the data change log binlog recorded when the user operates the table to be changed during the time period during which the current intermediate table is changed according to the first data change log (ie, the second change time period).
  • the current intermediate table refers to the intermediate table with empty data volume.
  • the current intermediate table refers to the intermediate table that has been modified according to the target change statement and stored according to the data of the table to be updated.
  • the current intermediate table in S130 and the current intermediate table in S140 are intermediate tables with the same name but different stages. That is, the current intermediate table in S140 is the intermediate table after the change operation is performed in S130.
  • the user can continue to change the table to be changed, so that the normal services related to the table to be changed will not be affected during the second change time period.
  • Run and at the same time record the second data change log of the user's change operation on the table to be changed during the second change time period.
  • the preset table switching conditions can be set in advance, and the intermediate table can be replaced by the conditions of the table to be changed.
  • the preset table switching condition may be that the data difference value between the intermediate table and the table to be updated is less than a preset threshold.
  • the target table may refer to the final database table obtained after making changes to the table to be changed.
  • the current intermediate table in S150 is the intermediate table obtained after the change operation is performed in S140.
  • This embodiment can detect whether the current preset table switching condition is satisfied based on the second data change log to determine whether the intermediate table and the table to be changed are close. If it is determined based on the second data change log that the preset table switching conditions are met, it means that the data difference between the current intermediate table and the table to be changed is small. At this time, based on the target change type, the second data change log and the current intermediate table, It takes a short time to complete the lock switching operation on the table to be updated and obtain the changed target table. This eliminates the need to lock the table during the entire change process, greatly reducing the table locking time for database table changes and improving the user experience.
  • S150 may include: determining the total number of data change statements in the second data change log; if the total number is less than or equal to the preset quantity threshold, determining that the preset table switching condition is met.
  • the data change statement may refer to the SQL statement used when the user performs a change operation on the table to be changed.
  • the second data change log may include all data change statements corresponding to all change operations performed by the user on the table to be changed within the second change time period. The more data change statements there are, the greater the number of change operations on the table to be changed during the second change period, which in turn indicates that the amount of data that needs to be synchronized between the intermediate table and the table to be changed is greater.
  • the preset quantity threshold can be the maximum value of the data difference between the intermediate table and the table to be changed, which is set in advance based on business requirements.
  • the total number of data change statements in the second data change log can be counted. If the total number of data change statements in the second data change log is less than or equal to the preset quantity threshold, then This indicates that the data difference between the current intermediate table and the table to be changed is small. At this time, it can be determined that the preset table switching conditions are met, and the table to be changed can be locked and switched.
  • the method further includes: if it is determined based on the second data change log that the preset table switching condition is not satisfied, then continue to perform data changes on the current intermediate table based on the target change type and the second data change log, and record the data to be changed.
  • the change table generates the next data change log within the data change time period of the current intermediate table until it is determined based on the next data change log that the preset table switching conditions are met.
  • the next data change log may refer to the data change log of the user's operation on the change table in the next change time period. For example, within the change processing time period of the current intermediate table based on the second data change log (that is, the next change time period is the third change time period), the next data change log recorded when the user operates on the to-be-changed table is In the same way, there may be a third data change log, a fourth data change log, a fifth data change log, etc., and so on.
  • the preset table switching condition is not met, for example, the total number of data change statements in the second data change log is greater than the preset number threshold. If it is determined based on the second data change log that the preset table switching condition is not met, for example, the total number of data change statements in the second data change log is greater than the preset number threshold, then continue to change the target table according to the target change type and the second data change log. , perform another data change on the current intermediate table obtained from the last change, and record the third data change log during the data change period of the current intermediate table, that is, the third data change log of the user's change operation on the table to be changed during the third change time period, and based on the third data change log The third data change log detects whether the current preset table switching conditions are met.
  • the modification operation on the database table can be performed in any period of time, and there is no need to wait until the service is off-peak to make changes.
  • interruption can be performed at any time without affecting the normal operation of services related to the table to be changed.
  • the technical solution of the embodiment of this application is to obtain the target database and target change statement to be changed, parse the target change statement, and create an intermediate table with the same structure as the table to be changed based on the obtained name of the table to be changed, so as to facilitate utilization
  • the current intermediate table replaces the table to be changed for change processing, so there is no need to lock the table to be changed when the change starts.
  • the target change type corresponding to the target change statement and the table data in the table to be changed perform table data storage and change processing on the current intermediate table, and record the first data generated by the table to be changed within the data processing time period of the current intermediate table. Change log.
  • the data change log realizes data synchronization between the intermediate table and the table to be changed. If it is determined based on the second data change log that the preset table switching conditions are met, it indicates that the data difference between the current intermediate table and the table to be changed is small. At this time, the lock switching operation of the table to be changed can be completed in a short time. , obtain the changed target table, thereby eliminating the need to lock the table during the entire change process, which greatly reduces the table locking time for database table changes and improves user experience.
  • S150 may include: renaming the table to be changed to a preset table name; performing data changes and renaming the current intermediate table based on the target change type, the second data change log and the name of the table to be changed. Operation to obtain the changed target table.
  • the default table name is different from the table name to be changed.
  • the preset table name may refer to another name set in advance for the table to be changed that is different from the name of the table to be changed.
  • the preset table name may be any other name that is different from the names of all tables in the target database. For example, when the name of the table to be changed is t1, the default table name can be set to t1_bak.
  • the operation of locking and switching the table to be changed may be to rename the name of the table to be changed to a preset table name, and to rename the current intermediate table according to the target change type, the second data change log and the name of the table to be changed. Perform data change and rename operations on the table, and determine the intermediate table after completing the data change and rename as the target table after the change.
  • the table name t1 to be updated is renamed to the default table name t1_bak, and the data of the current intermediate table t1_tmp is changed according to the target change type, the second data change log and the table name t1 to be changed, and the current intermediate table t1_tmp is changed.
  • the name t1_tmp is renamed to the name of the table to be changed t1, thereby obtaining the table to be updated.
  • the target table t1 after table update.
  • the table to be changed t1_bak which is renamed to the preset table name, can be temporarily stored so that when the target table t1 fails, it can be restored based on the table to be changed t1_bak. If the target table t1 runs for the preset time without failure, the temporarily stored table t1_bak to be changed can be deleted to reduce data caching.
  • renaming the name of the table to be changed to the preset table name can be understood as locking the table to be changed, and determining the current intermediate table that has been renamed as the target table can be understood as unlocking the table to be changed. , so that the table to be changed only needs to be locked after the preset switching conditions are met, which greatly reduces the table locking time when the database table is changed.
  • performing data change and rename operations on the current intermediate table to obtain the changed target table may include: based on the target change type and the second data Change log, change the data of the current intermediate table, and rename the current intermediate table after the change to the name of the table to be changed, and obtain the target table after the change; or, rename the current intermediate table to the name of the table to be changed, and based on Target change type and second data change log, perform data changes on the renamed current intermediate table, and obtain the changed target table.
  • Figure 2 is a flow chart of another database table change method provided by an embodiment of the present application.
  • the target change type corresponding to the target change statement is table structure change
  • the step "Based on the target change type and The first data change log, "data change of the current intermediate table” is further explained.
  • the explanation of terms that are the same as or corresponding to the above embodiments will not be repeated here.
  • FIG. 1 Another database table modification method provided by this embodiment includes the following steps:
  • the target change statement obtained in this embodiment is: a table structure change type statement, such as an alter table statement, so that the structure of the table to be changed in the target database can be subsequently changed based on the target change statement. Even.
  • S220 Parse the target change statement, determine the name of the table to be changed corresponding to the table to be changed in the target database, and create a current intermediate table with the same structure as the table to be changed based on the name of the table to be changed.
  • the intermediate table change statement may refer to a statement that changes the intermediate table, which may be determined based on the target change statement.
  • the change object of the target change statement created by the user is the table to be changed, so the change object in the target change statement can be modified to the current intermediate table, that is, the name of the table to be changed in the target change statement is updated to the name of the intermediate table. , thereby obtaining the intermediate table change statement.
  • the table data in is synchronously stored in the current intermediate table after the table structure is changed.
  • the method of storing the table data in the table to be changed into the current intermediate table after execution may include a normal paging method and an identifier (ID) based segmentation method.
  • ID identifier
  • the table data in the table to be changed can be stored in the current intermediate table after execution based on the ID segmentation method, which can shorten the table data storage time.
  • each time based on the table data ID can Extract 100 pieces of data and store them in the current intermediate table. If there is no ID segmentation in the table to be changed, the table data in the table to be changed can be stored in the current intermediate table after execution based on ordinary paging.
  • step S230 and step S240 can be executed at the same time.
  • the intermediate table change statement corresponding to the data change statement may refer to a statement that changes the intermediate table, which may be determined based on the data change statement.
  • the change object in the data change statement in the first data change log is the table to be changed, so the change object in the data change statement can be modified to an intermediate table, that is, the name of the table to be changed in the data change statement can be updated to The name of the intermediate table to obtain the intermediate table change statement corresponding to the data change statement.
  • the intermediate table change statement corresponding to the data change statement in the first data change log can be directly executed in the current intermediate table obtained after S230, so that the first change will be
  • the user's change operations on the to-be-changed table during the interval are synchronized to the current intermediate table, thereby synchronously changing the data in the current intermediate table.
  • the two steps are to execute the intermediate table change statement corresponding to the data change statement in the first data change log in the current intermediate table, and to record the second data change log generated by the table to be changed during the data change time period of the current intermediate table. If executed at the same time, the order is not distinguished, that is, step S250 and step S260 can be executed at the same time.
  • performing data change and rename operations on the current intermediate table to obtain the changed target table may include:
  • the technical solution of the embodiment of this application is to execute the intermediate table change statement corresponding to the target change statement in the current intermediate table when the target change type corresponding to the target change statement is a table structure change, and store the table data in the table to be changed.
  • execute the intermediate table change statement corresponding to the data change statement in the first data change log in the current intermediate table so that the intermediate table and data change log can be used It can realize table structure changes and data synchronization, and greatly shortens the table lock time for database table changes, improving user experience.
  • Figure 3 is a flow chart of another database table modification method provided by an embodiment of the present application.
  • the target change type corresponding to the target change statement is a table data change based on a reference table
  • the target change statement and the table data in the table to be changed perform table data storage and change processing on the current intermediate table
  • the step "based on the The target change type and the first data change log, data change of the current intermediate table” are further explained. The explanation of terms that are the same as or corresponding to the above embodiments will not be repeated here.
  • FIG. 3 another database table modification method provided by this embodiment includes the following steps:
  • the target change statement obtained in this embodiment is: a table data change type statement based on the reference table, such as an update from statement, so that the table data to be changed in the target database based on the reference table can be subsequently modified based on the target change statement. change.
  • the intermediate table change statement may refer to a statement that changes the intermediate table, which may be determined based on the target change statement.
  • the change object of the target change statement created by the user is the table to be changed, so the change object in the target change statement can be modified to the current intermediate table, that is, the name of the table to be changed in the target change statement is updated to the name of the intermediate table. , thereby obtaining the intermediate table change statement.
  • the method of storing the table data in the table to be changed into the current intermediate table may include a normal paging method and an ID-based segmentation method.
  • the table data in the table to be changed can be stored in the current intermediate table based on the ID segmentation method, which can shorten the table data storage time. For example, if there are 10,000 pieces of data, 100 pieces can be extracted based on the table data ID each time. The data is stored in the current intermediate table. If there is no ID segmentation in the table to be changed, the table data in the table to be changed can be stored in the current intermediate table based on ordinary paging.
  • step S330 and step S340 can be executed simultaneously.
  • the intermediate table change statement corresponding to the data change statement may refer to a statement that changes the intermediate table, which may be determined based on the data change statement.
  • the change object in the data change statement in the first data change log is the table to be changed, so the change object in the data change statement can be modified.
  • the intermediate table change statement corresponding to the data change statement in the first data change log can be executed in the current intermediate table obtained after step S330, so that the user data in the first change time period can be
  • the change operation performed on the to-be-changed table is synchronized to the current intermediate table, thereby synchronously changing the data in the current intermediate table.
  • execute the intermediate table change statement corresponding to the target change statement again in the obtained current intermediate table so that table data can be changed again in the current intermediate table after the data synchronization change is completed. , thereby ensuring the accuracy of table data changes during the entire data change process.
  • step S350 and step S360 can be executed at the same time.
  • the technical solution of the embodiment of this application is that when the target change type corresponding to the target change statement is a table data change based on a reference table, the table data in the table to be changed is stored in the current intermediate table, and the table data is stored in the current intermediate table based on the reference table in the target database.
  • the following is an example of a database table changing device provided by an embodiment of the present application.
  • This device belongs to the same concept as the database table changing method of the above embodiment.
  • Figure 4 is a schematic structural diagram of a database table changing device provided by an embodiment of the present application. This embodiment can be applied to the situation of changing a database table with a large amount of data.
  • the device includes: a target database acquisition module 410, a target change statement parsing module 420, a first change processing module 430, a second change processing module 440 and a target table acquisition module 450.
  • the target database acquisition module 410 is configured to acquire the target database to be changed and the target change statement corresponding to the target database; the target change statement parsing module 420 is configured to parse the target change statement and determine the target change statement in the target database.
  • the first change processing module 430 is configured to correspond to the target change statement based on the The target change type, the target change statement and the table data in the table to be changed, perform table data storage and change processing on the current intermediate table, and record that the table to be changed is within the data processing time period of the current intermediate table
  • the generated first data change log; the second change processing module 440 is configured to perform data changes on the current intermediate table based on the target change type and the first data change log, and record the data of the to-be-changed table in the current intermediate table.
  • the second data change log generated within the data change time period of the table; the target table acquisition module 450 is configured to, if it is determined based on the second data change log that the preset table switching condition is met, based on the target change type, the The second data change log and the current intermediate table are described, and the table to be changed is locked and switched to obtain the changed target table.
  • the technical solution of the embodiment of this application is to obtain the target database and target change statement to be changed, parse the target change statement, and create an intermediate table with the same structure as the table to be changed based on the obtained name of the table to be changed, so as to facilitate utilization
  • the current intermediate table replaces the table to be changed for change processing, so there is no need to lock the table to be changed when the change starts.
  • the target change type corresponding to the target change statement and the table data in the table to be changed perform table data storage and change processing on the current intermediate table, and record the first data generated by the table to be changed within the data processing time period of the current intermediate table. Change log.
  • the data change log realizes data synchronization between the intermediate table and the table to be changed. If based on the second number According to the change log, it is determined that the preset table switching conditions are met, which means that the data difference between the current intermediate table and the table to be changed is small. At this time, the lock switching operation of the table to be changed can be completed in a short time. After obtaining the changes, The target table eliminates the need to lock the table during the entire change process, greatly reducing the table lock time for database table changes and improving user experience.
  • the target database acquisition module 410 is configured to: acquire the target change task currently to be processed from the change task queue, where the change task queue is used to store multiple change tasks created by the user;
  • the target database to be changed is determined, and the target change statement corresponding to the target database in the target change task is obtained.
  • the first change processing module 430 is configured to: if the target change type corresponding to the target change statement is a table structure change, execute the intermediate table change statement corresponding to the target change statement in the current intermediate table, And store the table data in the table to be changed into the current intermediate table after execution; if the target change type corresponding to the target change statement is table data change based on the reference table, then the table data in the table to be changed will be The table data is stored in the current intermediate table, and based on the reference table in the target database, the intermediate table change statement corresponding to the target change statement is executed in the current intermediate table.
  • the first change processing module 440 is configured to: if the target change type is a table structure change, execute the intermediate table change corresponding to the data change statement in the first data change log in the current intermediate table. statement; if the target change type is a table data change based on a reference table, execute the intermediate table change statement corresponding to the data change statement in the first data change log in the current intermediate table, and execute the change statement based on the data change statement in the target database. reference table, and execute the intermediate table change statement corresponding to the target change statement again in the current intermediate table after execution.
  • the target table acquisition module 450 may include:
  • the preset table switching unit is configured to determine the total number of data change statements in the second data change log; if the total number is less than or equal to the preset quantity threshold, it is determined that the preset table switching condition is met.
  • the target table acquisition module 450 may also include:
  • a table-to-be-changed renaming unit is configured to rename the table-to-be-changed to a preset table name that is different from the table-to-be-changed name;
  • a target table acquisition unit is configured to change the table based on the target type, the second data change log and the name of the table to be changed, perform data change and rename operations on the current intermediate table, and obtain the changed target table.
  • the target table acquisition unit can be set to:
  • the database table changing device may also include:
  • the change termination module of the table to be changed is configured to continue to process the current intermediate table based on the target change type and the second data change log if it is determined based on the second data change log that the preset table switching conditions are not met. Perform data changes and record the next data change log generated by the table to be changed within the data change time period of the current intermediate table until it is determined that the preset table switching condition is satisfied based on the next data change log.
  • the database table changing device provided by the embodiments of this application can execute the database table changing method provided by any embodiment of this application, and has the corresponding functional modules and effects for executing the database table changing method.
  • the multiple units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the multiple functional units
  • the names are only for the convenience of distinguishing each other and are not used to limit the scope of protection of this application.
  • FIG. 5 is a schematic structural diagram of an electronic device provided by an embodiment of the present application. 5 illustrates a block diagram of an exemplary electronic device 12 suitable for implementing embodiments of the present application.
  • the electronic device 12 shown in FIG. 5 is only an example and should not bring any limitations to the functions and scope of use of the embodiments of the present application.
  • electronic device 12 is embodied in the form of a general computing device.
  • the components of electronic device 12 may include, but are not limited to: one or more processors or processing units 16, memory 28, and a bus 18 connecting various system components (including memory 28 and processing unit 16).
  • Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics accelerated port, a processor, or a local bus using any of a variety of bus structures.
  • these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (Video Electronics Standards) Association, VESA) local bus and Peripheral Component Interconnect (PCI) bus.
  • Electronic device 12 includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including volatile and nonvolatile media, removable and non-removable media.
  • Memory 28 may include computer system readable media in the form of volatile memory, such as random access Memory (Random Access Memory, RAM) 30 and/or cache memory 32.
  • Electronic device 12 may include other removable/non-removable, volatile/non-volatile computer system storage media.
  • storage system 34 may be configured to read and write to non-removable, non-volatile magnetic media (not shown in Figure 5, commonly referred to as a "hard drive”).
  • a disk drive configured to read and write to removable non-volatile disks (e.g., "floppy disks") and to removable non-volatile optical disks (e.g., Compact Discs) may be provided.
  • System memory 28 may include at least one program product having a set (eg, at least one) of program modules configured to perform the functions of embodiments of the present application.
  • a program/utility 40 having a set of (at least one) program modules 42 may be stored, for example, in memory 28 , each or a combination of these examples may include the implementation of a network environment.
  • Program modules 42 generally perform functions and/or methods in the embodiments described herein.
  • Electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), may also communicate with one or more devices that enable a user to interact with electronic device 12, and/or with Any device (eg, network card, modem, etc.) that enables the electronic device 12 to communicate with one or more other computing devices. This communication may occur through an input/output (I/O) interface 22 .
  • the electronic device 12 can also communicate with one or more networks (such as a local area network (Local Area Network, LAN), a wide area network (Wide Area Network, WAN), and/or a public network, such as the Internet) through the network adapter 20. As shown in FIG.
  • network adapter 20 communicates with other modules of electronic device 12 via bus 18 .
  • other hardware and/or software modules may be used in conjunction with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, disk arrays (Redundant Arrays). of Independent Disks, RAID) systems, tape drives and data backup storage systems, etc.
  • the processing unit 16 executes a variety of functional applications and data processing by running programs stored in the memory 28, for example, implementing the steps of a database table modification method provided by the embodiment of the present invention.
  • the method includes:
  • the current intermediate table with the same structure; based on the target change type corresponding to the target change statement, the target change statement and the table data in the table to be changed, perform the current intermediate table Table data storage and change processing, and record the first data change log generated by the table to be changed within the data processing time period of the current intermediate table; based on the target change type and the first data change log, perform data changes on the current intermediate table, and Record the second data change log generated by the table to be changed within the data change time period of the current intermediate table; if it is determined based on the second data change log that the preset table switching conditions are met, then based on the target change type, the second data change log and For the current intermediate table, lock and switch the table to be changed to obtain the changed target table.
  • processor can also implement the technical solution of the database table modification method provided by any embodiment of the present application.
  • This embodiment provides a computer-readable storage medium on which a computer program is stored.
  • the program is executed by a processor, the database table modification method provided by any embodiment of the present application is implemented.
  • the method includes:
  • the current intermediate table with the same structure; based on the target change type corresponding to the target change statement, the target change statement and the table data in the table to be changed, perform table data storage and change processing on the current intermediate table, and record the table to be changed in the current intermediate table
  • the first data change log generated within the data processing time period; based on the target change type and the first data change log, perform data changes on the current intermediate table, and record the data changes generated by the table to be changed within the data change time period of the current intermediate table.
  • the second data change log if it is determined based on the second data change log that the preset table switching conditions are met, then based on the target change type, the second data change log and the current intermediate table, the table to be changed is locked and switched, and the changed table is obtained. target table.
  • the computer storage medium in the embodiment of the present application may be any combination of one or more computer-readable media.
  • the computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium.
  • the computer-readable storage medium may be, for example, but not limited to: an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. Examples of computer-readable storage media (a non-exhaustive list) include: electrical connections having one or more conductors, portable computer disks, hard drives, RAM, ROM, Erasable Programmable Read-Only Memory, EPROM or flash memory), optical fiber, CD-ROM, optical storage device, magnetic storage device, or any suitable combination of the above.
  • a computer-readable storage medium may be any tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device.
  • a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave carrying computer-readable program code therein. This propagated data signal can use a variety of Forms, including but not limited to electromagnetic signals, optical signals or any suitable combination of the above.
  • a computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device .
  • Program code embodied on a computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, radio frequency (Radio Frequency, RF), etc., or any suitable combination of the above.
  • any appropriate medium including but not limited to: wireless, wire, optical cable, radio frequency (Radio Frequency, RF), etc., or any suitable combination of the above.
  • Computer program code for performing operations of the present application may be written in one or more programming languages, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional Procedural programming language—such as "C" or a similar programming language.
  • the program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server.
  • the remote computer may be connected to the user computer through any kind of network, including a LAN or WAN, or may be connected to an external computer (eg, through the Internet using an Internet service provider).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请提供了数据库表变更方法、装置、设备和存储介质。该数据库表变更方法包括:获取待变更的目标数据库和目标变更语句,对目标变更语句进行解析,确定待变更表名称,并创建与待变更表的结构相同的当前中间表,对当前中间表进行表数据存储和变更处理,并记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志,对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志,若基于第二数据变更日志确定预设表切换条件被满足,对待变更表进行加锁切换,获得变更后的目标表。

Description

数据库表变更方法、装置、设备和存储介质
本申请要求在2022年08月24日提交中国专利局、申请号为202211021950.3的中国专利申请的优先权,该申请的全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机技术,例如涉及数据库表变更方法、装置、设备和存储介质。
背景技术
随着计算机技术的发展,往往需要对数据库表进行变更,比如变更表结构或者更新表数据等。
在对数据库表进行变更时,需要先将数据库表进行锁表处理,并在锁表后对该数据库表进行变更。
上述方案至少存在如下问题:
当数据库表中的数据量较大时,比如为千万级别时,数据库表变更需要较长时间,使得锁表时间较长,从而导致与该数据库表相关的服务长时间不可用,降低了用户体验。
发明内容
本申请提供了数据库表变更方法、装置、设备和存储介质,以大大降低数据库表变更的锁表时间,提升用户体验。
第一方面,本申请提供了一种数据库表变更方法,包括:
获取待变更的目标数据库和目标数据库对应的目标变更语句;
对目标变更语句进行解析,确定目标数据库中的待变更表对应的待变更表名称,并基于待变更表名称,创建与待变更表的结构相同的当前中间表;
基于目标变更语句对应的目标变更类型,目标变更语句和待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志;
基于目标变更类型和第一数据变更日志,对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志;
若基于第二数据变更日志确定预设表切换条件被满足,则基于目标变更类 型、第二数据变更日志和当前中间表,对待变更表进行加锁切换,获得变更后的目标表。
第二方面,本申请还提供了一种数据库表变更装置,包括:
目标数据库获取模块,设置为获取待变更的目标数据库和目标数据库对应的目标变更语句;
目标变更语句解析模块,设置为对目标变更语句进行解析,确定目标数据库中的待变更表对应的待变更表名称,并基于待变更表名称,创建与待变更表的结构相同的当前中间表;
第一变更处理模块,设置为基于目标变更语句对应的目标变更类型,目标变更语句和待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志;
第二变更处理模块,设置为基于目标变更类型和第一数据变更日志,对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志;
目标表获取模块,设置为若基于第二数据变更日志确定预设表切换条件被满足,则基于目标变更类型、第二数据变更日志和当前中间表,对待变更表进行加锁切换,获得变更后的目标表。
第三方面,本申请实施例还提供了一种电子设备,所述电子设备包括:
一个或多个处理器;
存储器,设置为存储一个或多个程序;
当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现上述的数据库表变更方法。
第四方面,本申请还提供了一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现上述的数据库表变更方法。
附图说明
图1是本申请实施例提供的一种数据库表变更方法的流程图;
图2是本申请实施例提供的另一种数据库表变更方法的流程图;
图3是本申请实施例提供的另一种数据库表变更方法的流程图;
图4是本申请实施例提供的一种数据库表变更装置的结构示意图;
图5是本申请实施例提供的一种电子设备的结构示意图。
具体实施方式
下面结合附图和实施例对本申请进行说明。此处所描述的具体实施例仅仅用于解释本申请。为了便于描述,附图中仅示出了与本申请相关的部分。
图1为本申请实施例提供的一种数据库表变更方法的流程图,本实施例可适用于对数据量较大的数据库表进行变更的情况。该方法可以由数据库表变更装置来执行,该装置可以由软件和/或硬件的方式来实现,集成于电子设备中。如图1所示,该方法包括以下步骤:
S110、获取待变更的目标数据库和目标数据库对应的目标变更语句。
目标数据库可以是指需要变更的数据表所在的数据库。目标数据库可以基于业务需求进行设置。目标变更语句可以是指对数据库表的变更修改指令。目标变更语句可以是结构化查询语言(Structured Query Language,SQL)语句。目标变更语句可以基于待变更表的表名称,变更类型以及相应的变更内容进行设置。
可以根据用户创建的变更任务中获取需要变更的目标数据库,以及目标数据库对应的目标变更语句。示例性的,用户可以在操作界面中基于业务需求创建变更任务,其中,变更任务可以包括用户配置的目标数据库链接信息和目标变更语句。将用户创建的一个或多个变更任务存储至变更任务表中,在执行变更任务时,可以间隔固定时间,定时地从变更任务表中取出一项变更任务进行处理,并将该变更任务状态修改为执行中,直至所有变更任务处理完毕。可以基于当前取出的目标变更任务中的目标数据库链接信息确定出相应的目标数据库,以及获取该目标数据库对应的目标变更语句。
示例性地,S110可以包括:从变更任务队列中获取当前待处理的目标变更任务,其中,变更任务队列用于存储用户创建的多个变更任务;基于目标变更任务中的目标数据库链接信息,确定待变更的目标数据库,并获取目标变更任务中的目标数据库对应的目标变更语句。
目标变更任务可以是指当前需要执行的变更任务。例如,目标变更任务可以是对数据库A中的数据库表a的变更任务,还可以是对数据库B中的数据库表b的变更任务。目标数据库链接信息可以是指用于链接目标数据库地址的链接信息,以便基于目标数据库链接信息可以获得需要变更的目标数据库。例如,目标数据库链接信息可以是:xxxx:mysql:/localhost:1111example。
可以将用户创建的多个变更任务根据创建时间的先后顺序依次存储在变更任务队列中。利用变更任务队列,可以在当前变更任务执行完毕后,立即从该队列中取出下一变更任务,无需等到固定时间间隔后再执行下一个变更任务, 从而可以降低延迟,提高可靠性。从变更任务队列中获取当前需要处理的目标变更任务,并基于目标变更任务中的目标数据库链接信息可以确定出需要变更的目标数据库,同时从用户创建的目标变更任务中获取目标数据库对应的目标变更语句。
S120、对目标变更语句进行解析,确定目标数据库中的待变更表对应的待变更表名称,并基于待变更表名称,创建与待变更表的结构相同的当前中间表。
待变更表可以是指目标数据库中的需要执行变更操作的数据库表。待变更表名称在数据库中是唯一的,可以根据待变更表名称查询唯一对应的待变更表。中间表可以是指创建的与待变更表具有相同数据结构的临时表。当前中间表可以是指在当前时刻下获得的中间表。当前中间表中的表数据和/或表结构是动态变化的。例如,创建时获得的当前中间表是一个与待变更表具有相同数据结构的空表。
目标变更语句可以包括需要进行变更的数据库表名称,对目标变更语句进行解析,可以确定出待变更表名称。根据待变更表名称可以获得相应的待变更表,并可以创建出与该待变更表的结构相同的当前中间表,此时的当前中间表为一个空表。例如,对目标变更语句SQL进行解析后,获得的待变更表名称是t1,根据待变更表名称t1可以获得待变更表t1的结构,并根据待变更表t1的结构创建出与结构相同的当前中间表t1_tmp,该中间表的表名称不同于待更新表名称。
S130、基于目标变更语句对应的目标变更类型,目标变更语句和待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志。
目标变更类型可以指对待变更表进行变更的类型。目标变更类型可以包括表结构变更alter table和基于参考表的表数据变更update from等。表结构变更可以是对待变更表中的字段或者索引进行添加、修改和删除等操作。基于参考表的表数据变更可以是将参考表中的字段数据更新到待参考表中的相应字段数据。比如,基于参考表的表数据变更类型的目标变更语句可以是:update from A,B set a2=b2where a.a1=b.b1,该语句表示的是:当待变更表A中的a1字段值与参考表B中的b1字段值相等时,将待变更表A中的a2字段值更新为参考表B中的b2字段值。数据变更日志可以是指用户对待变更表进行变更操作时所记录的二进制日志文件binlog。第一数据变更日志可以是指在当前中间表根据目标变更语句进行变更处理时间段(即第一变更时间段)内用户对待变更表进行操作时所记录的数据变更日志binlog。
根据用户创建的目标变更语句可以确定出待变更表对应目标变更类型。基 于目标变更类型和待变更表中的表数据,对创建的当前中间表进行数据存储和变更操作,同时记录在对当前中间表进行数据存储和变更操作期间(即第一变更时间段)内,用户对待变更表进行变更操作对应的第一数据变更日志。
在根据目标变更语句对当前中间表执行变更操作过程中,用户可以继续对待变更表进行变更操作,从而在第一变更时间段内不会影响与待变更表相关的服务正常运行,并且同时记录在第一变更时间段内用户对待变更表进行变更操作的第一数据变更日志。
S140、基于目标变更类型和第一数据变更日志,对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志。
第二数据变更日志可以是指在当前中间表根据第一数据变更日志进行变更处理时间段(即第二变更时间段)内用户对待变更表进行操作时所记录的数据变更日志binlog。
在S130中当前中间表是指数据量为空的中间表,在S140中当前中间表是指根据目标变更语句进行变更和根据待更新表数据存储后的中间表。S130中的当前中间表和S140中的当前中间表为名称相同,所处阶段不同的中间表,即S140中当前中间表是在S130中执行完变更操作后的中间表。
基于目标变更类型和在第一变更时间段内记录的第一数据变更日志,对当前中间表继续执行数据变更操作,以便将待变更表在第一变更时间段内变更的表数据同步至当前中间表中,并同时记录根据第一数据变更日志对当前中间表数据变更期间(即第二变更时间段)内,用户对待变更表操作的第二数据变更日志。
同理,在根据第一数据变更日志对当前中间表执行变更操作过程中,用户可以继续对待变更表进行变更操作,从而在第二变更时间段内也不会影响与待变更表相关的服务正常运行,并且同时记录在第二变更时间段内用户对待变更表进行变更操作的第二数据变更日志。
S150、若基于第二数据变更日志确定预设表切换条件被满足,则基于目标变更类型、第二数据变更日志和当前中间表,对待变更表进行加锁切换,获得变更后的目标表。
预设表切换条件可以是预先设置的,将中间表可替换为待变更表的条件。例如,预设表切换条件可以是指中间表与待更新表之间的数据差异值小于预设阈值。目标表可以是指对待变更表进行变更后所获得的最终数据库表。S150中当前中间表是在S140中执行完变更操作后获得的中间表。
本实施例可以基于第二数据变更日志检测当前预设表切换条件是否被满足,以确定中间表与待变更表是否接近。若基于第二数据变更日志确定预设表切换条件被满足,则表明当前中间表与待变更表之间的数据差异较小,此时基于目标变更类型、第二数据变更日志和当前中间表,可以利用较短时间完成对待更新表进行加锁切换操作,获取变更后的目标表,从而无需在整个变更过程中进行锁表,大大降低了数据库表变更的锁表时间,提升了用户体验。
示例性地,S150可以包括:确定第二数据变更日志中的数据变更语句的总数量;若总数量小于或等于预设数量阈值,则确定预设表切换条件被满足。
数据变更语句可以是指用户对待变更表进行变更操作时的SQL语句。第二数据变更日志中可以包括在第二变更时间段内用户对待变更表进行的所有变更操作所对应的所有数据变更语句。数据变更语句越多,则表明在第二变更时间段内对待变更表的变更操作次数越多,进而表明中间表与待变更表之间需要同步的数据量也越大。预设数量阈值可以是预先基于业务需求设置的,中间表与待变更表之间的数据差异的最大值。
可以在获得第二数据变更日志后,对第二数据变更日志中的数据变更语句的总数量进行统计,如果第二数据变更日志中的数据变更语句的总数量小于或等于预设数量阈值,则表明当前中间表与待变更表之间的数据差异较小,此时可以确定预设表切换条件被满足,可以对待变更表进行加锁切换。
示例性地,该方法还包括:若基于第二数据变更日志确定预设表切换条件不被满足,则继续基于目标变更类型和第二数据变更日志,对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的下一数据变更日志,直到基于下一数据变更日志确定预设表切换条件被满足为止。
下一数据变更日志可以是指在下一变更时间段内用户对待变更表操作的数据变更日志。例如,在基于第二数据变更日志对当前中间表的变更处理时间段(即下一变更时间段为第三变更时间段)内,用户对待变更表进行操作时所记录的下一数据变更日志为第三数据变更日志,同理,可能还会存在第四数据变更日志、第五数据变更日志等,依次类推。
如果基于第二数据变更日志确定预设表切换条件不被满足,比如,第二数据变更日志中的数据变更语句的总数量大于预设数量阈值,则继续根据目标变更类型和第二数据变更日志,对上次变更获得的当前中间表进行再次数据变更,同时记录在当前中间表数据变更期间内,即第三变更时间段内用户对待变更表进行变更操作的第三数据变更日志,并基于第三数据变更日志检测当前预设表切换条件是否被满足,若预设表切换条件不被满足,则继续基于第三数据变更日志进行数据变更,并同时记录第四数据变更日志,若基于第四数据变更日志 确定预设表切换条件也不被满足,则继续数据变更,并同时记录第五数据变更日志,依次类推,直到预设表切换条件被满足为止。基于预设表切换条件被满足时的数据变更日志,对待变更表进行加锁切换,获得变更后的目标表。
在本实施例中,可以在任意时间段内执行对数据库表的变更操作,无需等到服务低峰期再去变更修改。而且,相对于在待变更表中直接执行变更语句而言,本实施例通过在中间表中执行变更语句,可以随时进行中断,不会影响待变更表相关的服务正常运行。
本申请实施例的技术方案,通过获取待变更的目标数据库和目标变更语句,并对目标变更语句进行解析,基于获得的待变更表名称,创建与待变更表的结构相同的中间表,以便利用当前中间表代替待变更表进行变更处理,从而无需在变更开始时对待变更表进行锁表。根据目标变更语句对应的目标变更类型和待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志。根据第一数据变更日志对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志,从而在对中间表进行变更处理过程中,可以利用数据变更日志实现中间表与待变更表之间的数据同步。若基于第二数据变更日志确定预设表切换条件被满足,则表明当前中间表与待变更表之间的数据差异较小,此时可以利用较短时间完成对待变更表进行加锁切换的操作,获得变更后的目标表,从而无需在整个变更过程中进行锁表,大大降低了数据库表变更的锁表时间,提升了用户体验。
在上述实施例的基础上,S150可以包括:将待变更表重命名为预设表名称;基于目标变更类型、第二数据变更日志和待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表。
预设表名称不同于待变更表名称。预设表名称可以是指预先为待变更表设置的不同于待变更表名称的其他名称,预设表名称可以是与目标数据库中的所有表名称均不相同的其他任意名称。例如,待变更表名称为t1时,预设表名称可以设为t1_bak。
在本实施例中,对待变更表进行加锁切换的操作可以是将待变更表的名称重新命名为预设表名称,根据目标变更类型、第二数据变更日志和待变更表名称,对当前中间表进行数据变更和重命名操作,并将完成数据变更和重命名后的中间表确定为变更后的目标表。
示例性的,将待更新表名称t1重新命名为预设表名称t1_bak,根据目标变更类型、第二数据变更日志和待变更表名称t1,对当前中间表t1_tmp进行数据变更,并将当前中间表名称t1_tmp重命名为待变更表名称t1,从而获得待更新 表更新后的目标表t1。
可以将重新命名为预设表名称的待变更表t1_bak进行暂时存储,以便在目标表t1运行出现故障时,可以基于待变更表t1_bak进行恢复。若目标表t1运行预设时间后没有出现故障,则可以将该暂时存储的待变更表t1_bak删除,以减少数据缓存。
在本实施例中,将待变更表的名称重新命名为预设表名称阶段可以理解为对待变更表进行加锁,将完成重命名的当前中间表确定为目标表可以理解为对待变更表进行解锁,从而仅需要在满足预设切换条件后对待变更表进行锁表,大大降低了数据库表变更时的锁表时间。
示例性地,基于目标变更类型、第二数据变更日志和待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表,可以包括:基于目标变更类型和第二数据变更日志,对当前中间表进行数据变更,并将变更后的当前中间表重命名为待变更表名称,获得变更后的目标表;或者,将当前中间表重命名为待变更表名称,并基于目标变更类型和第二数据变更日志,对重命名后的当前中间表进行数据变更,获得变更后的目标表。
在对当前中间表进行数据变更和重名称操作,获得变更后的目标表时,可以先基于目标变更类型和第二数据变更日志,对当前中间表进行数据变更,然后将变更后的当前中间表重新命名为待变更表名称,获得变更后的目标表。或者,还可以先将当前中间表重命名为待变更表名称,然后基于目标变更类型和第二数据变更日志,对已重新命名后的当前中间表进行数据变更,获得变更后的目标表。本实施例对当前中间表的数据变更操作和重名称操作的先后顺序不进行限定。
图2为本申请实施例提供的另一种数据库表变更方法的流程图,本实施例在上述实施例的基础上,在目标变更语句对应的目标变更类型为表结构变更时,对步骤“基于所述目标变更语句对应的目标变更类型,所述目标变更语句和所述待变更表中的表数据,对当前中间表进行表数据存储和变更处理”、以及步骤“基于所述目标变更类型和所述第一数据变更日志,对当前中间表进行数据变更”进行了进一步说明。其中与上述实施例相同或相应的术语的解释在此不再赘述。
参见图2,本实施例提供的另一种数据库表变更方法包括以下步骤:
S210、获取待变更的目标数据库和目标数据库对应的目标变更语句。
本实施例获取到的目标变更语句为:表结构变更类型的语句,比如alter table语句,以便后续基于该目标变更语句,对目标数据库中的待变更表进行结构变 更。
S220、对目标变更语句进行解析,确定目标数据库中的待变更表对应的待变更表名称,并基于待变更表名称,创建与待变更表的结构相同的当前中间表。
S230、在当前中间表中执行目标变更语句对应的中间表变更语句,并将待变更表中的表数据存储至执行后的当前中间表中。
中间表变更语句可以是指对中间表进行变更的语句,其可以基于目标变变更语句进行确定。例如,用户创建的目标变更语句针对的变更对象是待变更表,从而可以将目标变更语句中的变更对象修改为当前中间表,也就是将目标变更语句中的待变更表名称更新为中间表名称,从而获得中间表变更语句。
针对表结构变更类型,可以先基于中间表变更语句对当前中间表进行表结构变更,也就是在当前中间表中执行中间表变更语句,获得表结构变更后的当前中间表,再将待变更表中的表数据同步存储至表结构变更后的当前中间表中。示例性的,将待变更表中的表数据存储至执行后的当前中间表中的方式可以包括基于普通分页方式和基于标识(Identifier,ID)分段方式。在本实施例中可以基于ID分段方式将待变更表中的表数据存储至执行后的当前中间表中,可以缩短表数据存储时间,比如有1万条数据,每次基于表数据ID可以提取100条数据存储至当前中间表中。若待变更表中没有进行ID分段,则可以通过基于普通分页方式将待变更表中的表数据存储至执行后的当前中间表中。
S240、记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志。
根据中间表变更语句和表结构变更类型对当前中间表执行表结构变更,和记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志,两个步骤是同时执行的,不区分先后顺序,即步骤S230和步骤S240可以同时执行。
S250、在当前中间表中执行第一数据变更日志中的数据变更语句对应的中间表变更语句。
数据变更语句对应的中间表变更语句可以是指对中间表进行变更的语句,其可以基于数据变变更语句进行确定。例如,第一数据变更日志中的数据变更语句针对的变更对象是待变更表,从而可以将数据变更语句中的变更对象修改为中间表,也就是将数据变更语句中的待变更表名称更新为中间表名称,从而获得数据变更语句对应的中间表变更语句。
针对表结构变更类型,可以直接在S230之后获得的当前中间表中执行第一数据变更日志中的数据变更语句对应的中间表变更语句,以便将在第一变更时 间段内用户对待变更表进行的变更操作同步至当前中间表中,从而对当前中间表中的数据进行同步变更。
S260、记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志。
在当前中间表中执行第一数据变更日志中的数据变更语句对应的中间表变更语句,和记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志,两个步骤是同时执行的,不区分先后顺序,即步骤S250和步骤S260可以同时执行。
S270、若基于第二数据变更日志确定预设表切换条件被满足,则将所述待变更表重命名为预设表名称,并基于所述第二数据变更日志和所述待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表。
针对于表结构变更类型而言,基于所述第二数据变更日志和所述待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表,可以包括:
在当前中间表中执行第二数据变更日志中的数据变更语句对应的中间表变更语句,并将执行语句后的当前中间表重命名为所述待变更表名称,获得变更后的目标表;或者,将当前中间表重命名为所述待变更表名称,并在重命名后的当前中间表中执行第二数据变更日志中的数据变更语句对应的中间表变更语句,获得执行语句后的目标表。
本申请实施例的技术方案,在目标变更语句对应的目标变更类型为表结构变更时,通过在当前中间表中执行目标变更语句对应的中间表变更语句,并将待变更表中的表数据存储至执行后的当前中间表中,根据记录的第一数据变更日志,在当前中间表中执行第一数据变更日志中的数据变更语句对应的中间表变更语句,从而可以利用中间表和数据变更日志可以实现表结构变更和数据同步,并且大大缩短数据库表变更的锁表时间,提升用户体验。
图3为本申请实施例提供的另一种数据库表变更方法的流程图,本实施例在上述实施例的基础上,对目标变更语句对应的目标变更类型为基于参考表的表数据变更时,对步骤“基于所述目标变更语句对应的目标变更类型,所述目标变更语句和所述待变更表中的表数据,对当前中间表进行表数据存储和变更处理”、以及步骤“基于所述目标变更类型和所述第一数据变更日志,对当前中间表进行数据变更”进行了进一步说明。其中与上述实施例相同或相应的术语的解释在此不再赘述。
参见图3,本实施例提供的另一种数据库表变更方法包括以下步骤:
S310、获取待变更的目标数据库和目标数据库对应的目标变更语句。
本实施例获取到的目标变更语句为:基于参考表的表数据变更类型的语句,比如update from语句,以便后续基于该目标变更语句,对目标数据库中的待变更表进行基于参考表的表数据变更。
S320、对目标变更语句进行解析,确定目标数据库中的待变更表对应的待变更表名称,并基于待变更表名称,创建与待变更表的结构相同的当前中间表。
S330、将待变更表中的表数据存储至当前中间表,并基于目标数据库中的参考表,在当前中间表中执行目标变更语句对应的中间表变更语句。
中间表变更语句可以是指对中间表进行变更的语句,其可以基于目标变变更语句进行确定。例如,用户创建的目标变更语句针对的变更对象是待变更表,从而可以将目标变更语句中的变更对象修改为当前中间表,也就是将目标变更语句中的待变更表名称更新为中间表名称,从而获得中间表变更语句。
针对基于参考表的表数据变更类型,可以先将待变更表中的表数据同步存储至当前中间表中,然后基于目标数据库中的参考表,在同步存储后的当前中间表中执行中间表变更语句,获得表数据变更后的当前中间表。示例性的,将待变更表中的表数据存储至当前中间表中的方式可以包括基于普通分页方式和基于ID分段方式。在本实施例中可以基于ID分段方式将待变更表中的表数据存储至当前中间表中,可以缩短表数据存储时间,比如有1万条数据,每次基于表数据ID可以提取100条数据存储至当前中间表中。若待变更表中没有进行ID分段,则可以通过基于普通分页方式将待变更表中的表数据存储至当前中间表中。
S340、记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志。
在当前中间表中执行目标变更语句对应的中间表变更语句,和记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志,两个步骤是同时执行的,不区分先后顺序,即步骤S330和步骤S340可以同时执行。
S350、在当前中间表中执行第一数据变更日志中的数据变更语句对应的中间表变更语句,并基于目标数据库中的参考表,在执行后的当前中间表中再次执行目标变更语句对应的中间表变更语句。
数据变更语句对应的中间表变更语句可以是指对中间表进行变更的语句,其可以基于数据变变更语句进行确定。例如,第一数据变更日志中的数据变更语句针对的变更对象是待变更表,从而可以将数据变更语句中的变更对象修改 为中间表,也就是将数据变更语句中的待变更表名称更新为中间表名称,从而获得数据变更语句对应的中间表变更语句。
针对基于参考表的表数据变更类型,可以先在步骤S330之后获得的当前中间表中执行第一数据变更日志中的数据变更语句对应的中间表变更语句,以便将在第一变更时间段内用户对待变更表进行的变更操作同步至当前中间表中,从而对当前中间表中的数据进行同步变更。完成数据同步变更后,基于目标数据库中的参考表,在获得的当前中间表中再次执行目标变更语句对应的中间表变更语句,以便在完成数据同步变更后的当前中间表中进行再次表数据变更,从而保证在整个数据变更过程中,表数据变更的准确性。
S360、记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志。
在执行后的当前中间表中再次执行目标变更语句对应的中间表变更语句,和记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志,两个步骤是同时执行的,不区分先后顺序,即步骤S350和步骤S360可以同时执行。
S370、若基于第二数据变更日志确定预设表切换条件被满足,则将所述待变更表重命名为预设表名称,并基于所述第二数据变更日志和所述待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表。
针对于基于参考表的表数据变更类型而言,基于所述第二数据变更日志和所述待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表,可以包括:
在当前中间表中执行第二数据变更日志中的数据变更语句对应的中间表变更语句,并基于目标数据库中的参考表,在执行后的当前中间表中再次执行目标变更语句对应的中间表变更语句,并将执行语句后的当前中间表重命名为所述待变更表名称,获得变更后的目标表;或者,将当前中间表重命名为所述待变更表名称,并在重命名后的当前中间表中执行第二数据变更日志中的数据变更语句对应的中间表变更语句,并基于目标数据库中的参考表,在执行后的当前中间表中再次执行目标变更语句对应的中间表变更语句,获得再次执行语句后的目标表。
本申请实施例的技术方案,在目标变更语句对应的目标变更类型为基于参考表的表数据变更时,通过将待变更表中的表数据存储至当前中间表,并基于目标数据库中的参考表,在当前中间表中执行目标变更语句对应的中间表变更语句,并根据记录的第一数据变更日志,在当前中间表中执行第一数据变更日 志中的数据变更语句对应的中间表变更语句,并基于目标数据库中的参考表,在执行后的当前中间表中再次执行目标变更语句对应的中间表变更语句,从而可以利用中间表和数据变更日志可以实现基于参考表的表数据变更和数据同步,并且大大缩短数据库表变更的锁表时间,提升用户体验。
以下是本申请实施例提供的数据库表变更装置的实施例,该装置与上述实施例的数据库表变更方法属于同一个构思,在数据库表变更装置的实施例中未详尽描述的细节内容,可以参考上述数据库表变更方法的实施例。
图4为本申请实施例提供的一种数据库表变更装置的结构示意图,本实施例可适用于对数据量较大的数据库表进行变更的情况。如图4所示,该装置包括:目标数据库获取模块410、目标变更语句解析模块420、第一变更处理模块430、第二变更处理模块440和目标表获取模块450。
目标数据库获取模块410,设置为获取待变更的目标数据库和所述目标数据库对应的目标变更语句;目标变更语句解析模块420,设置为对所述目标变更语句进行解析,确定所述目标数据库中的待变更表对应的待变更表名称,并基于所述待变更表名称,创建与所述待变更表的结构相同的当前中间表;第一变更处理模块430,设置为基于所述目标变更语句对应的目标变更类型,所述目标变更语句和所述待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录所述待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志;第二变更处理模块440,设置为基于所述目标变更类型和所述第一数据变更日志,对当前中间表进行数据变更,并记录所述待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志;目标表获取模块450,设置为若基于所述第二数据变更日志确定预设表切换条件被满足,则基于所述目标变更类型、所述第二数据变更日志和当前中间表,对所述待变更表进行加锁切换,获得变更后的目标表。
本申请实施例的技术方案,通过获取待变更的目标数据库和目标变更语句,并对目标变更语句进行解析,基于获得的待变更表名称,创建与待变更表的结构相同的中间表,以便利用当前中间表代替待变更表进行变更处理,从而无需在变更开始时对待变更表进行锁表。根据目标变更语句对应的目标变更类型和待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志。根据第一数据变更日志对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志,从而在对中间表进行变更处理过程中,可以利用数据变更日志实现中间表与待变更表之间的数据同步。若基于第二数 据变更日志确定预设表切换条件被满足,则表明当前中间表与待变更表之间的数据差异较小,此时可以利用较短时间完成对待变更表进行加锁切换的操作,获得变更后的目标表,从而无需在整个变更过程中进行锁表,大大降低了数据库表变更的锁表时间,提升了用户体验。
一实施例中,目标数据库获取模块410,设置为:从变更任务队列中获取当前待处理的目标变更任务,其中,所述变更任务队列用于存储用户创建的多个变更任务;
基于所述目标变更任务中的目标数据库链接信息,确定待变更的目标数据库,并获取所述目标变更任务中的所述目标数据库对应的目标变更语句。
一实施例中,第一变更处理模块430,设置为:若所述目标变更语句对应的目标变更类型为表结构变更,则在当前中间表中执行所述目标变更语句对应的中间表变更语句,并将所述待变更表中的表数据存储至执行后的当前中间表中;若所述目标变更语句对应的目标变更类型为基于参考表的表数据变更,则将所述待变更表中的表数据存储至当前中间表,并基于所述目标数据库中的参考表,在当前中间表中执行所述目标变更语句对应的中间表变更语句。
一实施例中,第一变更处理模块440,设置为:若所述目标变更类型为表结构变更,则在当前中间表中执行所述第一数据变更日志中的数据变更语句对应的中间表变更语句;若所述目标变更类型为基于参考表的表数据变更,则在当前中间表中执行所述第一数据变更日志中的数据变更语句对应的中间表变更语句,并基于所述目标数据库中的参考表,在执行后的当前中间表中再次执行所述目标变更语句对应的中间表变更语句。
一实施例中,目标表获取模块450,可以包括:
预设表切换单元,设置为确定所述第二数据变更日志中的数据变更语句的总数量;若所述总数量小于或等于预设数量阈值,则确定预设表切换条件被满足。
一实施例中,目标表获取模块450,还可以包括:
待变更表重命名单元,设置为将所述待变更表重命名为预设表名称,所述预设表名称不同于所述待变更表名称;目标表获取单元,设置为基于所述目标变更类型、所述第二数据变更日志和所述待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表。
一实施例中,目标表获取单元可以设置为:
基于所述目标变更类型和所述第二数据变更日志,对当前中间表进行数据变更,并将变更后的当前中间表重命名为所述待变更表名称,获得变更后的目 标表;或者,将当前中间表重命名为所述待变更表名称,并基于所述目标变更类型和所述第二数据变更日志,对重命名后的当前中间表进行数据变更,获得变更后的目标表。
一实施例中,数据库表变更装置,还可以包括:
待变更表变更终止模块,设置为若基于所述第二数据变更日志确定足预设表切换条件不被满足,则继续基于所述目标变更类型和所述第二数据变更日志,对当前中间表进行数据变更,并记录所述待变更表在当前中间表的数据变更时间段内产生的下一数据变更日志,直到基于下一数据变更日志确定预设表切换条件被满足为止。
本申请实施例所提供的数据库表变更装置可执行本申请任意实施例所提供的数据库表变更方法,具备执行数据库表变更方法相应的功能模块和效果。
上述数据库表变更装置的实施例中,所包括的多个单元和模块只是按照功能逻辑进行划分的,但并不局限于上述的划分,只要能够实现相应的功能即可;另外,多个功能单元的名称也只是为了便于相互区分,并不用于限制本申请的保护范围。
图5为本申请实施例提供的一种电子设备的结构示意图。图5示出了适于用来实现本申请实施方式的示例性电子设备12的框图。图5显示的电子设备12仅仅是一个示例,不应对本申请实施例的功能和使用范围带来任何限制。
如图5所示,电子设备12以通用计算设备的形式表现。电子设备12的组件可以包括但不限于:一个或者多个处理器或者处理单元16,内存28,连接不同系统组件(包括内存28和处理单元16)的总线18。
总线18表示几类总线结构中的一种或多种,包括存储器总线或者存储器控制器,外围总线,图形加速端口,处理器或者使用多种总线结构中的任意总线结构的局域总线。举例来说,这些体系结构包括但不限于工业标准体系结构(Industry Standard Architecture,ISA)总线,微通道体系结构(Micro Channel Architecture,MAC)总线,增强型ISA总线、视频电子标准协会(Video Electronics Standards Association,VESA)局域总线以及外围组件互连(Peripheral Component Interconnect,PCI)总线。
电子设备12包括多种计算机系统可读介质。这些介质可以是任何能够被电子设备12访问的可用介质,包括易失性和非易失性介质,可移动的和不可移动的介质。
内存28可以包括易失性存储器形式的计算机系统可读介质,例如随机存取 存储器(Random Access Memory,RAM)30和/或高速缓存存储器32。电子设备12可以包括其它可移动/不可移动的、易失性/非易失性计算机系统存储介质。仅作为举例,存储系统34可以设置为读写不可移动的、非易失性磁介质(图5未显示,通常称为“硬盘驱动器”)。尽管图5中未示出,可以提供设置为对可移动非易失性磁盘(例如“软盘”)读写的磁盘驱动器,以及对可移动非易失性光盘(例如只读光盘存储器(Compact Disc Read-Only Memory,CD-ROM),数字视盘(Digital Video Disc-Read Only Memory,DVD-ROM)或者其它光介质)读写的光盘驱动器。在这些情况下,每个驱动器可以通过一个或者多个数据介质接口与总线18相连。系统存储器28可以包括至少一个程序产品,该程序产品具有一组(例如至少一个)程序模块,这些程序模块被配置以执行本申请实施例的功能。
具有一组(至少一个)程序模块42的程序/实用工具40,可以存储在例如内存28中,这样的程序模块42包括但不限于操作系统、一个或者多个应用程序、其它程序模块以及程序数据,这些示例中的每一个或一种组合中可能包括网络环境的实现。程序模块42通常执行本申请所描述的实施例中的功能和/或方法。
电子设备12也可以与一个或多个外部设备14(例如键盘、指向设备、显示器24等)通信,还可与一个或者多个使得用户能与该电子设备12交互的设备通信,和/或与使得该电子设备12能与一个或多个其它计算设备进行通信的任何设备(例如网卡,调制解调器等等)通信。这种通信可以通过输入/输出(Input/Output,I/O)接口22进行。并且,电子设备12还可以通过网络适配器20与一个或者多个网络(例如局域网(Local Area Network,LAN),广域网(Wide Area Network,WAN)和/或公共网络,例如因特网)通信。如图5所示,网络适配器20通过总线18与电子设备12的其它模块通信。应当明白,尽管图中未示出,可以结合电子设备12使用其它硬件和/或软件模块,包括但不限于:微代码、设备驱动器、冗余处理单元、外部磁盘驱动阵列、磁盘阵列(Redundant Arrays of Independent Disks,RAID)系统、磁带驱动器以及数据备份存储系统等。
处理单元16通过运行存储在内存28中的程序,从而执行多种功能应用以及数据处理,例如实现本发实施例所提供的一种数据库表变更方法步骤,该方法包括:
获取待变更的目标数据库和目标数据库对应的目标变更语句;对目标变更语句进行解析,确定目标数据库中的待变更表对应的待变更表名称,并基于待变更表名称,创建与待变更表的结构相同的当前中间表;基于目标变更语句对应的目标变更类型,目标变更语句和待变更表中的表数据,对当前中间表进行 表数据存储和变更处理,并记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志;基于目标变更类型和第一数据变更日志,对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志;若基于第二数据变更日志确定预设表切换条件被满足,则基于目标变更类型、第二数据变更日志和当前中间表,对待变更表进行加锁切换,获得变更后的目标表。
本领域技术人员可以理解,处理器还可以实现本申请任意实施例所提供的数据库表变更方法的技术方案。
本实施例提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现如本申请任意实施例所提供的数据库表变更方法,该方法包括:
获取待变更的目标数据库和目标数据库对应的目标变更语句;对目标变更语句进行解析,确定目标数据库中的待变更表对应的待变更表名称,并基于待变更表名称,创建与待变更表的结构相同的当前中间表;基于目标变更语句对应的目标变更类型,目标变更语句和待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志;基于目标变更类型和第一数据变更日志,对当前中间表进行数据变更,并记录待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志;若基于第二数据变更日志确定预设表切换条件被满足,则基于目标变更类型、第二数据变更日志和当前中间表,对待变更表进行加锁切换,获得变更后的目标表。
本申请实施例的计算机存储介质,可以采用一个或多个计算机可读的介质的任意组合。计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质。计算机可读存储介质例如可以是但不限于:电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的例子(非穷举的列表)包括:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、RAM、ROM、可擦式可编程只读存储器(Erasable Programmable Read-Only Memory,EPROM或闪存)、光纤、CD-ROM、光存储器件、磁存储器件、或者上述的任意合适的组合。在本文件中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。
计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种 形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。
计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、射频(Radio Frequency,RF)等等,或者上述的任意合适的组合。
可以以一种或多种程序设计语言或其组合来编写用于执行本申请操作的计算机程序代码,所述程序设计语言包括面向对象的程序设计语言,诸如Java、Smalltalk、C++,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络,包括LAN或WAN,连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。
本领域普通技术人员应该明白,上述的本申请的多个模块或多个步骤可以用通用的计算装置来实现,它们可以集中在单个计算装置上,或者分布在多个计算装置所组成的网络上,他们可以用计算机装置可执行的程序代码来实现,从而可以将它们存储在存储装置中由计算装置来执行,或者将它们分别制作成多个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本申请不限制于任何特定的硬件和软件的结合。

Claims (11)

  1. 一种数据库表变更方法,包括:
    获取待变更的目标数据库和所述目标数据库对应的目标变更语句;
    对所述目标变更语句进行解析,确定所述目标数据库中的待变更表对应的待变更表名称,并基于所述待变更表名称,创建与所述待变更表的结构相同的当前中间表;
    基于所述目标变更语句对应的目标变更类型,所述目标变更语句和所述待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录所述待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志;
    基于所述目标变更类型和所述第一数据变更日志,对当前中间表进行数据变更,并记录所述待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志;
    在基于所述第二数据变更日志确定预设表切换条件被满足的情况下,基于所述目标变更类型、所述第二数据变更日志和当前中间表,对所述待变更表进行加锁切换,获得变更后的目标表。
  2. 根据权利要求1所述的方法,其中,所述获取待变更的目标数据库和所述目标数据库对应的目标变更语句,包括:
    从变更任务队列中获取待处理的目标变更任务,其中,所述变更任务队列用于存储用户创建的多个变更任务;
    基于所述目标变更任务中的目标数据库链接信息,确定所述待变更的目标数据库,并获取所述目标变更任务中的所述目标数据库对应的目标变更语句。
  3. 根据权利要求1所述的方法,其中,所述基于所述目标变更语句对应的目标变更类型,所述目标变更语句和所述待变更表中的表数据,对当前中间表进行表数据存储和变更处理,包括:
    在所述目标变更语句对应的目标变更类型为表结构变更的情况下,在当前中间表中执行所述目标变更语句对应的中间表变更语句,并将所述待变更表中的表数据存储至执行后的当前中间表中;
    在所述目标变更语句对应的目标变更类型为基于参考表的表数据变更的情况下,将所述待变更表中的表数据存储至当前中间表,并基于所述目标数据库中的参考表,在当前中间表中执行所述目标变更语句对应的中间表变更语句。
  4. 根据权利要求1所述的方法,其中,所述基于所述目标变更类型和所述第一数据变更日志,对当前中间表进行数据变更,包括:
    在所述目标变更类型为表结构变更的情况下,在当前中间表中执行所述第一数据变更日志中的数据变更语句对应的中间表变更语句;
    在所述目标变更类型为基于参考表的表数据变更的情况下,在当前中间表中执行所述第一数据变更日志中的数据变更语句对应的中间表变更语句,并基于所述目标数据库中的参考表,在执行后的当前中间表中再次执行所述目标变更语句对应的中间表变更语句。
  5. 根据权利要求1所述的方法,其中,所述基于所述第二数据变更日志确定预设表切换条件被满足,包括:
    确定所述第二数据变更日志中的数据变更语句的总数量;
    在所述总数量小于或等于预设数量阈值的情况下,确定预设表切换条件被满足。
  6. 根据权利要求1所述的方法,其中,所述基于所述目标变更类型、所述第二数据变更日志和当前中间表,对所述待变更表进行加锁切换,获得变更后的目标表,包括:
    将所述待变更表重命名为预设表名称,其中,所述预设表名称不同于所述待变更表名称;
    基于所述目标变更类型、所述第二数据变更日志和所述待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表。
  7. 根据权利要求6所述的方法,其中,所述基于所述目标变更类型、所述第二数据变更日志和所述待变更表名称,对当前中间表进行数据变更和重名称操作,获得变更后的目标表,包括:
    基于所述目标变更类型和所述第二数据变更日志,对当前中间表进行数据变更,并将变更后的当前中间表重命名为所述待变更表名称,获得变更后的目标表;或者,
    将当前中间表重命名为所述待变更表名称,并基于所述目标变更类型和所述第二数据变更日志,对重命名后的当前中间表进行数据变更,获得变更后的目标表。
  8. 根据权利要求1-7任一项所述的方法,还包括:
    在基于所述第二数据变更日志确定所述预设表切换条件不被满足的情况下,继续基于所述目标变更类型和所述第二数据变更日志,对当前中间表进行数据变更,并记录所述待变更表在当前中间表的数据变更时间段内产生的下一数据变更日志,直到基于下一数据变更日志确定所述预设表切换条件被满足为止。
  9. 一种数据库表变更装置,包括:
    目标数据库获取模块,设置为获取待变更的目标数据库和所述目标数据库对应的目标变更语句;
    目标变更语句解析模块,设置为对所述目标变更语句进行解析,确定所述目标数据库中的待变更表对应的待变更表名称,并基于所述待变更表名称,创建与所述待变更表的结构相同的当前中间表;
    第一变更处理模块,设置为基于所述目标变更语句对应的目标变更类型,所述目标变更语句和所述待变更表中的表数据,对当前中间表进行表数据存储和变更处理,并记录所述待变更表在当前中间表的数据处理时间段内产生的第一数据变更日志;
    第二变更处理模块,设置为基于所述目标变更类型和所述第一数据变更日志,对当前中间表进行数据变更,并记录所述待变更表在当前中间表的数据变更时间段内产生的第二数据变更日志;
    目标表获取模块,设置为在基于所述第二数据变更日志确定预设表切换条件被满足的情况下,基于所述目标变更类型、所述第二数据变更日志和当前中间表,对所述待变更表进行加锁切换,获得变更后的目标表。
  10. 一种电子设备,包括:
    至少一个处理器;
    存储器,设置为存储至少一个程序;
    当所述至少一个程序被所述至少一个处理器执行,使得所述至少一个处理器实现如权利要求1-8中任一所述的数据库表变更方法。
  11. 一种计算机可读存储介质,存储有计算机程序,所述程序被处理器执行时实现如权利要求1-8中任一所述的数据库表变更方法。
PCT/CN2023/091258 2022-08-24 2023-04-27 数据库表变更方法、装置、设备和存储介质 WO2024041022A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211021950.3 2022-08-24
CN202211021950.3A CN115408391A (zh) 2022-08-24 2022-08-24 一种数据库表变更方法、装置、设备和存储介质

Publications (1)

Publication Number Publication Date
WO2024041022A1 true WO2024041022A1 (zh) 2024-02-29

Family

ID=84160751

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/091258 WO2024041022A1 (zh) 2022-08-24 2023-04-27 数据库表变更方法、装置、设备和存储介质

Country Status (2)

Country Link
CN (1) CN115408391A (zh)
WO (1) WO2024041022A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115408391A (zh) * 2022-08-24 2022-11-29 京东科技信息技术有限公司 一种数据库表变更方法、装置、设备和存储介质
CN117171262A (zh) * 2023-08-09 2023-12-05 飞算数智科技(深圳)有限公司 数据同步的方法、装置、存储介质及电子设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101187934A (zh) * 2006-11-21 2008-05-28 国际商业机器公司 用于提供对关系数据库表的高性能数据修改的方法和系统
US20140222872A1 (en) * 2013-02-04 2014-08-07 Bank Of America Corporation Multi-row database updating for enterprise workflow application
CN111966747A (zh) * 2020-07-23 2020-11-20 深圳市科脉技术股份有限公司 数据同步方法、系统、终端设备及存储介质
CN112860697A (zh) * 2021-02-10 2021-05-28 中国工商银行股份有限公司 分布式数据库表结构变更方法、装置及系统
CN115408391A (zh) * 2022-08-24 2022-11-29 京东科技信息技术有限公司 一种数据库表变更方法、装置、设备和存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101187934A (zh) * 2006-11-21 2008-05-28 国际商业机器公司 用于提供对关系数据库表的高性能数据修改的方法和系统
US20140222872A1 (en) * 2013-02-04 2014-08-07 Bank Of America Corporation Multi-row database updating for enterprise workflow application
CN111966747A (zh) * 2020-07-23 2020-11-20 深圳市科脉技术股份有限公司 数据同步方法、系统、终端设备及存储介质
CN112860697A (zh) * 2021-02-10 2021-05-28 中国工商银行股份有限公司 分布式数据库表结构变更方法、装置及系统
CN115408391A (zh) * 2022-08-24 2022-11-29 京东科技信息技术有限公司 一种数据库表变更方法、装置、设备和存储介质

Also Published As

Publication number Publication date
CN115408391A (zh) 2022-11-29

Similar Documents

Publication Publication Date Title
CN109254733B (zh) 用于存储数据的方法、装置和系统
WO2024041022A1 (zh) 数据库表变更方法、装置、设备和存储介质
CN110647579A (zh) 数据同步方法及装置、计算机设备与可读介质
WO2022063284A1 (zh) 数据同步方法、装置、设备及计算机可读介质
US20100199065A1 (en) Methods and apparatus for performing efficient data deduplication by metadata grouping
WO2021184761A1 (zh) 数据访问方法和装置、数据存储方法和装置
CN111339186A (zh) 工作流引擎数据同步方法、装置、介质及电子设备
CN106909597B (zh) 一种数据库迁移方法和装置
US11210277B2 (en) Distributing and processing streams over one or more networks for on-the-fly schema evolution
KR102119258B1 (ko) 데이터베이스 관리 시스템에서의 변경 데이터 캡쳐 구현 기법
CN111949693B (zh) 一种数据处理装置、数据处理方法、存储介质及电子设备
CN112069773A (zh) 数据处理系统、方法、装置、电子设备和计算机可读介质
WO2023273544A1 (zh) 日志文件的存储方法、装置、设备和存储介质
US10262024B1 (en) Providing consistent access to data objects transcending storage limitations in a non-relational data store
CN110633046A (zh) 一种分布式系统的存储方法、装置、存储设备及存储介质
CN113076304A (zh) 一种分布式版本管理方法、装置和系统
CN112163038A (zh) 跨集群数据同步方法、装置、设备及存储介质
US10552394B2 (en) Data storage with improved efficiency
CN109614411B (zh) 数据存储方法、设备和存储介质
US9473561B2 (en) Data transmission for transaction processing in a networked environment
CN109347899B (zh) 在分布式存储系统中写入日志数据的方法
CN113051244B (zh) 数据访问方法和装置、数据获取方法和装置
US8862544B2 (en) Grid based replication
CN112948410A (zh) 数据处理方法、装置、设备及介质
CN117422556B (zh) 基于复制状态机的衍生品交易系统、设备和计算机介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23856116

Country of ref document: EP

Kind code of ref document: A1