Summary of the invention
Fundamental purpose of the present invention is to provide a kind of data processing method for database table and device, to solve prior art to the lower problem of the data-handling efficiency in database table.
To achieve these goals, according to an aspect of the present invention, provide a kind of data processing method of database table.According to the data processing method of database table of the present invention, comprise: obtain the temporary table consistent with database table structure; And by blocked operation by the data exchange of database table in temporary table.
Further, by blocked operation, the data exchange of database table is comprised to temporary table: judge whether database table has subregion; If judge database table, there is subregion, by blocked operation, the subregion of database table is transferred in temporary table from database table; And if judge database table and there is no subregion, by blocked operation, directly the data in database table and temporary table are exchanged.
Further, by blocked operation, the data exchange of database table is comprised to temporary table: the configuration information by metadata in blocked operation Update Table storehouse table by the data exchange of database table in temporary table.
Further, before obtaining the temporary table consistent with database table structure, method also comprises: according to database table, create temporary table.
Further, by blocked operation, the data exchange of database table is comprised to temporary table: the data in delete database table, by blocked operation by after the data exchange of database table is in temporary table, method also comprises: temporary table is carried out and to be removed operation.
To achieve these goals, according to a further aspect in the invention, provide a kind of data processing equipment of database table.According to the data processing equipment of database table of the present invention, comprise: judge module, for judging whether database table has subregion; Shift module for when judging database table and have subregion, is transferred in temporary table by blocked operation by the subregion of database table from database table; And Switching Module, for when judging database table and there is no subregion, by blocked operation, directly the data in database table and temporary table are exchanged.
Further, shift module also for the configuration information by blocked operation Update Table storehouse table metadata by the data exchange of database table in temporary table.
Further, data processing equipment also comprises: creating unit, for before obtaining the temporary table consistent with database table structure, creates temporary table according to database table.
Further, data processing equipment comprises: switch unit also comprises removing module, for the data of delete database table; And remove unit, for by blocked operation by the data exchange of database table after temporary table, temporary table is carried out and is removed operation.
By the present invention, adopt and obtain the temporary table consistent with database table structure; And by blocked operation by the data exchange of described database table in described temporary table, solved problem to the data-handling efficiency in database table lower in prior art, and then reached the effect that improves the data-handling efficiency in tables of data.
Embodiment
It should be noted that, in the situation that not conflicting, embodiment and the feature in embodiment in the application can combine mutually.Describe below with reference to the accompanying drawings and in conjunction with the embodiments the present invention in detail.
The embodiment of the present invention provides a kind of data processing method of tables of data, and the method may operate on computer program.
Fig. 1 is according to the process flow diagram of the data processing method of the database table of first embodiment of the invention.As shown in the figure, the data processing method of this database table comprises the steps:
Step S101, obtains the temporary table consistent with database table structure.
The structure of tables of data comprises field name, type etc., obtain the temporary table consistent with data list structure comprise obtain consistent with field name, the type of database table structure, index is consistent, table compress mode one Primary key of making peace is consistent, wherein, index comprises clustered index and Nonclustered index.
In order to guarantee not make mistakes in data handling procedure, set up the temporary table consistent with database table structure.Wherein, stored and need processed data in processed database table, temporary table can need processed data in stored data base table.
Step S102, by blocked operation by the data exchange of database table in temporary table.Blocked operation can be for all data in database table, also can be for the partial data in database table.So-called blocked operation is exactly that the data in database table are moved on in temporary table, the integral body that can simultaneously remove many data or database table data removes, but, log not, do not relate to reading and writing data IO, when need to retaining database table structure, only the data in database table are processed.
By above step, can carry out batch hand-off process to the data in database table, improved the efficiency of data processing, list structure that simultaneously can save data storehouse table.
Fig. 2 is according to the process flow diagram of the data processing method of the database table of second embodiment of the invention.As shown in the figure, the data processing method of this database table comprises the steps:
Step S201, obtains the temporary table consistent with database table structure.
The structure of tables of data comprises field name, type etc., obtain the temporary table consistent with data list structure comprise obtain consistent with field name, the type of database table structure, index is consistent, table compress mode one Primary key of making peace is consistent, wherein, index comprises clustered index and Nonclustered index.
In order to guarantee not make mistakes in data handling procedure, set up the temporary table consistent with database table structure.Wherein, stored and need processed data in processed database table, temporary table can need processed data in stored data base table.
Step S202, judges whether database table has subregion.Database table partitioned storage data can improve the performance of database, therefore, in more complicated database table, often there is subregion, if database table has subregion, need to first determine and need data to be processed in which subregion, and the data in this subregion are processed.
The data that are partitioned storage are a plurality of files physically, but remain in logic a table, and the operation of his-and-hers watches is also the same with before subregion, and therefore, the method that the embodiment of the present invention provides also can be applied in the database table after being partitioned.In the database table no matter being partitioned or the database table not being partitioned, can carry out the operations such as insertion, deletion, inquiry and renewal of data.Certainly, the embodiment of the present invention is more concerned about be database table data be to delete.
Step S203, has subregion if judge database table, by blocked operation, the subregion of database table is transferred in temporary table from database table.
Before the data in database table are processed, first judge whether database table has subregion, if database table has subregion, to carrying out the data of the subregion of data processing, be transferred in temporary table.In the process shifting, only shift the data that need subregion to be processed, the data list structure that this subregion is corresponding is not changed.Meanwhile, the blank content in blank temporary table is switched in corresponding database table, thereby has realized the switching of database table.
Step S204, does not have subregion if judge database table, by blocked operation, directly the data in database table and temporary table is exchanged.If judged in database table, there is no subregion, can directly to all data in database table, carry out blocked operation.Data in database table and the corresponding clear data of temporary table are exchanged, thereby realized the switching of data.
In said process, owing to being only the exchange of data, so just can complete 1 second for example in the very short time.Therefore,, when the deletion to data, improved the efficiency that data are deleted.Meanwhile, due to the data that store in temporary table in database table, in the situation that deleting, mistake can recover data.
Further, by blocked operation, the data exchange of database table is comprised to temporary table: the configuration information by metadata in blocked operation Update Table storehouse table by the data exchange of database table in temporary table.
Pass through blocked operation, metadata in database table is switched in temporary table by atomic operation, the metadata being about in database table is switched in temporary table, metadata corresponding position in database table is empty, namely will in database table, need the content of deleting to delete, retain the structure of database table simultaneously, and content is deleted.
Further, before obtaining the temporary table consistent with database table structure, according to database table, create temporary table.
The temporary table creating is consistent with the structure of database table, comprises field name, type is consistent, index is consistent, it is consistent to show compress mode one Primary key of making peace, and wherein, index comprises clustered index and Nonclustered index.
Further, by blocked operation, the data exchange of database table is comprised to temporary table: the data in delete database table, by blocked operation by after the data exchange of database table is in temporary table, temporary table is carried out and to be removed operation.
The temporary table structure of setting up is consistent with database table, but its content is empty, by the data exchange of database table in temporary table, the content pages of temporary table is switched in database table, in database table, the content of relevant position is empty, and the data in database table are deleted.If the data that are switched in temporary table no longer need to retain, only temporary table directly need be deleted, thereby realized, the content in database table is deleted, improved data-handling efficiency in database table.
The present invention also provides a kind of data processing equipment of database table.
Fig. 3 is according to the schematic diagram of the data processing equipment of the database table of first embodiment of the invention.As shown in the figure, this device comprises acquiring unit 10 and switch unit 20.
Acquiring unit 10 is for obtaining the temporary table consistent with database table structure.The structure of tables of data comprises field name, type etc., obtain the temporary table consistent with data list structure comprise obtain consistent with field name, the type of database table structure, index is consistent, table compress mode one Primary key of making peace is consistent, wherein, index comprises clustered index and Nonclustered index.
In order to guarantee not make mistakes in data handling procedure, set up the temporary table consistent with database table structure.Wherein, stored and need processed data in processed database table, temporary table can need processed data in stored data base table.
Switch unit 20 for by blocked operation by the data exchange of database table to temporary table.
Blocked operation can be for all data in database table, also can be for the partial data in database table.So-called blocked operation is exactly that the data in database table are moved on in temporary table, the integral body that can simultaneously remove many data or database table data removes, but, log not, do not relate to reading and writing data IO, when need to retain database table structure, only the data in database table are processed.
By above device, can carry out batch hand-off process to the data in database table, improved the efficiency of data processing, list structure that simultaneously can save data storehouse table.
Fig. 4 is according to the schematic diagram of the data processing equipment of the database table of second embodiment of the invention.As shown in the figure, the data processing equipment of this database table comprises acquiring unit 10 and switch unit 20, and wherein, switch unit 20 comprises judge module 201, shift module 202 and Switching Module 203.
Judge module 201 is for judging whether database table has subregion.Database table partitioned storage data can improve the performance of database, therefore, in more complicated database table, often there is subregion, if database table has subregion, need to first determine and need data to be processed in which subregion, and the data in this subregion are processed.
The data that are partitioned storage are a plurality of files physically, but remain in logic a table, and the operation of his-and-hers watches is also the same with before subregion, and therefore, the method that the embodiment of the present invention provides also can be applied in the database table after being partitioned.In the database table no matter being partitioned or the database table not being partitioned, can carry out the operations such as insertion, deletion, inquiry and renewal of data.Certainly, the embodiment of the present invention is more concerned about be database table data be to delete.
Shift module 202, for when judging database table and have subregion, is transferred to the subregion of database table in temporary table by blocked operation from database table.
Before the data in database table are processed, first judge whether database table has subregion, if database table has subregion, to carrying out the data of the subregion of data processing, be transferred in temporary table.In the process shifting, only shift the data that need subregion to be processed, the data list structure that this subregion is corresponding is not changed.Meanwhile, the blank content in blank temporary table is switched in corresponding database table, thereby has realized the switching of database table.
Switching Module 203, for when judging database table and there is no subregion, directly exchanges the data in database table and temporary table by blocked operation.If judged in database table, there is no subregion, can directly to all data in database table, carry out blocked operation.Data in database table and the corresponding clear data of temporary table are exchanged, thereby realized the switching of data.
In said process, owing to being only the exchange of data, so just can complete 1 second for example in the very short time.Therefore,, when the deletion to data, improved the efficiency that data are deleted.Meanwhile, due to the data that store in temporary table in database table, in the situation that deleting, mistake can recover data.
Further, shift module 202 also for the configuration information by blocked operation Update Table storehouse table metadata by the data exchange of database table in temporary table.
Pass through blocked operation, metadata in database table is switched in temporary table by atomic operation, the metadata being about in database table is switched in temporary table, metadata corresponding position in database table is empty, namely will in database table, need the content of deleting to delete, retain the structure of database table simultaneously, and content is deleted.
Further, this data processing equipment also comprises creating unit, and this creating unit, for before obtaining the temporary table consistent with database table structure, creates temporary table according to database table.
The temporary table creating is consistent with the structure of database table, comprises field name, type is consistent, index is consistent, it is consistent to show compress mode one Primary key of making peace, and wherein, index comprises clustered index and Nonclustered index.
Further, the switch unit 20 of data processing equipment also comprises removing module, and this removing module, for the data of delete database table, also comprises and removes unit, for by blocked operation by the data exchange of database table after temporary table, temporary table is carried out and to be removed operation.
The temporary table structure of setting up is consistent with database table, but its content is empty, by the data exchange of database table in temporary table, the content pages of temporary table is switched in database table, in database table, the content of relevant position is empty, and the data in database table are deleted.If the data that are switched in temporary table no longer need to retain, only temporary table directly need be deleted, thereby realized, the content in database table is deleted, improved data-handling efficiency in database table.
Obviously, those skilled in the art should be understood that, above-mentioned each module of the present invention or each step can realize with general calculation element, they can concentrate on single calculation element, or be distributed on the network that a plurality of calculation elements form, alternatively, they can be realized with the executable program code of calculation element, thereby, they can be stored in memory storage and be carried out by calculation element, or they are made into respectively to each integrated circuit modules, or a plurality of modules in them or step are made into single integrated circuit module to be realized.Like this, the present invention is not restricted to any specific hardware and software combination.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, for a person skilled in the art, the present invention can have various modifications and variations.Within the spirit and principles in the present invention all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.