Skip to Main Content
  • Questions
  • question about row movement and alter table shrink

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, philippe.

Asked: February 01, 2008 - 10:20 am UTC

Last updated: January 12, 2011 - 10:57 am UTC

Version: 10.2

Viewed 1000+ times

You Asked

Hi Tom,
In 10G we can shrink a table but before doing this we need to enable row movement.
Is there a disadvantage doing this and is it recommended to disable it afterwards ?
If no, why isn't row movement enabled by default ?
Thank you.

and Tom said...

enable row movement simply gives Oracle the ability to modify a rows rowid.

Prior to Oracle 8i when this new capability was introduced, a rowid was immutable. Once a row was inserted, the rowid assigned to it would never change.

Enabling row movement allows Oracle to modify a rowid of a row - this happens when:

a) you update a partition key causing the row to move partitions
b) flashback a table
c) alter a table shrinking the space compact
d) technically, the universal rowid of an index organized table will change as well if you update the primary key

The disadvantage would be if you STORE the rowid of row in another table - something you do not normally do.

So, unless you expect the rowid of a row to never change, this is a safe attribute.

It is not the default, because in general - defaults reflect the original behavior. Changing a default to be something different is generally not desirable.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

What about Oracle Text?

Curtis Ruck, February 06, 2008 - 9:52 am UTC

If recall correctly Oracle Text stores the rowid in one of its tables for a Context Index. Would that be affected by enabling row movement and shrinking the table?
Tom Kyte
February 06, 2008 - 10:13 am UTC

ops$tkyte%ORA10GR2> CREATE TABLE t
  2  (
  3    x   int primary key,
  4    dt  date,
  5    y   varchar2(30)
  6  )
  7  tablespace users
  8  enable row movement
  9  /

Table created.

ops$tkyte%ORA10GR2> insert into t values ( 0, to_date( '12-mar-2003' ), 'hello world' );

1 row created.

ops$tkyte%ORA10GR2> alter table t shrink space compact;

Table altered.

ops$tkyte%ORA10GR2> create index t_idx on t(y) indextype is ctxsys.context parameters( 'sync(on commit)' );

Index created.

ops$tkyte%ORA10GR2> alter table t shrink space compact;
alter table t shrink space compact
*
ERROR at line 1:
ORA-10631: SHRINK clause should not be specified for this object


note that a partition key update is permitted, internally that is delete+insert and the right thing happens:

ops$tkyte%ORA10GR2> CREATE TABLE t
  2  (
  3    x   int primary key,
  4    dt  date,
  5    y   varchar2(30)
  6  )
  7  tablespace users
  8  enable row movement
  9  PARTITION BY RANGE (dt)
 10  (
 11    PARTITION part1 VALUES LESS THAN (to_date('13-mar-2003','dd-mon-yyyy')) ,
 12    PARTITION part2 VALUES LESS THAN (to_date('14-mar-2003','dd-mon-yyyy')) ,
 13    PARTITION junk VALUES LESS THAN (MAXVALUE)
 14  )
 15  /

Table created.

ops$tkyte%ORA10GR2> insert into t values ( 0, to_date( '12-mar-2003' ), 'hello world' );

1 row created.

ops$tkyte%ORA10GR2> create index t_idx on t(y) indextype is ctxsys.context parameters( 'sync(on commit)' );

Index created.

ops$tkyte%ORA10GR2> select rowid, t.* from t where contains( y, 'hello' )>0;

ROWID                       X DT        Y
------------------ ---------- --------- ------------------------------
AAAlouAAEAAAAAMAAA          0 12-MAR-03 hello world

ops$tkyte%ORA10GR2> update t set dt=dt+1;

1 row updated.

ops$tkyte%ORA10GR2> commit;

Commit complete.

ops$tkyte%ORA10GR2> select rowid, t.* from t where contains( y, 'hello' )>0;

ROWID                       X DT        Y
------------------ ---------- --------- ------------------------------
AAAlovAAEAAAAAUAAA          0 13-MAR-03 hello world

Token tables $I in Oracle text CONTEXT index

Serafin Sedano, January 12, 2011 - 3:37 am UTC

Hi,

So it would be safe to enable row movement to the DR$INDEX_NAME$I table with tokens in a CONTEXT Oracle text index?

Or Oracle will be continously changing row ids and, therefore, rebuilding the index associated to that table (DR$INDEX_NAME$X)?
Tom Kyte
January 12, 2011 - 10:57 am UTC

why do you want to do this?