How expensive is it to rename column name on a big table?
-
06-10-2020 - |
Question
Say we have table in an Oracle DB with millions of rows - how expensive is it rename it? My guess (and hope) is that it's just a metadata change, so the size of the table has no impact, but I'd like to verify (couldn't find any useful results).
Solution
Yes, it is just a metadata update.
SQL> create table t1 as
with g as (select * from dual connect by level <= 1000)
select 'HELLO' as c1 from g,g,g where rownum <= 1e7;
Table created.
SQL> select bytes/1024/1024 from user_segments where segment_name = 'T1';
BYTES/1024/1024
---------------
128
SQL> select
s.value/1024/1024
from v$mystat s
natural join v$statname sn
where sn.name = 'redo size';
S.VALUE/1024/1024
-----------------
131.848621
SQL> alter table t1 rename column c1 to c2;
Table altered.
SQL> select
s.value/1024/1024
from v$mystat s
natural join v$statname sn
where sn.name = 'redo size';
S.VALUE/1024/1024
-----------------
131.851715
Above statement produced just a tiny amount of redo.
But there are other aspects: the required locks and invalidation of related PL/SQL objects.
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange