Oracle - 截断全局临时表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2733709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:31:34  来源:igfitidea点击:

Oracle - truncating a global temporary table

sqloracle

提问by Ariod

I am processing large amounts of data in iterations, each and iteration processes around 10-50 000 records. Because of such large number of records, I am inserting them into a global temporary table first, and then process it. Usually, each iteration takes 5-10 seconds.

我在迭代中处理大量数据,每次迭代处理大约 10-50 000 条记录。由于记录数量如此之多,我是先将它们插入到一个全局临时表中,然后再进行处理。通常,每次迭代需要 5-10 秒。

Would it be wise to truncate the global temporary table after each iteration so that each iteration can start off with an empty table? There are around 5000 iterations.

在每次迭代后截断全局临时表以便每次迭代都可以从一个空表开始是否明智?大约有 5000 次迭代。

回答by Jeffrey Kemp

No! The whole idea of a Global Temporary Table is that the data disappears automatically when you no longer need it.

不!全局临时表的整个想法是当您不再需要数据时,数据会自动消失。

For example, if you want the data to disappear when you COMMIT, you should use the ON COMMIT DELETE ROWS option when originally creating the table.

例如,如果您希望在 COMMIT 时数据消失,则应在最初创建表时使用 ON COMMIT DELETE ROWS 选项。

That way, you don't need to do a TRUNCATE - you just COMMIT, and the table is all fresh and empty and ready to be reused.

这样,您不需要执行 TRUNCATE - 您只需 COMMIT,并且该表是全新的和空的,可以重复使用。

回答by glasnt

5000 iterations on 50000 records per run? If you need to be doing that much processing, surely you can optimise your processing logic to run more efficiently. That would give you more speed compared to truncating tables.

每次运行 50000 条记录上的 5000 次迭代?如果您需要进行那么多处理,当然可以优化处理逻辑以更有效地运行。与截断表相比,这将为您提供更快的速度。

However, if you are finished with data in a temp table, you should truncate it, or just ensure that the next process to use the table isn't re-processing the same data over again.

但是,如果您完成了临时表中的数据,您应该截断它,或者只是确保下一个使用该表的进程不会再次重新处理相同的数据。

E.g. have a 'processed' flag, so new processes don't use the existing data. OR remove data when no longer needed.

例如,有一个“已处理”标志,因此新进程不使用现有数据。或在不再需要时删除数据。