drop table temp_lck;
create table temp_lck
( 
    lck_object_id                 integer not null,
    lck_object_type               varchar(50) not null,
    lck_type                      char not null,
    lck_thread_id                 varchar(200) not null,
    lck_jvm_id                    varchar(200) not null,
    lck_tx_id                     varchar(200),
    primary key (lck_object_id, lck_object_type, lck_jvm_id, lck_thread_id, 
lck_type)
) organize by dimensions (lck_jvm_id)
in users index in indx;

drop index iutl_lck_0;
create index iutl_lck_0 on temp_lck (
        lck_jvm_id,
        lck_thread_id,
        lck_type
)   ALLOW REVERSE SCANS;

--- Avoid orphan LCK records while loading the new LCK table
declare lck_cursor cursor for   
  select * from lck 
  where lck_object_type in 
  ('CATALOG','CATEGORY','CATEGORY_TREE','COLLABORATION_AREA','PATHS_FOR_CATEGORY','WORKFLOW_EVENT') 
  OR (lck_object_type = 'ITEM' and 
    exists (select 1 from itm where lck_object_id = itm_id and itm_next_version_id = 999999999));

load from lck_cursor of cursor modified by pagefreespace=5 messages lck.msg 
insert into temp_lck nonrecoverable indexing mode rebuild;

drop table tutl_lck_lock;

rename temp_lck to tutl_lck_lock;

drop alias lck;

create alias lck for tutl_lck_lock;

