将所有列值重置为默认值的快速方法
我正在将数据从一种模式转换为另一种模式。源模式中的每个表都有一个“状态”列(默认为 NULL)。记录转换后,我将状态列更新为 1。之后,我可以报告已转换(未转换)的记录数。
虽然转换例程仍在开发中,但我希望能够快速将所有状态值再次重置为 NULL。
表上的 UPDATE 语句太慢(记录太多)。有谁知道一种快速的替代方法来实现这一目标?
I'm converting data from one schema to another. Each table in the source schema has a 'status' column (default NULL). When a record has been converted, I update the status column to 1. Afterwards, I can report on the # of records that are (not) converted.
While the conversion routines are still under development, I'd like to be able to quickly reset all values for status to NULL again.
An UPDATE statement on the tables is too slow (there are too many records). Does anyone know a fast alternative way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
重置列的最快方法是 SET UNUSED 该列,然后添加具有相同名称和数据类型的列。
这将是最快的方法,因为这两个操作都不会触及实际的表(仅更新字典)。
正如Nivas的回答 列的实际顺序将被更改(重置列将是最后一列)。如果您的代码依赖于列的顺序(不应该!),您可以创建一个视图,该视图将按正确的顺序排列列(重命名表,创建与旧表同名的视图) ,从基表中撤销授权,将授权添加到视图)。
SET UNUSED 方法不会回收列使用的空间(而删除列将释放每个块中的空间)。
The fastest way to reset a column would be to SET UNUSED the column, then add a column with the same name and datatype.
This will be the fastest way since both operations will not touch the actual table (only dictionary update).
As in Nivas' answer the actual ordering of the columns will be changed (the reset column will be the last column). If your code rely on the ordering of the columns (it should not!) you can create a view that will have the column in the right order (rename table, create view with the same name as old table, revoke grants from base table, add grants to view).
The SET UNUSED method will not reclaim the space used by the column (whereas dropping the column will free space in each block).
如果该列可为空(因为默认为 NULL,我认为就是这种情况),则删除并再次添加该列?
If the column is nullable (since default is NULL, I think this is the case), drop and add the column again?
如果您正在开发中,为什么需要 7000 万条记录?为什么不针对数据的子集进行开发?
If you are in development why do you need 70 million records? Why not develop against a subset of the data?
您尝试过使用闪回表吗?
例如:
这样做的作用是确保每次运行测试时您正在处理的表都是相同的。当然,您需要确保有足够的 UNDO 来保存更改。
Have you tried using flashback table?
For example:
What this does is ensure that the table you are working on is IDENTICAL each time you run your tests. Of course, you need to ensure you have sufficient UNDO to hold your changes.
嗯。也许向状态列添加索引。
或者,添加一个仅包含主键的新表。然后在记录转换时插入到该表,并 TRUNC 该表以重置...
hm. maybe add an index to the status column.
or alterately, add a new table with the primary key only in it. then insert to that table when the record is converted, and TRUNC that table to reset...
我喜欢其他一些答案,但我刚刚在一本调优书中读到,由于多种原因,重新创建表通常比在表上进行大量更新更快。在这种情况下,这似乎是理想的,因为您将编写 CREATE TABLE X AS SELECT 并希望只包含很少的列。
I like some of the other answers, but I just read in a tuning book that for several reasons it's often quicker to recreate the table than to do massive updates on the table. In this case, it seems ideal, since you would be writing the CREATE TABLE X AS SELECT with hopefully very few columns.