是的,你是對的,索引不會被修改,因爲主鍵(自然索引)列具有相同的值,像它的索引。
而且,此更新
update t set id=1,content='ccc'
where id=1;
是資源更加comsuming比
update t set content='ccc'
where id=1;
因爲,更新索引的列比更新未編入索引的速度慢。
示例如下...
SQL> create table a (b numeric, c varchar2(50));
SQL> set timing on;
SQL> insert into a(b) select rownum from dual connect by level <= 1000000;
1000000 rows created.
Elapsed: 00:00:02.74
SQL> update a set c=ascii(b);
1000000 rows updated.
Elapsed: 00:00:46.72
SQL> commit;
Commit complete.
Elapsed: 00:00:00.03
SQL> truncate table a;
Table truncated.
Elapsed: 00:00:01.33
SQL> insert into a(b) select rownum from dual connect by level <= 1000000;
1000000 rows created.
Elapsed: 00:00:00.80
SQL> commit;
Commit complete.
Elapsed: 00:00:00.03
SQL> create index idx_c on a;
Index created.
Elapsed: 00:00:00.46
SQL> update a set c=ascii(b);
1000000 rows updated.
Elapsed: 00:01:53.12
SQL> commit;
Commit complete.
Elapsed: 00:00:00.04
這就是我的預期。你知道一種方法來演示它嗎?我的主管希望看到確鑿的證據。 –
@LuyinSun好吧,我已經添加了一個我的朋友的例子。順便說一句,我已經與chr混淆ascii函數,你可以試試這個。 –
謝謝Barbaros。我現在有了主意。 –