CN-115510068-B - Table space moving method, apparatus, device and storage medium
Abstract
The invention discloses a method, a device, equipment and a storage medium for table space movement. The method comprises the steps of obtaining a table space moving statement input by a user, wherein the table space statement is a database statement for moving a target table to a target table space, constructing an intermediate table in the target table space according to the target table, wherein the definition of the intermediate table is the same as that of a dependent object of the target table, the structure of the intermediate table is the same as that of the target table, performing data dictionary exchange on the target table and the intermediate table, and transferring data in the intermediate table after the data dictionary exchange to the target table after the data dictionary exchange.
Inventors
- ZHU ZHONGYING
- MENG ZHENGLING
- HAN ZHUZHONG
Assignees
- 上海达梦数据库有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20221019
Claims (8)
- 1. A method of tablespace movement, comprising: Obtaining a table space moving statement input by a user, wherein the table space statement is a database statement for moving a target table to a target table space; Constructing an intermediate table in the target table space according to the target table, wherein the definition of the intermediate table is the same as that of the dependent object of the target table, and the structure of the intermediate table is the same as that of the target table; Performing data dictionary exchange on the target table and the intermediate table; migrating the data in the intermediate table after the data dictionary exchange to a target table after the data dictionary exchange; The exchanging the target table and the intermediate table for the data dictionary comprises the following steps: performing data dictionary exchange on the index in the target table and the index in the intermediate table; Wherein the exchanging the index in the target table with the index in the intermediate table for the data dictionary includes: Exchanging the names of the indexes in the target table and the parent object IDs of the indexes in the intermediate table with each other, wherein the data page root address information corresponding to the indexes in the target table and the data page root address information corresponding to the indexes in the intermediate table are kept unchanged, and the names of the target table are kept unchanged in the data dictionary exchanging process.
- 2. The method of claim 1, wherein constructing an intermediate table in the target table space from the target table comprises: if the target table and the target table space both exist and the target table type is not a target type, constructing an intermediate table in the target table space according to the target table.
- 3. The method of claim 1, wherein the target table comprises a table to be moved and a sub-table of the table to be moved, and the intermediate table comprises a first table corresponding to the table to be moved and a second table corresponding to the sub-table of the table to be moved; exchanging the target table and the intermediate table for a data dictionary, including: exchanging a data dictionary between the table to be moved and the first table; and carrying out data dictionary exchange on the sub-table of the table to be moved and the second table.
- 4. The method of claim 1, wherein migrating data in the intermediate table after the data dictionary exchange to the target table after the data dictionary exchange comprises: Querying an intermediate table after data dictionary exchange to obtain a query result; and inserting the query result into a target table after data dictionary exchange.
- 5. The method as recited in claim 1, further comprising: And deleting the intermediate table after the data dictionary exchange.
- 6. A tablespace moving device, comprising: the acquisition module is used for acquiring a tablespace moving statement input by a user, wherein the tablespace statement is a database statement for moving a target table to a target tablespace; the construction module is used for constructing an intermediate table in the target table space according to the target table, wherein the definition of the intermediate table is the same as that of the dependent object of the target table, and the structure of the intermediate table is the same as that of the target table; the exchange module is used for exchanging the data dictionary between the target table and the intermediate table; The migration module is used for migrating the data in the intermediate table after the data dictionary exchange to the target table after the data dictionary exchange; the exchange module is specifically configured to: performing data dictionary exchange on the index in the target table and the index in the intermediate table; Wherein the exchanging the index in the target table with the index in the intermediate table for the data dictionary includes: Exchanging the names of the indexes in the target table and the parent object IDs of the indexes in the intermediate table with each other, wherein the data page root address information corresponding to the indexes in the target table and the data page root address information corresponding to the indexes in the intermediate table are kept unchanged, and the names of the target table are kept unchanged in the data dictionary exchanging process.
- 7. An electronic device, the electronic device comprising: At least one processor, and A memory communicatively coupled to the at least one processor, wherein, The memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the tablespace moving method of any one of claims 1-5.
- 8. A computer readable storage medium storing computer instructions for causing a processor to implement the tablespace moving method of any one of claims 1-5 when executed.
Description
Table space moving method, apparatus, device and storage medium Technical Field The embodiment of the invention relates to the technical field of databases, in particular to a method, a device, equipment and a storage medium for table space movement. Background In database systems, data is stored in data tables, which are stored in a table space. In practical application scenarios, it is sometimes necessary to move the entire table or a partition of the table to a designated table space, for data management purposes. In the prior art, a table is generally reconstructed on a new table space or a partition is newly added, and then data is transferred to the new table or the new partition, but the scheme has the following problems: Directly creating a new object cannot be named the same as the original object, and then carrying out renaming operation additionally. The created new object ID changes, and if the ID is used as a condition to query in the system table, the original data table cannot be seen. If the partition is a mobile partition, when the new partition is created, the insertion of the data on the original partition into the new partition may trigger the UNIQUE constraint conflict on the main table, and in this case, if the data is to be transferred normally, an additional operation of data query insertion is required by means of the intermediate table. Disclosure of Invention The embodiment of the invention provides a method, a device, equipment and a storage medium for moving a table space, which solve the problems by carrying out the table space movement based on data dictionary exchange, can improve the efficiency of the table space movement and reduce the complexity of the table space movement. According to an aspect of the present invention, there is provided a tablespace moving method including: Obtaining a table space moving statement input by a user, wherein the table space statement is a database statement for moving a target table to a target table space; Constructing an intermediate table in the target table space according to the target table, wherein the definition of the intermediate table is the same as that of the dependent object of the target table, and the structure of the intermediate table is the same as that of the target table; Performing data dictionary exchange on the target table and the intermediate table; and migrating the data in the intermediate table after the data dictionary exchange to the target table after the data dictionary exchange. According to another aspect of the present invention, there is provided a tablespace moving apparatus including: the acquisition module is used for acquiring a tablespace moving statement input by a user, wherein the tablespace statement is a database statement for moving a target table to a target tablespace; the construction module is used for constructing an intermediate table in the target table space according to the target table, wherein the definition of the intermediate table is the same as that of the dependent object of the target table, and the structure of the intermediate table is the same as that of the target table; the exchange module is used for exchanging the data dictionary between the target table and the intermediate table; and the migration module is used for migrating the data in the intermediate table after the data dictionary exchange to the target table after the data dictionary exchange. According to another aspect of the present invention, there is provided an electronic apparatus including: At least one processor, and A memory communicatively coupled to the at least one processor, wherein, The memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the tablespace moving method according to any one of the embodiments of the invention. According to another aspect of the present invention, there is provided a computer readable storage medium storing computer instructions for causing a processor to implement a tablespace moving method according to any one of the embodiments of the present invention when executed. The embodiment of the invention comprises the steps of obtaining a table space moving statement input by a user, wherein the table space statement is a database statement for moving a target table to a target table space, constructing an intermediate table in the target table space according to the target table, wherein the definition of a dependent object of the intermediate table is the same as that of a dependent object of the target table, the structure of the intermediate table is the same as that of the target table, carrying out data dictionary exchange on the target table and the intermediate table, and migrating data in the intermediate table after the data dictionary exchange to the target table after the data dictionary exchange, so that the efficiency of the table space movement can be improved, and the complexity of the