大家过年好!我是个oracle新手,有个问题感觉想不通,请各位前辈指教,问题如下:
在生产库上监控到一个delete操作引起了大量磁盘排序,感觉很迷惑,在测试环境下做了个测试:
SQL> select tablespace_name,bytes/1024/1024 from dba_temp_files;
TABLESPACE_NAME BYTES/1024/1024
------------------------------ ---------------
TEMP2 200
TEMP 2
SQL> alter database default temporary tablespace temp2;
Database altered.
SQL> select count(*) from test;
COUNT(*)
----------
200000
SQL> select count(distinct object_id) from test;
COUNT(DISTINCTOBJECT_ID)
------------------------
200000
SQL> create unique index idx_test1 on test(object_id);
Index created.
SQL> alter database default temporary tablespace temp;
Database altered.
SQL> delete from test where object_id>0;
delete from test where object_id>0
*
ERROR at line 1:
ORA-01652: unable to extend temp segment by 128 in tablespace TEMP
SQL> delete /*+ full(test) */ from test where object_id>0;
200000 rows deleted.
显然走索引范围扫描时需要排序,而全表扫描的情况下,是不需要排序。为什么delete时采用了索引范围扫描就需要排序呢,望各位前辈指点迷津,多谢了!