oracle 在空表中执行缓慢的查询。(删除大量插入后)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4408212/
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
Slow query execution in an empty table. (after deleting a large amount of inserts)
提问by Stefanos Kargas
I have a table in an oracle database with 15 fields. This table had 3500000 inserts. I deleted them all.
我在 oracle 数据库中有一个表,有 15 个字段。该表有 3500000 个插入。我把它们都删除了。
delete
from table
After that, whenever I execute a select statement
I get a very slow response (7 sec) even though the table is empty.
I get a normal response only in the case that I search
according to an indexed field.
之后,每当我执行 select 语句时,
即使表是空的,我也会得到非常慢的响应(7 秒)。只有在我根据索引字段进行搜索的情况下,我才会得到正常响应。
Why?
为什么?
采纳答案by Stefanos Kargas
回答by Stefanos Kargas
Tom Kyte has a good explanation of this issue:
Tom Kyte 对这个问题有很好的解释:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:492636200346818072
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:492636200346818072
It should help you understand deletes, truncates, and high watermarks etc.
它应该可以帮助您了解删除、截断和高水印等。
回答by RJ.
In sql when you want to completely clear out a table, you should use truncate instead of delete. Let's say you have your table with 3.5 million rows in it and there is an index (unique identifier) on a column of bigint that increments for each row. Truncating the table will completely clear out the table and reset the index to 0. Delete will not clear the index and will continue at 3,500,001 when the next record is inserted. Truncate is also much faster than delete. Read the articles below to understand the differences.
在sql中,当你想彻底清除一个表时,你应该使用truncate而不是delete。假设您的表中有 350 万行,并且 bigint 列上有一个索引(唯一标识符),每行递增。截断表将完全清除表并将索引重置为 0。删除不会清除索引并在插入下一条记录时在 3,500,001 处继续。截断也比删除快得多。阅读以下文章以了解差异。
Read this article Read this articlethat explains the difference between truncate and delete. There are times to use each one. Hereis another article from an Oracle point of view.
阅读这篇文章阅读这篇文章,它解释了 truncate 和 delete 之间的区别。每一种都有使用的时候。 这是 Oracle 观点的另一篇文章。