Database System and Method for Changing Database Columns
By adding the second column to the physical table of the distributed database and hiding the column in the logical table, the problem of user access failure when column type changes in traditional methods is solved, and a stable column change process is achieved.
Patent Information
- Application Number
- CN202211198909.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-29
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2042-09-29
AI Technical Summary
In distributed databases, when traditional methods perform operations to modify column types, the types of columns in the data table and the physical table of the global secondary index (GSI) cannot be changed at the same time, resulting in the user's write or read access request execution failure.
By adding a second column in the physical data table and the physical GSI table, whose attribute value is the change target value of the first column to be changed, and adding a hidden second column in the logical data table and the logical GSI table, the logical table structure is configured to replace the first column with the second column in the user access logic, and finally delete the first column in the physical table.
The database column changes are implemented without causing user write or read access to fail, ensuring the stability of the column change process and the normal execution of business.
Smart Images

Figure CN115687343B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to databases, and particularly to a solution for column change in a database. Background Art
[0002] With the continuous popularization and deepening of Internet applications, the amount of data to be processed is also increasing continuously, and the performance requirements for databases are getting higher and higher. Distributed databases have received more and more attention.
[0003] A distributed database system implemented based on the idea of distributed database sharding mainly consists of one or more data nodes (DN, also referred to as "storage nodes") and one or more computing nodes (CN).
[0004] Logical tables (also referred to as "logical database tables") are stored on computing nodes, and a logical table can have multiple partitions (shards). The data of each partition is stored in the sub-databases and sub-tables on their respective corresponding data nodes, that is, physical tables (also referred to as "physical database tables").
[0005] When performing database operations, a user can send logical SQL (Structured Query Language) instructions acting on the logical table to the computing node, and then the computing node can send physical SQL instructions acting on the physical table to the data node.
[0006] In addition, the concept of global secondary index (GSI) has also been proposed. GSI is an index outside the data table (in some cases, also referred to as the "main table" or "data main table"), which may contain several columns and the primary key of the main table and adopts different sharding modes. The data in both the data table and GSI is consistent. Both the data table and GSI can respectively have logical tables on computing nodes and physical tables on data nodes.
[0007] A table consists of one or more columns. Information of a certain part of the table is stored in the columns. Each column has its own column name and corresponding column type (data type). Each column stores a specific piece of information. For example, in a personnel information table, one column stores the personnel number, another column stores the personnel name, and the address, city, state, and postal code, etc. are also stored in their respective columns, and each row corresponds to a different person and records their various information.
[0008] In some cases, it is necessary to perform change operations on the attributes of the columns in the table, that is, column change operations. For example, the column name and / or column type can be changed.
[0009] When performing an operation to modify the column type on a distributed database using traditional methods, the types of columns in the physical tables of both the data table and the GSI cannot be changed simultaneously. This may result in different types of columns and data being seen on the main table and the GSI at the same time, leading to the failure of the user's write or read access requests.
[0010] Some database solutions use third-party tools or built-in tools to perform column change operations. Their common feature is that they need to copy the data to a new table, which takes a long time to execute and requires additional dependence on MySQL triggers or Binlogs.
[0011] In some other traditional database solutions, for the operation of column type change, the database system (such as MySQL) on the data node needs to handle it under the condition of locking the table. And if an SQL statement for the corresponding table is to be executed during the locking period, an error will be reported, that is, online column change cannot be achieved. This will affect the normal execution of the business.
[0012] Therefore, there is still a need for an improved database column change solution. Summary of the Invention
[0013] One technical problem to be solved by the present disclosure is to provide a database column change solution that can conveniently implement column change without causing the failure of user write or read access during the column change process.
[0014] According to the first aspect of the present disclosure, there is provided a database column change method. The database has a data table and a global secondary index GSI for the data table. The data table has a logical data table on a computing node and a physical data table on a data node. The GSI has a logical GSI table on a computing node and a physical GSI table on a data node. The method includes: adding a second column to the physical data table and the physical GSI table respectively, and at least one attribute value of the second column in the physical data table and the physical GSI table is the change target value of the corresponding attribute of the first column to be changed in the data table; adding a second column to the structure definitions of the logical data table and the logical GSI table respectively, and making the second column hidden from the user. The second columns in the logical data table and the logical GSI table are respectively associated with the second columns in the physical data table and the physical GSI table, and at least one attribute value of the second columns in the logical data table and the logical GSI table is the change target value; configuring in the structure definitions of the logical data table and the logical GSI table respectively to replace the first column with the second column in the user access logic of the database; deleting the first column from the physical data table and the physical GSI table; and deleting the first column from the structure definitions of the logical data table and the logical GSI table.
[0015] Optionally, the column names of the second columns in the physical data table and the physical GSI table and the column names of the second columns in the logical data table and the logical GSI table are both the changed target values of the column name of the first column.
[0016] Alternatively, optionally, the column names of the second columns in the physical data table and the physical GSI table may be different from the column names of the second columns in the logical data table and the logical GSI table, and the column names of the second columns in the logical data table and the logical GSI table are configured to be mapped to the column names of the second columns in the physical data table and the physical GSI table.
[0017] Optionally, the method may further include: after each change to the structure definitions of the logical data table and the logical GSI table respectively, synchronizing the changed structure definitions of the logical data table and the logical GSI table to all computing nodes.
[0018] Optionally, the operation of synchronizing the changed structure definitions of the logical data table and the logical GSI table to all computing nodes is an atomic operation.
[0019] Optionally, after being configured in the structure definitions of the logical data table and the logical GSI table respectively to use the second column instead of the first column in the user access logic of the database, and after synchronizing the changed structure definitions of the logical data table and the logical GSI table to all computing nodes, perform the step of deleting the first column in the physical data table and the physical GSI table.
[0020] Optionally, the method may further include: after adding the second column and before deleting the first column, making the second columns of the physical data table and the physical GSI table have the same data content as the first columns of the physical data table and the physical GSI table.
[0021] Optionally, the step of making the second columns of the physical data table and the physical GSI table have the same data content as the first columns of the physical data table and the physical GSI table includes: when the first column is displayed to the user and the second column is hidden from the user, configuring in the structure definitions of the logical data table and the logical GSI table respectively to copy the modifications to the first column on the second columns of the physical data table and the physical GSI table respectively; and / or copying the existing data content in the first columns of the physical data table and the physical GSI table respectively to the second columns of the physical data table and the physical GSI table respectively; and / or when the first column is hidden from the user and the second column is displayed to the user, configuring in the structure definitions of the logical data table and the logical GSI table respectively to stop copying the modifications to the first column on the second columns of the physical data table and the physical GSI table respectively, and copying the modifications to the second column on the first columns of the physical data table and the physical GSI table respectively.
[0022] Optionally, before the step of deleting the first column in the physical data table and the physical GSI table, the method further includes: configuring in the respective structure definitions of the logical data table and the logical GSI table to stop copying modifications to the second column on the first column of the physical data table and the physical GSI table respectively.
[0023] Optionally, the attributes of the first column to be changed include the column name and the column type, or only the column name. The step of configuring in the respective structure definitions of the logical data table and the logical GSI table to replace the first column with the second column in the user access logic of the database includes: configuring in the respective structure definitions of the logical data table and the logical GSI table to hide the first column from the user and display the second column to the user.
[0024] Optionally, the attributes of the first column to be changed include the column type. The step of configuring in the respective structure definitions of the logical data table and the logical GSI table to replace the first column with the second column in the user access logic of the database includes: swapping the column names of the first column and the second column in the physical data table and the physical GSI table, or respectively modifying the column names of the first column and the second column in the logical data table and the logical GSI table to map to the column names of the second column and the first column in the physical data table and the physical GSI table; and swapping the column names of the first column and the second column in the respective structure definitions of the logical data table and the logical GSI table.
[0025] Optionally, the database is a distributed database.
[0026] Optionally, the database operates on each column based on the column name.
[0027] According to a second aspect of the present disclosure, there is provided a database system including one or more computing nodes and one or more data nodes, wherein the column change operation is implemented using the method described in the first aspect above.
[0028] According to a third aspect of the present disclosure, there is provided a computing device including: a processor; and a memory storing executable code thereon, which when executed by the processor causes the processor to execute the method described in the first aspect above.
[0029] According to a fourth aspect of the present disclosure, there is provided a computer program product including executable code, which when executed by a processor of an electronic device causes the processor to execute the method described in the first aspect above.
[0030] According to a fifth aspect of the present disclosure, there is provided a non-transitory machine-readable storage medium storing executable code thereon, which when executed by a processor of an electronic device causes the processor to execute the method described in the first aspect above.
[0031] Thus, the column change of the database is conveniently implemented, and the execution of the user write or read access request will not fail during the column change process. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The above and other objects, features, and advantages of the present disclosure will become more apparent by describing the exemplary embodiments of the present disclosure in more detail in conjunction with the accompanying drawings, wherein, in the exemplary embodiments of the present disclosure, the same reference numerals generally represent the same components.
[0033] Figure 1 is a schematic block diagram of a distributed database system.
[0034] Figure 2 is a schematic diagram of a write operation in a database with a global secondary index (GSI).
[0035] Figure 3 is a schematic diagram of a query operation in a database with a global secondary index (GSI).
[0036] Figure 4 is a schematic flowchart of a database column change method according to the present disclosure.
[0037] Figure 5 is a schematic flowchart of a database column change method according to an improved embodiment of the present disclosure.
[0038] Figures 6A to 6H Schematically shows the column change process in one case.
[0039] Figures 7A to 7I Schematically shows the column change process in another case.
[0040] Figure 8 Shows a schematic structural diagram of a computing device that can be used to implement the above database column change method according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0041] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present disclosure will be more thorough and complete, and can fully convey the scope of the present disclosure to those skilled in the art.
[0042] In a distributed database, when performing a column change operation, it is necessary to execute the corresponding physical DDL instructions on all physical tables and modify the logical table structure definition stored in the computing nodes (which can also be called "logical Schema") to make it consistent with the physical table structure definition after the physical DDL (which can also be called "physical Schema").
[0043] DDL is the Data Definition Language. For example, adding columns, changing column types and lengths, adding constraints, etc.
[0044] However, there will be some problems in this process.
[0045] During the process of performing physical column changes, due to the distributed characteristics, it is generally impossible to make all physical DDLs complete at the same time. Therefore, it is impossible to select an exact time point to perform the logical Schema change.
[0046] For example, in some cases, the user changes the column name while changing the column type. In this way, there may be a time point when some physical tables have completed the physical DDL and use the new column name, while another part of the physical tables have not completed the physical DDL and use the old column name. At this time, the query instructions issued by the user will report an error whether they use the new column name or the old column name.
[0047] Or, it is also possible that after the physical column change is executed on the data table, the column change has not been executed on the global secondary index (GSI), and the column types of this column in the data table and GSI are inconsistent.
[0048] On the other hand, the database system may have multiple computing nodes. In this way, during the process of logical Schema change, different computing nodes may see different versions of the logical Schema before and after the change. At this time, it is necessary to ensure that the computing nodes that see different versions of the logical Schema before and after can work properly.
[0049] On the other hand, since column change is not an online DDL operation in MySQL, the DML statements sent to the physical table when the physical table executes DDL will be blocked, thus affecting the normal business execution of users.
[0050] Here, "online DDL operation" refers to a DDL operation that allows the concurrent execution of the user's DML statements during the execution of DDL. DML is the Data Manipulation Language, such as INSERT, UPDATE, DELETE and other statements.
[0051] The present disclosure proposes a novel database column change solution. By adding a new column, switching the access logic between the old and new columns, and deleting the old column, the change of column attributes can be conveniently achieved. For users, the changes to the data table and GSI will not cause the failure of write or read access.
[0052] First, refer to Figures 1 to 3 A brief description is given of the distributed database system to which the column change solution of the present disclosure can be applied.
[0053] Figure 1 is a schematic block diagram of the distributed database system.
[0054] As Figure 1 shown, the distributed database may include one or more computing nodes and one or more data nodes.
[0055] Figure 2 And Figure 3 are respectively schematic diagrams of write and query operations in a distributed database with GSI.
[0056] As Figure 2 And Figure 3 shown, the distributed database includes a logical table in the logical layer and physical tables (sub-database 1, sub-database 2,...) in the physical layer. The logical table may be located on the computing node, while the physical tables are located on the data nodes. Different sub-databases may be located on multiple different data nodes. The logical table may also be located on multiple computing nodes.
[0057] The distributed database has a data table (for example, the main table) and a GSI for providing a global secondary index for the data table such as the main table. The data table and GSI respectively have physical tables (main table sub-table 1, main table sub-table 2; index sub-table 1, index sub-table 2;...) on the data nodes and logical tables on the computing nodes.
[0058] For ease of description, in the present disclosure, the logical table of the data table is referred to as the "logical data table", the physical table of the data table is referred to as the "physical data table" (i.e., Figure 2 And Figure 3 the main table sub-tables in), the logical table of the GSI is referred to as the "logical GSI table", and the physical table of the GSI is referred to as the "physical GSI table" (i.e., Figure 2 And Figure 3 the index sub-tables in).
[0059] It should be understood that in the logical data table, physical data table, logical GSI table, and physical GSI table for the same data table, there are the same columns, only the presentation form or storage form of the columns is different. For ease of description, in the present disclosure, the same columns in the logical data table, physical data table, logical GSI table, and physical GSI table for the same data table are not named separately.
[0060] In the present disclosure, the expressions "first column" and "second column" are only used to distinguish different columns, and do not represent any other meanings such as sequence or priority.
[0061] A user can send a logical SQL (Structured Query Language) instruction acting on a logical table, such as a write instruction or a query instruction, to a compute node. Then, the compute node can send a physical SQL instruction acting on a physical table to a data node.
[0062] Regarding the global secondary index (GSI), it is further described as follows.
[0063] In a distributed database, if a data row and its corresponding index row are stored on the same shard, this kind of index is called a local index. Different from a local index, if a data row and its corresponding index row are stored on different shards, then this kind of index is called a global secondary index, which is mainly used to quickly determine the data shards involved in a query. The two can be used in combination. After the query is sent to a single shard through the GSI, the local index on this shard can improve the query performance within the shard.
[0064] The GSI supports adding split dimensions on demand and provides a globally unique index. Each GSI corresponds to an index table, and XA multi-write is used to ensure strong data consistency between the main table and the index table. Here, "XA transaction" means "distributed transaction".
[0065] If the query dimension is different from the split dimension of the logical table, cross-shard queries may occur. The increase in cross-shard queries will lead to performance problems such as query slowdown and connection pool exhaustion. Using the GSI can reduce cross-shard queries by adding split dimensions and eliminate performance bottlenecks.
[0066] The following refers to Figure 4 Describe a database column change method according to the present disclosure.
[0067] Column change means changing the attribute of a column in a database to a change target value. The attribute to be changed can be, for example, the column name and / or the column type.
[0068] Figure 4 It is a schematic flowchart of a database column change method according to the present disclosure. The database here can be a distributed database.
[0069] Suppose it is necessary to change the attribute of the first column in the database. It should be understood that there is an associated first column in the corresponding logical data table and physical data table, and there is an associated first column in the corresponding logical GSI table and physical GSI table. The first column in the logical GSI table and physical GSI table provides a global secondary index for the first column in the logical data table and physical data table.
[0070] The present disclosure creatively proposes to implement a new online column change solution for a database through online DDL operations such as adding columns, renaming columns, and deleting columns on a database system such as MySQL.
[0071] As Figure 4 shown, in step S410, a second column is added to the physical data table and the physical GSI table respectively. The value of at least one attribute of the second column in the physical data table and the physical GSI table is the attribute change target value of the corresponding attribute of the first column to be changed in the data table. The column change operation expects to change the value of the attribute of the first column to the attribute change target value.
[0072] Thus, a second column is added at the physical layer of the data node.
[0073] The attributes of a column can include, for example, column name, column type, and so on.
[0074] In some cases, the column name of the second column added here can be different from the target value of the column name of the first column.
[0075] In some solutions, the association between the columns of the logical table and the columns of the physical table is realized through the same column name, that is, the columns with the same column name in the logical table and the physical table are associated and correspond to the same column.
[0076] In this case, if the attribute to be changed in the first column includes the column name, then the column name of the second column can be set to the target value of the column name change of the first column. That is, if it is desired to change the column name of the first column to "N", then the column name of the second column in the physical table is set to "N".
[0077] In other solutions, the association between the columns of the logical table and the columns of the physical table is realized through a mapping relationship of column names. In other words, a mapping relationship can be configured to record which column names in the physical table each column name in the logical table corresponds to. The logical table is for the user, and the user can find the desired column name in the logical table. Based on the column name in the logical table, the corresponding column name in the physical table can be determined through the mapping relationship, so as to perform queries based on the corresponding physical table column name in the physical table.
[0078] In this case, if the attributes expected to be changed in the first column include the column name, then the column name of the second column does not have to be set to the target value of the column name change of the first column, but can be set to any column name that meets the general column name conditions (such as non-conflicting and non-repeating). That is, if it is desired to change the column name of the first column to "N", the column name of the second column in the physical table does not have to be set to "N", but can be set to, for example, "M". In this way, the column name of the second column in the logical table can be set to "N" later, and the column name "N" in the logical table can be mapped to the column name "M" in the physical table.
[0079] In addition, the column names of the corresponding columns in the data table and GSI are generally the same. The set of column names of GSI is a subset of the set of column names of the data table.
[0080] In step S420, add a second column to the structure definitions (schemas) of the logical data table and the logical GSI table respectively, and hide the second column from the user.
[0081] It should be understood that the second columns in the logical data table and the logical GSI table are respectively associated with the second columns in the physical data table and the physical GSI table, and the value of at least one attribute of the second columns in the logical data table and the logical GSI table is the above-mentioned target value of the attribute change.
[0082] As described above, in the case where the association between the columns of the logical table and the physical table is achieved through the same column name, if the column name needs to be changed, the column names of the second columns in the physical data table and the physical GSI table set in the above step S410 are the same as the column names of the second columns in the logical data table and the logical GSI table set in step S420, and both are the target values of the column name change. Thus, the association between the newly added second columns in the logical table and the physical table can be achieved.
[0083] On the other hand, in the case where the association between the columns of the logical table and the physical table is achieved through the mapping relationship of the column names, the column name of the second column in the logical table is configured to have the target value of the column name change, while the column name of the second column in the physical table does not necessarily have to be the target value of the column name change. By configuring the column names of the second columns in the logical data table and the logical GSI table to be mapped to the column names of the second columns in the physical data table and the physical GSI table, the association between the two can be achieved.
[0084] Thus, a second column is added to the logical layer of the computing node.
[0085] At this time, the first column has not changed and is still displayed to the user.
[0086] In step S430, configurations are made in the structure definitions of the logical data table and the logical GSI table respectively, so as to replace the first column to be changed with the second column in the user access logic of the database.
[0087] Specifically, configurations can be made in the structure definitions of the logical data table and the logical GSI table respectively, so that the first column to be changed is hidden from the user, while the second column is shown to the user, and the second columns in the logical data table and the logical GSI table are kept associated with the second columns in the physical data table and the physical GSI table respectively.
[0088] Thus, the exchange of the second column and the first column in the user access logic is achieved. For the user, the column (the first column) with the original attribute value is changed to the column (the second column) with the target value of the attribute change. Although two columns are actually replaced, what the user perceives seems to be only the attribute change of one column.
[0089] After that, the user accesses (writes or queries) the second column in the physical table through the second column in the logical table. The second column is shown to the user, while the first column is no longer shown to the user but hidden from the user.
[0090] Next, the configuration operation of step S430 will be further described in detail.
[0091] Here, the column attributes of the first column to be changed may include the column name and / or the column type. For different change attributes, there may be different configuration schemes.
[0092] When the column attributes of the first column to be changed include the column name and the column type, or only include the column name, configurations can be made in the structure definitions of the logical data table and the logical GSI table respectively, so that the first column is hidden from the user, while the second column is shown to the user.
[0093] In this way, the user will see that the column with the column name (and column type) of the second column in the logical table replaces the column with the column name (and column type) of the original first column, as if the column name (and column type) of the original first column has been changed to the column name (and column type) of the second column.
[0094] As described above, the second column in the physical table may have the same column name as the second column in the logical table; or, it may also have a different column name, as long as the column name of the second column in the logical table is mapped to the column name of the second column in the physical table.
[0095] On the other hand, when it is not necessary to change the column names but only the column types are expected to be changed, that is, when the column attributes to be changed in the first column include the column type, the user access logic can be changed by first swapping the association relationships between the column names of the first and second columns in the physical table and the column names of the first and second columns in the logical table, and then swapping the column names of the first and second columns in the logical table. When adding the second column in step S410, since the column attributes expected to be changed do not include the column name, the column name of the second column can be set to any new column name that meets the general column name conditions (such as non-conflicting and non-repeating).
[0096] For example, in the case where the association between the columns of the logical table and the columns of the physical table is achieved through the same column names between the logical table and the physical table, the column names of the first and second columns can be swapped in the physical data table and the physical GSI table first, so as to swap the association relationships between the column names of the first and second columns in the physical table and the column names of the first and second columns in the logical table.
[0097] On the other hand, in the case where the association between the columns of the logical table and the columns of the physical table is achieved through a mapping relationship of column names, the column names of the first and second columns can be swapped in the physical data table and the physical GSI table; alternatively, the column names of the first and second columns in the logical data table and the logical GSI table can also be respectively modified to the column names mapped to the second and first columns in the physical data table and the physical GSI table, so as to swap the association relationships between the column names of the first and second columns in the physical table and the column names of the first and second columns in the logical table. In other words, in this case, it is not necessary to modify the column names of the first and second columns in the physical table, but only the mapping relationships between the first and second columns in the logical table and the physical table need to be modified (swapped).
[0098] At this time, the first and second columns in the physical table have been swapped based on the association relationships with the first and second columns in the logical table, while the column names in the logical table have not been swapped.
[0099] It should be understood that the database can operate on each column based on the column name. Although the first and second columns in different tables can be distinguished by their respective unique and unchanging column IDs, when performing access control, or rather, when sending physical SQL instructions from the logical layer of the computing node to the physical layer of the data node, the column to be accessed can be determined by the column name. In the respective structure definitions of the logical data table and the logical GSI table, the columns displayed to the user and / or the columns hidden from the user can also be configured by the column name. In fact, the write or query requests issued by the user are also based on the column name to determine the column to be accessed.
[0100] In this way, the first column (with the original column name) in the logical data table and the logical GSI table will become associated with the second column (with the original column name or the mapping relationship corresponding to the first column of the logical table after swapping) in the physical data table and the physical GSI table, while the second column (with the new column name) in the logical data table and the logical GSI table will become associated with the first column (with the new column name or the mapping relationship corresponding to the second column of the logical table after swapping) in the physical data table and the physical GSI table.
[0101] At this time, the first column with the original column name in the logical data table and the logical GSI table is still displayed to the user, while the second column with the new column name is hidden from the user. The second column in the physical data table and the physical GSI table that has the original column name or the mapping relationship corresponding to the first column of the logical table after the column name swap or the column name mapping relationship swap is respectively associated with the first column in the logical data table and the logical GSI table, while the first column in the physical data table and the physical GSI table that has the new column name or the mapping relationship corresponding to the second column of the logical table is respectively associated with the second column in the logical data table and the logical GSI table. When the user accesses the first column of the original column type at the logical layer, they actually access the second column of the new column type (the target value of the attribute change) at the physical layer.
[0102] Then, in the respective structure definitions of the logical data table and the logical GSI table, swap the column names of the first column and the second column.
[0103] At this time, the column names in the physical table and the logical table have both been swapped. The second column with the original column name in the logical data table and the logical GSI table is displayed to the user, while the first column with the new column name is hidden from the user. The second column in the logical data table and the logical GSI table has the same column name (the original column name) or a mapping relationship based on the column name as the second column in the physical data table and the physical GSI table, and is thus associated. The first column in the logical data table and the logical GSI table has the same column name (the new column name) or a mapping relationship based on the column name as the first column in the physical data table and the physical GSI table, and is thus associated.
[0104] Thus, the user (in the logical table) will see that the column (the second column) with the original column name and the new column type replaces the original column (the first column) with the original column name and the original column type, as if the original column type of the original first column has changed to the column type (the new column type) of the second column.
[0105] Then, in step S440, the first column can be deleted from the physical data table and the physical GSI table.
[0106] In step S450, delete the first column from the respective structure definitions of the logical data table and the logical GSI table.
[0107] Since the user no longer accesses the first column, the order of steps S440 and S450 can be reversed or they can be executed synchronously.
[0108] As described above, the database system may have multiple computing nodes, and each computing node may have a logical data table and a logical GSI table.
[0109] After each change to the structure definitions of the logical data table and the logical GSI table respectively, the changed structure definitions of the logical data table and the logical GSI table can be synchronized to all computing nodes.
[0110] The synchronization of the structure definition (logical Schema) of the logical table means that the updated structure definition is sent from the computing node that executes the DDL to all computing nodes, and after this operation, all computing nodes will see the updated structure definition (logical Schema).
[0111] It should be noted that each synchronization operation is atomic, that is, an atomic operation.
[0112] An atomic operation refers to one or a series of operations that cannot be interrupted. The synchronization operation may contain a series of operations. Since the synchronization operation is atomic, after the synchronization operation ends, either all computing nodes will see the updated state, or they will all see the state before the update. There will be no situation where some nodes succeed and some nodes fail, nor will there be a situation where a certain node sees partial success in this series of operations at a certain moment.
[0113] In this way, the modifications to the logical data table and the logical GSI table will either both succeed or both fail, without any other intermediate results.
[0114] In this way, after completing the configuration operation in step S430 and synchronizing the structure definitions of the changed logical data table and the logical GSI table to all computing nodes, the column deletion operations in steps S440 and S350 described above can be executed.
[0115] It has been referred to above Figure 4 It has been described that by adding a second column with the target value of the attribute change and replacing the first column with the second column, the attribute change of the first column can be achieved from the user's perspective.
[0116] In some cases, such as when performing column change operations online, the first column may already have some data content before the change, and during the change process, the user may also perform modification access operations on the first column or the second column. Therefore, after step S420 adds the second column to the structure definition of the logical table and before step S440 deletes the first column from the physical table, it is also possible to further make the second column of the physical data table and the physical GSI table have the same data content as the first column of the physical data table and the physical GSI table.
[0117] In this way, while successfully implementing the column change, it is also possible to further ensure the retention and continuation of the data content in the column.
[0118] Figure 5 is a schematic flowchart of a database column change method according to an improved embodiment of the present disclosure.
[0119] Figure 5 The method shown includes steps S410 to S450 described above with reference to Figure 4 These steps may be the same as those described above with reference to Figure 4 described.
[0120] Figure 5 The newly added steps S510 to S540 in are respectively used to synchronize different data contents or data modifications initiated by the user between the first column and the second column at different times, so that the first column and the second column have the same data content. It should be understood that in the database column change method of the improved embodiment, only any one of steps S510 to S540 may be included, or any two or three of them may be included in combination, or all of them may be included.
[0121] As Figure 5 shown, after step S420, when the first column is displayed to the user and the second column is hidden from the user, in step S510, it is possible to configure in the structure definitions of the logical data table and the logical GSI table respectively, so that the modifications to the first column are copied on the second column of the physical data table and the physical GSI table respectively. Such a modification copying operation can be called a "column multi-write" operation.
[0122] More generally speaking, the column multi-write operation means that when the user writes a value to a certain column in the logical table through the logical DML, a copy is made to another column in the physical DML in the physical table. This operation can be enabled through the configuration item of the logical table structure definition (logical Schema) on the computing node.
[0123] Thus, before adding the second column and before implementing the replacement change between the first column and the second column, the second column can receive the same modification operations as the first column, so that the new data content of the modification remains consistent between the two columns.
[0124] In other words, through the column multi-write operation, the data content of the second column of the physical data table and the physical GSI table is made consistent with the data content of the first column of the physical data table and the physical GSI table.
[0125] In the case where the first column may already have data content, in step S520, the existing data content in the first column of each of the physical data table and the physical GSI table can also be copied to the second column of each of the physical data table and the physical GSI table. Such a content copying operation can be referred to as a "column backfill" operation.
[0126] More generally speaking, the column backfill operation refers to copying the value of a certain column in the physical table to another column. This operation is completed in the data node.
[0127] In this way, the second column can have the historical data content that the first column previously had.
[0128] On the other hand, after step S430, in the case where the first column is hidden from the user and the second column is displayed to the user, in step S530, it can be configured in the structure definitions of each of the logical data table and the logical GSI table so that the copying of the modification to the first column on the second column of each of the physical data table and the physical GSI table is stopped (that is, the aforementioned column multi-write operation is stopped), and the modification to the second column is copied on the first column of each of the physical data table and the physical GSI table. The modification copying operation here can also be referred to as a "column multi-write" operation, or can also be referred to as a "reverse column multi-write" operation. In other words, in step S530, the direction of the column multi-write operation is modified.
[0129] In this way, the same data content can be maintained between the first column and the second column before the first column is deleted to avoid potential user access failures.
[0130] For example, in the case where there are multiple computing nodes, if in step S430, in one computing node, the structure definitions of each of the logical data table and the logical GSI table are configured to replace the first column to be changed with the second column in the user access logic of the database, and the modified structure definitions have not been synchronized to all computing nodes, then in the structure definitions of each of the logical data table and the logical GSI table on some computing nodes, the user still accesses the first column. In this way, it is necessary to continue to maintain the same data content between the first column and the second column so that the new data content modified by the user on the second column can also be synchronized to the first column.
[0131] It should be understood that in the above description of step S430, when the attribute to be changed is the column type and the column name does not need to be changed, after the column names of the first column and the second column are exchanged in the physical table and the logical table successively, the direction of column multi-writing has also been automatically adjusted accordingly. This is also because, as described above, operations on each column in the database are based on the column names. After the column names are exchanged, the corresponding direction of column multi-writing operation is also modified in the reverse direction.
[0132] When the structure definitions of the logical data table and the logical GSI table configured in step S430, for example, have been synchronized to all computing nodes, in step S540, it is possible to configure in the structure definitions of the logical data table and the logical GSI table respectively to stop copying the modifications to the second column on the first column of the physical data table and the physical GSI table, that is, to stop the reverse column multi-writing operation.
[0133] After that, steps S440 and S450 can be executed to delete the first column in the physical table and the data table respectively without worrying about data content loss.
[0134] The following refers to Figures 6A to 6H and Figures 7A to 7I to further describe in detail the solutions for column changes in two cases in the embodiments of the present disclosure.
[0135] Suppose there is a table T. In the database, corresponding to table T, there are a logical data table, a physical data table; a logical GSI table, and a physical GSI table. Specifically, the GSI table provides a global secondary index for the data table, and the data table and the GSI table each have a logical table and a physical table.
[0136] Since the same operations need to be performed on both the data table and the GSI table, therefore in Figures 6A to 6H and Figures 7A to 7I for table T, only one table is shown as a schematic for both the logical table and the physical table.
[0137] To perform a column change operation on a column in table T, the column name of the column to be changed is "A", and the column type is "L1".
[0138] According to the attributes to be modified for this column, it can be divided into two cases:
[0139] (1) Modify the type of column A from L1 to L2 and modify the column name to "B";
[0140] (2) Modify the type of column A from L1 to L2 without modifying the column name.
[0141] The following refers to Figures 6A to 6H to describe the column change process in the first case.
[0142] Figures 6A to 6HSchematically shows the column change process in the first case.
[0143] Figure 6A Schematically shows the initial state. In the figure, solid arrows represent write operations, and dashed arrows represent read operations. For columns A and the list involved here, the columns pointed to by the user's read / write arrows are visible to the user, and the columns not pointed to are invisible to the user.
[0144] As Figure 6A shown, both the logical table and the physical table have a column (the first column) with the column name "A" and the column type "L1". Column A is visible to the user, that is, the user can perform write / read operations on column A. Figure 6A The write / read operations on column A are represented by a solid arrow pointing to column A and a dashed arrow leading from column A, indicating that column A is visible to the user.
[0145] As described above, although they can be distinguished by, for example, their unique and invariant column IDs respectively, when performing access control, or rather, when sending physical SQL instructions from the logical layer of the computing node to the physical layer of the data node, the column to be accessed can be determined by the column name. In the following text, the column name is used to represent the column.
[0146] For the column change operation described below, from the user's perspective, the column name of column A is changed to "B", and the column type is changed to "L2". The column name "B" and the column type "L2" are the target values for the attribute change of column A.
[0147] As Figure 6B shown, a new column (the second column) with the column name "B" and the column type "L2" is added to the physical data table and the physical GSI table.
[0148] Here, the case where the logical table and the physical table are associated through the same column name to realize the association between the columns of the logical table and the columns of the physical table is taken as an example for description. It should be understood that any other column name, such as "C", can also be set for the second column added to the physical table, and after adding the second column to the logical table later, it can be set that the column B added to the logical table is mapped to the column C in the physical table. In this case, the "column B" in the physical table mentioned in the following text can be replaced by "column C".
[0149] At this time, in the structure definitions (logical Schema) of the logical data table and the logical GSI table, column B (the second column) does not exist in table T1 yet, so column B is invisible to the user.
[0150] Next, as Figure 6C shown, modify the structure definitions of the logical data table and the logical GSI table to add column B, but it is hidden from the user, so column B remains invisible to the user.
[0151] Meanwhile, column multi-write operations can be enabled for the data table and the GSI table, that is, all modifications made by the user to column A are copied to column B. Figure 6C This is indicated by a horizontal arrow pointing from column A to column B in the logical table.
[0152] In addition, the structure definitions of the modified logical data table and the logical GSI table can be synchronized to all computing nodes. As described above, this synchronization operation can be an atomic operation.
[0153] As Figure 6D shown, column backfilling operations can be performed on the physical data table and the physical GSI table, that is, all the contents in column A of the physical table are copied to column B. Figure 6D This is indicated by a horizontal arrow pointing from column A to column B in the physical table.
[0154] After Figure 6D the column backfilling operation shown is completed, as Figure 6E shown, column A is hidden and column B is displayed in the structure definitions of the logical data table and the logical GSI table, and the user sees the modified result, that is, column B. In other words, the user can access (read / write) column B and no longer access column A.
[0155] Meanwhile, the direction of column multi-write can be modified, that is, all modifications made by the user to column B are copied to column A. Figure 6E This is indicated by a horizontal arrow pointing from column B to column A in the logical table.
[0156] In addition, the structure definitions of the modified logical data table and the logical GSI table can be synchronized to all computing nodes. As described above, this synchronization operation can be an atomic operation.
[0157] Then, as Figure 6F shown, the structure definitions of the logical data table and the logical GSI table can be modified to stop column multi-write.
[0158] In addition, the structure definitions of the modified logical data table and the logical GSI table can be synchronized to all computing nodes.
[0159] Thus, as Figure 6G shown, column A can be deleted from the physical data table and the physical GSI table.
[0160] Furthermore, as Figure 6H shown, the structure definitions of the logical data table and the logical GSI table can be modified to delete column A.
[0161] In addition, the structure definitions of the modified logical data table and the logical GSI table can be synchronized to all computing nodes.
[0162] Thus, by adding Column B, switching column access logic, and deleting Column A, Column A was replaced by Column B. From the user's perspective, the original column with column type "L1" and column name "A" was changed to a column with column type "L2" and column name "B".
[0163] Next, refer to Figures 7A to 7I to describe the column change process in the above-mentioned second case.
[0164] Figures 7A to 7I Schematically shows the column change process in the above-mentioned second case.
[0165] Figure 7A Schematically shows the initial state. As Figure 7A shown, the logical table and the physical table have a column (the first column) with column name "A" and column type "L1", and Column A is visible to the user.
[0166] In the following description, the column name exchange of two columns is involved. From the user's perspective and / or from the perspective of the database control logic, the column names are still used to refer to each column. However, it should be understood that the same column name actually refers to different columns before and after the column name exchange. This can be understood by referring to the "first column" and "second column" (equivalent to the unique column identifier such as column ID that remains unchanged) noted in the brackets.
[0167] For the column change operation described below, from the user's perspective, the column type of Column A is changed to "L2", while the column name remains the same, still "A". The column type "L2" is the target value for the attribute change of Column A.
[0168] As Figure 7B shown, a column (the second column) with column name "A'" and column type "L2" is added to the physical data table and the physical GSI table.
[0169] At this time, in the structure definition (logical Schema) of the logical data table and the logical GSI table, Column A' (the second column) does not exist in Table T1 yet, so Column A' is not visible to the user.
[0170] Next, as Figure 7C shown, modify the structure definition of the logical data table and the logical GSI table to add Column A', but it is hidden from the user, so Column A' is still not visible to the user.
[0171] Here, a case where the columns of the logical table and the physical table are associated through the same column name is described as an example. It should be understood that the column names of the columns added in the logical table can be different from the column names of the columns added in the physical table. For example, the column name of the column added in the physical table is set to "D", and the column A' in the logical table can be mapped to the column D in the physical table. In this case, the "column A'" in the physical table mentioned below can be replaced with "column D".
[0172] At the same time, the column multi-write operation is enabled. All modifications made by the user to column A are copied once on column A'. Figure 7C In, it is indicated by a horizontal arrow from column A to column A' in the logical table.
[0173] In addition, the structure definitions of the changed logical data table and the logical GSI table can be synchronized to all computing nodes. As described above, this synchronization operation can be an atomic operation.
[0174] As Figure 7D shown, a column backfill operation can be performed on the physical data table and the physical GSI table, that is, all the contents in column A of the physical data table and the physical GSI table are copied to column A'. Figure 7D In, it is indicated by a horizontal arrow from column A to column A' in the physical table.
[0175] In Figure 7D After the column backfill operation shown is completed, as Figure 7E shown, the column names of column A and column A' (the first column and the second column) are exchanged in the physical data table and the physical GSI table.
[0176] After the exchange is completed, in the physical data table and the physical GSI table, the column type of column A (the second column) is "L2", and the column type of column A' (the first column) is "L1".
[0177] Here, a case where the columns of the logical table and the physical table are associated through the same column name is described as an example, and the column names of the first column and the second column in the physical table are exchanged. As described above, the mapping relationship between the first column and the second column in the physical table and the first column and the second column in the logical table can also be exchanged to achieve the exchange of the association relationship.
[0178] Next, as Figure 7F shown, the column names of column A and column A' (the first column and the second column) are exchanged in the structure definitions of the logical data table and the logical GSI table.
[0179] After the exchange is completed, viewed by column name, column A' (which has actually been replaced by the first column) is still hidden. The user sees that the type of column A (which has actually been replaced by the second column) after modification is "L2".
[0180] At this time, Figure 7E the column reverse writing operation from column A (the first column) to column A' (the second column) in Figure 7F has been naturally converted to the column reverse writing operation from column A (the second column) to column A' (the first column) after the column name exchange in
[0181] In addition, the structure definitions of the changed logical data table and logical GSI table can be synchronized to all computing nodes.
[0182] Then, as Figure 7G shown, the structure definitions of the logical data table and logical GSI table can be modified to stop column multi-writing.
[0183] In addition, the structure definitions of the changed logical data table and logical GSI table are synchronized to all computing nodes.
[0184] Thus, as Figure 7H shown, column A' (the first column) can be deleted from the physical data table and physical GSI table.
[0185] Furthermore, as Figure 7I shown, the structure definitions of the logical data table and logical GSI table can be modified to delete column A' (the first column).
[0186] In addition, the structure definitions of the changed logical data table and logical GSI table can be synchronized to all computing nodes.
[0187] Thus, by adding column A', exchanging column names, and deleting column A, the original column is replaced by the newly added column. From the user's perspective, the column with the original column type "L1" and column name "A" is changed to a column with column type "L2" and still column name "A".
[0188] The column change solution of the present disclosure is executed by transforming the physical column change operation into physical column addition, column renaming, and column subtraction, so that when the distributed database performs column change, the change of the structure definition (logical Schema) of the logical table is not affected by the different completion times of the structure definition (physical Schema) of the physical table, and it can ensure that the logical Schema can select a specific time point for change, so that the user can see a unified change time point, and the change takes effect on the main table (data table) and GSI simultaneously.
[0189] Moreover, in MySQL, adding columns, renaming columns, and dropping columns are all online DDLs. The column change solution of the present disclosure can use the operation of changing column types of online DDLs natively supported by MySQL. Therefore, the physical DDLs involved in this solution will not block the execution of DMLs concurrently executed by users, avoiding the problem that the original column change operations need to block user DMLs, and there is no need to additionally use Binlog or triggers.
[0190] When performing column changes through the column change solution of the present disclosure, users can always access data through the old columns until the logical Schema is switched. After the logical Schema is switched, they can directly access through the new columns. Therefore, the situation where access to both new and old columns may go wrong when the physical DDL is partially completed will not occur.
[0191] Moreover, since the logical switch of the main table (data table) and the GSI table is an atomic operation, the user's view of the logical Schemas of the main table (data table) and the GSI table must be consistent.
[0192] In addition, in the case of multiple computing nodes, for all logical Schema operations, the column change solution of the present application allows different computing nodes to simultaneously have different logical Schemas before and after the update without affecting the correctness of read and write access until all computing nodes are synchronized. The logical Schema operations (structural definition configuration of logical tables) involved in the column change solution of the present disclosure are analyzed and elaborated below.
[0193] (1) Regarding the operations of adding a new column (step S420) and enabling multi-write for columns (step S510) in the logical Schema.
[0194] In the old version of the logical Schema, the newly added column does not exist, and it cannot be read, nor can it be written to.
[0195] Although the new column has been added in the new version of the logical Schema, the column is hidden from the user. When writing to the old column, the computing node will automatically copy a user's write to the new column (column multi-write). And what the user reads is still the old column. Therefore, the possible data loss of the new column at this time will not affect the user's reading. So, normal access can be achieved through different versions of the logical Schema before and after the change.
[0196] (2) Regarding the operations of changing the column name and column type or changing the column name, where the old column is hidden and the new column is displayed in the logical Schema, or when changing the column type, the column names are swapped in the logical Schema (step S430).
[0197] At this time, after the column filling operation (step S520), the data contents of the new and old columns are the same. The old version logical Schema still accesses the old column, but the data content written through the new version logical Schema will be automatically copied to the old column (step S530). Therefore, the situation where the data content written through the new version logical Schema cannot be read will not occur.
[0198] Similarly, the data content written through the old version logical Schema will be automatically copied to the new column, so the new version logical Schema can also read the data content written through the old version logical Schema.
[0199] Therefore, normal access can be achieved through the logical Schemas of different versions before and after the change.
[0200] (3) Regarding the operation of stopping multiple writes to columns in the logical Schema (step S540).
[0201] At this time, the logical Schemas of the new and old versions both read through the new column, so stopping multiple writes to columns will not affect the data read by the user.
[0202] (4) Regarding the operation of deleting the old column in the logical Schema (step S450).
[0203] At this time, the logical Schemas of the new and old versions no longer access this column, so the logical Schemas of different versions can all achieve normal access.
[0204] Figure 8 The structural schematic diagram of a computing device that can be used to implement the above database column change method according to an embodiment of the present invention is shown.
[0205] See Figure 8 , the computing device 800 includes a memory 810 and a processor 820.
[0206] The processor 820 can be a multi-core processor or can include multiple processors. In some embodiments, the processor 820 can include a general-purpose main processor and one or more special coprocessors, such as a graphics processing unit (GPU), a digital signal processor (DSP), etc. In some embodiments, the processor 820 can be implemented using custom circuits, such as an application specific integrated circuit (ASIC) or a field programmable gate array (FPGA).
[0207] The memory 810 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, the ROM can store static data or instructions required by the processor 820 or other modules of the computer. The permanent storage device can be a readable and writable storage device. The permanent storage device can be a non-volatile storage device that does not lose the stored instructions and data even when the computer is powered off. In some embodiments, the permanent storage device employs a mass storage device (such as a magnetic or optical disk, flash memory) as the permanent storage device. In some other embodiments, the permanent storage device can be a removable storage device (such as a floppy disk, optical drive). The system memory can be a readable and writable storage device or a volatile readable and writable storage device, such as dynamic random access memory. The system memory can store some or all of the instructions and data required by the processor during operation. In addition, the memory 810 can include any combination of computer-readable storage media, including various types of semiconductor storage chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and magnetic disks and / or optical disks can also be used. In some embodiments, the memory 810 can include a removable storage device that is readable and / or writable, such as a compact disc (CD), read-only digital versatile disc (such as DVD-ROM, dual-layer DVD-ROM), read-only Blu-ray disc, ultra density optical disc, flash memory card (such as SD card, min SD card, Micro-SD card, etc.), magnetic floppy disk, and so on. The computer-readable storage medium does not include carrier waves and instantaneous electronic signals transmitted wirelessly or wired.
[0208] Executable code is stored on the memory 810, and when the executable code is processed by the processor 820, it can cause the processor 820 to execute the database column change method described above.
[0209] The database column change method according to the present invention has been described in detail above with reference to the accompanying drawings.
[0210] In addition, the method according to the present invention can also be implemented as a computer program or a computer program product, which includes computer program code instructions for performing the above steps defined in the above method of the present invention.
[0211] Alternatively, the present invention can also be implemented as a non-transitory machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium), on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or a computing device, a server, etc.), it causes the processor to execute each step of the above method according to the present invention.
[0212] Those skilled in the art will also understand that the various exemplary logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein can be implemented as electronic hardware, computer software, or a combination of both.
[0213] The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems and methods according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram may represent a module, a segment of code, or a part thereof, which contains one or more executable instructions for implementing the specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the figures. For example, two consecutive blocks may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or by a combination of dedicated hardware and computer instructions.
[0214] The embodiments of the present invention have been described above. The above description is exemplary and not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, the practical application, or the improvement of technologies in the market, or to enable other ordinary skilled in the art to understand the embodiments disclosed herein.
Claims
1. A method for database column change, the database having a data table and a global secondary index GSI for the data table, the data table having a logical data table on a computing node and a physical data table on a data node, the GSI having a logical GSI table on a computing node and a physical GSI table on a data node, the method comprising: Adding a second column to the physical data table and the physical GSI table respectively, and the value of at least one attribute of the second column in the physical data table and the physical GSI table being the change target value of the corresponding attribute of the first column to be changed in the data table; Adding a second column to the respective structure definitions of the logical data table and the logical GSI table and hiding the second column from the user, the second columns in the logical data table and the logical GSI table being associated with the second columns in the physical data table and the physical GSI table respectively, and the value of the at least one attribute of the second columns in the logical data table and the logical GSI table being the change target value; Configuring in the respective structure definitions of the logical data table and the logical GSI table to modify the column names of the first column and the second column in the logical data table and the logical GSI table to the column names that map to the second column and the first column in the physical data table and the physical GSI table respectively, so as to replace the first column with the second column in the user access logic of the database, and the second column being displayed to the user; Deleting the first column from the physical data table and the physical GSI table; And Deleting the first column from the respective structure definitions of the logical data table and the logical GSI table; After each change to the respective structure definitions of the logical data table and the logical GSI table, synchronizing the changed structure definitions of the logical data table and the logical GSI table to all computing nodes.
2. The method according to claim 1, wherein The column names of the second columns in the physical data table and the physical GSI table and the column names of the second columns in the logical data table and the logical GSI table are both the change target values of the column name of the first column; Or The column names of the second columns in the logical data table and the logical GSI table are configured to map to the column names of the second columns in the physical data table and the physical GSI table.
3. The method according to claim 1, wherein The operation of synchronizing the changed structure definitions of the logical data table and the logical GSI table to all computing nodes is an atomic operation.
4. The method according to claim 1, wherein After configuring in the respective structure definitions of the logical data table and the logical GSI table to replace the first column with the second column in the user access logic of the database and synchronizing the changed structure definitions of the logical data table and the logical GSI table to all computing nodes, performing the step of deleting the first column from the physical data table and the physical GSI table.
5. The method according to claim 1, further comprising: After adding the second column and before deleting the first column, making the second columns of the physical data table and the physical GSI table have the same data content as the first columns of the physical data table and the physical GSI table.
6. The method according to claim 5, wherein, The step of making the second columns of the physical data table and the physical GSI table have the same data content as the first columns of the physical data table and the physical GSI table includes: When the first column is displayed to the user and the second column is hidden from the user, configure in the structure definitions of the logical data table and the logical GSI table respectively, so that modifications to the first column are replicated on the second column of the physical data table and the physical GSI table respectively; and / or Copy the existing data content in the first column of the physical data table and the physical GSI table respectively to the second column of the physical data table and the physical GSI table respectively; and / or When the first column is hidden from the user and the second column is displayed to the user, configure in the structure definitions of the logical data table and the logical GSI table respectively, so that replication of modifications to the first column on the second column of the physical data table and the physical GSI table respectively is stopped, and modifications to the second column are replicated on the first column of the physical data table and the physical GSI table respectively.
7. The method according to claim 6, wherein, Before the step of deleting the first column in the physical data table and the physical GSI table, the method further includes:[[]] Configure in the structure definitions of the logical data table and the logical GSI table respectively to stop replicating modifications to the second column on the first column of the physical data table and the physical GSI table respectively.
8. The method according to claim 1, wherein The attributes to be changed in the first column include the column name and the column type, or only the column name. The step of configuring in the structure definitions of the logical data table and the logical GSI table respectively to replace the first column with the second column in the user access logic of the database includes:[[]] Configure in the structure definitions of the logical data table and the logical GSI table respectively to hide the first column from the user,[[]] And / or,[[]] The attributes to be changed in the first column include the column type. The step of configuring in the structure definitions of the logical data table and the logical GSI table respectively to replace the first column with the second column in the user access logic of the database further includes:[[]] Exchange the column names of the first column and the second column in the physical data table and the physical GSI table; and Exchange the column names of the first column and the second column in the structure definitions of the logical data table and the logical GSI table respectively.
9. The method according to claim 8, wherein The database is a distributed database; and / or The database operates on each column based on the column name.
10. A database system includes one or more computing nodes and one or more data nodes, wherein, Use the method according to any one of claims 1 to 9 to implement the column change operation.
11. A computing device, comprising:[[]] A processor; And A memory having executable code stored thereon, which when executed by the processor causes the processor to execute the method according to any one of claims 1 to 9.
12. A computer program product, comprising executable code, which when executed by a processor of an electronic device causes the processor to execute the method according to any one of claims 1 to 9.
13. A non-transitory machine-readable storage medium having executable code stored thereon, which when executed by a processor of an electronic device causes the processor to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Create table for exchange
CN108369587A
Cross-regional quick read-write method and device and medium
CN114398369A