TimesTen 重建索引

####备份变更表###
ttisql -connStr "dsn=ttprim" -e "
CREATE TABLE  timesten.XIAOXU_CESHI_BAK
AS
SELECT * FROM  timesten.XIAOXU_CESHI;
exit;"

####比对备份表数据###
ttisql -connStr "dsn=ttprim" -e "
SELECT count(1) FROM  timesten.XIAOXU_CESHI;
SELECT count(1) FROM  timesten.XIAOXU_CESHI_BAK;
exit;" >> /tmp/prt.cnt

####导出文件###
ttBulkCp -o -s "|" DSN=ttprim  timesten.XIAOXU_CESHI  /tmp/timestenXIAOXU_CESHI.dat


###表更操作###
ttisql -connStr "dsn=ttprim" -e "


alter session set ddl_replication_level=2;

alter session set ddl_replication_action='EXCLUDE';

truncate table   timesten.XIAOXU_CESHI;

drop table  timesten.XIAOXU_CESHI;

create table  timesten.XIAOXU_CESHI (
        PRESENT_ID     TT_BIGINT NOT NULL,
        KEY_ID         TT_BIGINT NOT NULL,
        ATTR_ID        TT_INTEGER NOT NULL,
        MIN_CYCLE_ID   TT_BIGINT NOT NULL,
        MAX_CYCLE_ID   TT_BIGINT NOT NULL,
        FREE_VOLUME    NUMBER(24,7),
        USAGE_VOLUME   NUMBER(24,7),
        OVER_VOLUME    NUMBER(24,7),
        TARIFF_PLAN_ID TT_INTEGER,
        CDR_END_TIME   TT_TIMESTAMP,
        SUBS_ID        TT_BIGINT NOT NULL,
        CHANGE_TIME    TT_TIMESTAMP,
        SYNC_FLAG      TT_TINYINT DEFAULT 1);


create unique index  timesten.PK_XIAOXU_CESHI on  timesten.XIAOXU_CESHI  (KEY_ID, PRESENT_ID,ATTR_ID,MIN_CYCLE_ID,MAX_CYCLE_ID,SUBS_ID);


alter active standby pair include table  timesten.XIAOXU_CESHI;
alter session set ddl_replication_level=1;
exit;"


---比对(主备库执行查询)
ttisql -connStr "dsn=ttprim" -e "
select count(1) from  timesten.XIAOXU_CESHI;
allindexes timesten.XIAOXU_CESHI;
exit;"


---导回数据
ttBulkCp -i DSN=ttprim  timesten.XIAOXU_CESHI /tmp/timestenXIAOXU_CESHI.dat


---比对(主备库执行查询)
ttisql -connStr "dsn=ttprim" -e "
select count(1) from  timesten.XIAOXU_CESHI;
exit;"


---表分析
ttisql -connStr "dsn=ttprim" -e "
call ttOptEstimateStats('timesten.XIAOXU_CESHI',1,'51  PERCENT'); commit;
exit;"


 

你可能感兴趣的:(TimesTen 重建索引)