SET NAMES 'GBK';
DELIMITER ;//
/*本版本说明：清空业务统计ST表、流量USR表数据。流量USR表与业务统计ST_USR表新增CLI_MAC字段；流量表与业务统计ST表在CLI_MAC与CLI_DID上建立索引；修改相关建表与统计程序或配置；在所有摘要表中在CLI_MAC字段中建立索引，为提高摘要表建立索引的速度，首先清除摘要表数据*/

/*清空业务统计ST表数据*/

TRUNCATE TABLE ST_DAY_GAME;
TRUNCATE TABLE ST_DAY_MAIL;
TRUNCATE TABLE ST_DAY_MSN;
TRUNCATE TABLE ST_DAY_NETVIDEO;
TRUNCATE TABLE ST_DAY_QQ;
TRUNCATE TABLE ST_DAY_STOCK;
TRUNCATE TABLE ST_DAY_USR;
TRUNCATE TABLE ST_DAY_WEB;
TRUNCATE TABLE ST_DAY_WEB_CONTRAVENE_RULE;
TRUNCATE TABLE ST_DAY_WEB_POST;
TRUNCATE TABLE ST_DAY_YMSG;
TRUNCATE TABLE ST_HOUR_GAME;
TRUNCATE TABLE ST_HOUR_MAIL;
TRUNCATE TABLE ST_HOUR_MSN;
TRUNCATE TABLE ST_HOUR_NETVIDEO;
TRUNCATE TABLE ST_HOUR_QQ;
TRUNCATE TABLE ST_HOUR_STOCK;
TRUNCATE TABLE ST_HOUR_USR;
TRUNCATE TABLE ST_HOUR_WEB;
TRUNCATE TABLE ST_HOUR_WEB_CONTRAVENE_RULE;
TRUNCATE TABLE ST_HOUR_WEB_POST;
TRUNCATE TABLE ST_HOUR_YMSG;
TRUNCATE TABLE ST_MONTH_GAME;
TRUNCATE TABLE ST_MONTH_MAIL;
TRUNCATE TABLE ST_MONTH_MSN;
TRUNCATE TABLE ST_MONTH_NETVIDEO;
TRUNCATE TABLE ST_MONTH_QQ;
TRUNCATE TABLE ST_MONTH_STOCK;
TRUNCATE TABLE ST_MONTH_USR;
TRUNCATE TABLE ST_MONTH_WEB;
TRUNCATE TABLE ST_MONTH_WEB_CONTRAVENE_RULE;
TRUNCATE TABLE ST_MONTH_WEB_POST;
TRUNCATE TABLE ST_MONTH_YMSG;
TRUNCATE TABLE ST_TMP_CUR_DAY_GAME;
TRUNCATE TABLE ST_TMP_CUR_DAY_MAIL;
TRUNCATE TABLE ST_TMP_CUR_DAY_MSN;
TRUNCATE TABLE ST_TMP_CUR_DAY_NETVIDEO;
TRUNCATE TABLE ST_TMP_CUR_DAY_QQ;
TRUNCATE TABLE ST_TMP_CUR_DAY_STOCK;
TRUNCATE TABLE ST_TMP_CUR_DAY_USR;
TRUNCATE TABLE ST_TMP_CUR_DAY_WEB;
TRUNCATE TABLE ST_TMP_CUR_DAY_WEB_CONTRAVENE_RULE;
TRUNCATE TABLE ST_TMP_CUR_DAY_WEB_POST;
TRUNCATE TABLE ST_TMP_CUR_DAY_YMSG;
TRUNCATE TABLE ST_TMP_GAME;
TRUNCATE TABLE ST_TMP_MAIL;
TRUNCATE TABLE ST_TMP_MSN;
TRUNCATE TABLE ST_TMP_NETVIDEO;
TRUNCATE TABLE ST_TMP_QQ;
TRUNCATE TABLE ST_TMP_STOCK;
TRUNCATE TABLE ST_TMP_USR;
TRUNCATE TABLE ST_TMP_WEB;
TRUNCATE TABLE ST_TMP_WEB_CONTRAVENE_RULE;
TRUNCATE TABLE ST_TMP_WEB_POST;
TRUNCATE TABLE ST_TMP_YMSG;



/*业务统计ST表新增CLI_MAC字段*/

ALTER TABLE ST_DAY_GAME ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_MAIL ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_MSN ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_NETVIDEO ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_QQ ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_STOCK ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_USR ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_WEB ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_WEB_CONTRAVENE_RULE ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_WEB_POST ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_DAY_YMSG ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_GAME ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_MAIL ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_MSN ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_NETVIDEO ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_QQ ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_STOCK ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_USR ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_WEB ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_WEB_CONTRAVENE_RULE ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_WEB_POST ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_HOUR_YMSG ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_GAME ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_MAIL ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_MSN ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_NETVIDEO ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_QQ ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_STOCK ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_USR ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_WEB ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_WEB_CONTRAVENE_RULE ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_WEB_POST ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_MONTH_YMSG ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_GAME ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_MAIL ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_MSN ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_NETVIDEO ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_QQ ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_STOCK ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_USR ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_WEB ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_WEB_CONTRAVENE_RULE ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_WEB_POST ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_CUR_DAY_YMSG ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_GAME ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_MAIL ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_MSN ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_NETVIDEO ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_QQ ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_STOCK ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_USR ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_WEB ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_WEB_CONTRAVENE_RULE ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_WEB_POST ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;
ALTER TABLE ST_TMP_YMSG ADD COLUMN CLI_MAC BIGINT(20) UNSIGNED  AFTER CLI_IP;



/*在业务统计ST表CLI_MAC上建立索引*/

ALTER TABLE ST_DAY_GAME ADD INDEX  IDX_ST_DAY_GAME_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_MAIL ADD INDEX  IDX_ST_DAY_MAIL_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_MSN ADD INDEX  IDX_ST_DAY_MSN_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_NETVIDEO ADD INDEX  IDX_ST_DAY_NETVIDEO_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_QQ ADD INDEX  IDX_ST_DAY_QQ_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_STOCK ADD INDEX  IDX_ST_DAY_STOCK_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_USR ADD INDEX  IDX_ST_DAY_USR_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_WEB ADD INDEX  IDX_ST_DAY_WEB_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_DAY_WEB_CONTRAVENE_RULE_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_WEB_POST ADD INDEX  IDX_ST_DAY_WEB_POST_CLI_MAC (CLI_MAC);
ALTER TABLE ST_DAY_YMSG ADD INDEX  IDX_ST_DAY_YMSG_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_GAME ADD INDEX  IDX_ST_HOUR_GAME_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_MAIL ADD INDEX  IDX_ST_HOUR_MAIL_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_MSN ADD INDEX  IDX_ST_HOUR_MSN_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_NETVIDEO ADD INDEX  IDX_ST_HOUR_NETVIDEO_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_QQ ADD INDEX  IDX_ST_HOUR_QQ_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_STOCK ADD INDEX  IDX_ST_HOUR_STOCK_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_USR ADD INDEX  IDX_ST_HOUR_USR_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_WEB ADD INDEX  IDX_ST_HOUR_WEB_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_HOUR_WEB_CONTRAVENE_RULE_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_WEB_POST ADD INDEX  IDX_ST_HOUR_WEB_POST_CLI_MAC (CLI_MAC);
ALTER TABLE ST_HOUR_YMSG ADD INDEX  IDX_ST_HOUR_YMSG_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_GAME ADD INDEX  IDX_ST_MONTH_GAME_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_MAIL ADD INDEX  IDX_ST_MONTH_MAIL_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_MSN ADD INDEX  IDX_ST_MONTH_MSN_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_NETVIDEO ADD INDEX  IDX_ST_MONTH_NETVIDEO_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_QQ ADD INDEX  IDX_ST_MONTH_QQ_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_STOCK ADD INDEX  IDX_ST_MONTH_STOCK_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_USR ADD INDEX  IDX_ST_MONTH_USR_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_WEB ADD INDEX  IDX_ST_MONTH_WEB_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_MONTH_WEB_CONTRAVENE_RULE_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_WEB_POST ADD INDEX  IDX_ST_MONTH_WEB_POST_CLI_MAC (CLI_MAC);
ALTER TABLE ST_MONTH_YMSG ADD INDEX  IDX_ST_MONTH_YMSG_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_GAME ADD INDEX  IDX_ST_TMP_CUR_DAY_GAME_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_MAIL ADD INDEX  IDX_ST_TMP_CUR_DAY_MAIL_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_MSN ADD INDEX  IDX_ST_TMP_CUR_DAY_MSN_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_NETVIDEO ADD INDEX  IDX_ST_TMP_CUR_DAY_NETVIDEO_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_QQ ADD INDEX  IDX_ST_TMP_CUR_DAY_QQ_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_STOCK ADD INDEX  IDX_ST_TMP_CUR_DAY_STOCK_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_USR ADD INDEX  IDX_ST_TMP_CUR_DAY_USR_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_WEB ADD INDEX  IDX_ST_TMP_CUR_DAY_WEB_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_TMP_CUR_DAY_WEB_CONTRAVENE_RULE_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_WEB_POST ADD INDEX  IDX_ST_TMP_CUR_DAY_WEB_POST_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_CUR_DAY_YMSG ADD INDEX  IDX_ST_TMP_CUR_DAY_YMSG_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_GAME ADD INDEX  IDX_ST_TMP_GAME_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_MAIL ADD INDEX  IDX_ST_TMP_MAIL_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_MSN ADD INDEX  IDX_ST_TMP_MSN_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_NETVIDEO ADD INDEX  IDX_ST_TMP_NETVIDEO_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_QQ ADD INDEX  IDX_ST_TMP_QQ_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_STOCK ADD INDEX  IDX_ST_TMP_STOCK_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_USR ADD INDEX  IDX_ST_TMP_USR_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_WEB ADD INDEX  IDX_ST_TMP_WEB_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_TMP_WEB_CONTRAVENE_RULE_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_WEB_POST ADD INDEX  IDX_ST_TMP_WEB_POST_CLI_MAC (CLI_MAC);
ALTER TABLE ST_TMP_YMSG ADD INDEX  IDX_ST_TMP_YMSG_CLI_MAC (CLI_MAC);


/*在业务统计ST表CLI_DID上建立索引*/

ALTER TABLE ST_DAY_GAME ADD INDEX  IDX_ST_DAY_GAME_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_MAIL ADD INDEX  IDX_ST_DAY_MAIL_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_MSN ADD INDEX  IDX_ST_DAY_MSN_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_NETVIDEO ADD INDEX  IDX_ST_DAY_NETVIDEO_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_QQ ADD INDEX  IDX_ST_DAY_QQ_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_STOCK ADD INDEX  IDX_ST_DAY_STOCK_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_USR ADD INDEX  IDX_ST_DAY_USR_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_WEB ADD INDEX  IDX_ST_DAY_WEB_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_DAY_WEB_CONTRAVENE_RULE_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_WEB_POST ADD INDEX  IDX_ST_DAY_WEB_POST_CLI_DID (CLI_DID);
ALTER TABLE ST_DAY_YMSG ADD INDEX  IDX_ST_DAY_YMSG_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_GAME ADD INDEX  IDX_ST_HOUR_GAME_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_MAIL ADD INDEX  IDX_ST_HOUR_MAIL_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_MSN ADD INDEX  IDX_ST_HOUR_MSN_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_NETVIDEO ADD INDEX  IDX_ST_HOUR_NETVIDEO_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_QQ ADD INDEX  IDX_ST_HOUR_QQ_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_STOCK ADD INDEX  IDX_ST_HOUR_STOCK_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_USR ADD INDEX  IDX_ST_HOUR_USR_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_WEB ADD INDEX  IDX_ST_HOUR_WEB_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_HOUR_WEB_CONTRAVENE_RULE_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_WEB_POST ADD INDEX  IDX_ST_HOUR_WEB_POST_CLI_DID (CLI_DID);
ALTER TABLE ST_HOUR_YMSG ADD INDEX  IDX_ST_HOUR_YMSG_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_GAME ADD INDEX  IDX_ST_MONTH_GAME_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_MAIL ADD INDEX  IDX_ST_MONTH_MAIL_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_MSN ADD INDEX  IDX_ST_MONTH_MSN_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_NETVIDEO ADD INDEX  IDX_ST_MONTH_NETVIDEO_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_QQ ADD INDEX  IDX_ST_MONTH_QQ_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_STOCK ADD INDEX  IDX_ST_MONTH_STOCK_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_USR ADD INDEX  IDX_ST_MONTH_USR_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_WEB ADD INDEX  IDX_ST_MONTH_WEB_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_MONTH_WEB_CONTRAVENE_RULE_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_WEB_POST ADD INDEX  IDX_ST_MONTH_WEB_POST_CLI_DID (CLI_DID);
ALTER TABLE ST_MONTH_YMSG ADD INDEX  IDX_ST_MONTH_YMSG_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_GAME ADD INDEX  IDX_ST_TMP_CUR_DAY_GAME_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_MAIL ADD INDEX  IDX_ST_TMP_CUR_DAY_MAIL_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_MSN ADD INDEX  IDX_ST_TMP_CUR_DAY_MSN_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_NETVIDEO ADD INDEX  IDX_ST_TMP_CUR_DAY_NETVIDEO_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_QQ ADD INDEX  IDX_ST_TMP_CUR_DAY_QQ_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_STOCK ADD INDEX  IDX_ST_TMP_CUR_DAY_STOCK_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_USR ADD INDEX  IDX_ST_TMP_CUR_DAY_USR_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_WEB ADD INDEX  IDX_ST_TMP_CUR_DAY_WEB_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_TMP_CUR_DAY_WEB_CONTRAVENE_RULE_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_WEB_POST ADD INDEX  IDX_ST_TMP_CUR_DAY_WEB_POST_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_CUR_DAY_YMSG ADD INDEX  IDX_ST_TMP_CUR_DAY_YMSG_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_GAME ADD INDEX  IDX_ST_TMP_GAME_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_MAIL ADD INDEX  IDX_ST_TMP_MAIL_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_MSN ADD INDEX  IDX_ST_TMP_MSN_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_NETVIDEO ADD INDEX  IDX_ST_TMP_NETVIDEO_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_QQ ADD INDEX  IDX_ST_TMP_QQ_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_STOCK ADD INDEX  IDX_ST_TMP_STOCK_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_USR ADD INDEX  IDX_ST_TMP_USR_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_WEB ADD INDEX  IDX_ST_TMP_WEB_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_WEB_CONTRAVENE_RULE ADD INDEX  IDX_ST_TMP_WEB_CONTRAVENE_RULE_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_WEB_POST ADD INDEX  IDX_ST_TMP_WEB_POST_CLI_DID (CLI_DID);
ALTER TABLE ST_TMP_YMSG ADD INDEX  IDX_ST_TMP_YMSG_CLI_DID (CLI_DID);

/*业务统计表汇总存储过程*/
DROP PROCEDURE IF EXISTS `PROC_ST_BUILD`;
CREATE  PROCEDURE `PROC_ST_BUILD`(
        V_STAT_TIME VARCHAR(10),
        V_TBL_KEY_NAME VARCHAR(128),
        V_STAT_TYPE VARCHAR(128)
    )
BEGIN
DECLARE V_INT_STAT_TIME INT DEFAULT 0;
DECLARE V_CUR_DONE INT DEFAULT 0;
DECLARE V_CFG_NAME VARCHAR(128) DEFAULT NULL;
DECLARE V_DIMENSION_SQL VARCHAR(10240) DEFAULT NULL;
DECLARE V_HEAD_DIMENSION_SQL VARCHAR(10240) DEFAULT NULL;
DECLARE V_CONVERT_DIMENSION_SQL VARCHAR(10240) DEFAULT NULL;
DECLARE V_HEAD_CONVERT_DIMENSION_SQL VARCHAR(10240) DEFAULT NULL;
DECLARE V_DYNAMIC_DIMENSION_SQL VARCHAR(10240) DEFAULT NULL;
DECLARE V_METRIC_SQL VARCHAR(10240) DEFAULT NULL;
DECLARE V_SUM_METRIC_SQL VARCHAR(10240) DEFAULT NULL;
DECLARE V_FITER_SQL VARCHAR(10240) DEFAULT NULL;
DECLARE V_TABLE_NAME VARCHAR(128) DEFAULT NULL;
DECLARE CUR_DIMENSIONALITY CURSOR FOR 
SELECT CFG_NAME FROM CFG_ST_TABLE_ANALYSE_DETAIL 
WHERE TBL_KEY_NAME=V_TBL_KEY_NAME 
AND CFG_TYPE='DIMENSIONALITY' ORDER BY SORT_ID;
DECLARE CUR_METRIC CURSOR FOR 
SELECT CFG_NAME FROM CFG_ST_TABLE_ANALYSE_DETAIL  
WHERE TBL_KEY_NAME=V_TBL_KEY_NAME 
AND CFG_TYPE='METRIC' ORDER BY SORT_ID;
	
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET V_CUR_DONE = 1;
FLUSH TABLES;
SET V_INT_STAT_TIME =DATE_FORMAT(V_STAT_TIME, '%Y%m%d');
SET V_HEAD_DIMENSION_SQL='APP_TYPE,CLI_DID,CLI_IP,CLI_MAC,CLI_ORG_L1,CLI_ORG_L2,CLI_ORG_L3,CLI_ORG_L4,';		
IF V_STAT_TYPE='DAY' THEN
		SET V_HEAD_CONVERT_DIMENSION_SQL=CONCAT('TO_DAYS(STAT_TIME),SUBSTRING(STAT_TIME,1,10),APP_TYPE,CLI_DID,CLI_IP,CLI_MAC,CLI_ORG_L1,CLI_ORG_L2,CLI_ORG_L3,CLI_ORG_L4,');
		
ELSEIF V_STAT_TYPE='MONTH' THEN
		SET V_HEAD_CONVERT_DIMENSION_SQL=CONCAT('SUBSTRING(''',V_INT_STAT_TIME,''',1,6),DATE_ADD(STAT_TIME,INTERVAL (-DAYOFMONTH(STAT_TIME)+1) DAY),APP_TYPE,CLI_DID,CLI_IP,CLI_MAC,CLI_ORG_L1,CLI_ORG_L2,CLI_ORG_L3,CLI_ORG_L4,');
				
END IF;
IF V_STAT_TYPE='DAY' THEN
		SET V_FITER_SQL=CONCAT(' WHERE PART_FD=TO_DAYS(''',V_STAT_TIME,''') AND STAT_TIME=''',V_STAT_TIME,''' ');
		
ELSEIF V_STAT_TYPE='MONTH' THEN
		SET V_FITER_SQL=CONCAT(' WHERE PART_FD=SUBSTRING(''',V_INT_STAT_TIME,''',1,6) AND STAT_TIME=DATE_ADD(''',V_STAT_TIME,''',INTERVAL (-DAYOFMONTH(''',V_STAT_TIME,''')+1) DAY)',' ');
				
END IF;
SET V_DYNAMIC_DIMENSION_SQL='';
		OPEN CUR_DIMENSIONALITY;
		REPEAT
		FETCH CUR_DIMENSIONALITY INTO 
		V_CFG_NAME;
		
				IF NOT V_CUR_DONE THEN
				
				
				SET V_DYNAMIC_DIMENSION_SQL=CONCAT(V_DYNAMIC_DIMENSION_SQL,V_CFG_NAME,',');		
				
				END IF;
		
		UNTIL V_CUR_DONE END REPEAT;
		CLOSE CUR_DIMENSIONALITY;
SET V_DIMENSION_SQL=CONCAT(V_HEAD_DIMENSION_SQL,V_DYNAMIC_DIMENSION_SQL);
SET V_CONVERT_DIMENSION_SQL=CONCAT(V_HEAD_CONVERT_DIMENSION_SQL,V_DYNAMIC_DIMENSION_SQL);
SET V_METRIC_SQL='';
SET V_SUM_METRIC_SQL='';
SET V_CUR_DONE = 0;
		OPEN CUR_METRIC;
		REPEAT
		FETCH CUR_METRIC INTO 
		V_CFG_NAME;
		
				IF NOT V_CUR_DONE THEN
				
				SET V_METRIC_SQL=CONCAT(V_METRIC_SQL,V_CFG_NAME,',');		
				
				
				SET V_SUM_METRIC_SQL=CONCAT(V_SUM_METRIC_SQL,'SUM(',V_CFG_NAME,'),');		
				END IF;
		
		UNTIL V_CUR_DONE END REPEAT;
		CLOSE CUR_METRIC;
SET V_METRIC_SQL=SUBSTRING(V_METRIC_SQL,1,LENGTH(V_METRIC_SQL)-1);
SET V_SUM_METRIC_SQL=SUBSTRING(V_SUM_METRIC_SQL,1,LENGTH(V_SUM_METRIC_SQL)-1);
SET V_TABLE_NAME=V_TBL_KEY_NAME;
IF V_STAT_TYPE='DAY' THEN 
	
	SET @V_SQL_SCRIPT=CONCAT('TRUNCATE TABLE ST_TMP_CUR_DAY_',V_TABLE_NAME,'; ');
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
	
	
	SET @V_SQL_SCRIPT=CONCAT('INSERT INTO ST_TMP_CUR_DAY_',V_TABLE_NAME,' (PART_FD,STAT_TIME,',V_DIMENSION_SQL,V_METRIC_SQL,')  ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'SELECT ','PART_FD,SUBSTRING(STAT_TIME,1,10),',V_DIMENSION_SQL,V_SUM_METRIC_SQL,' ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'FROM ST_HOUR_',V_TABLE_NAME,' ');
	SET V_DYNAMIC_DIMENSION_SQL=SUBSTRING(V_DYNAMIC_DIMENSION_SQL,1,LENGTH(V_DYNAMIC_DIMENSION_SQL)-1);
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'WHERE PART_FD=TO_DAYS(',V_INT_STAT_TIME,') AND STAT_TIME>=''',V_STAT_TIME,''' AND STAT_TIME<DATE_ADD(''',V_STAT_TIME,''',INTERVAL 1 DAY) GROUP BY PART_FD,SUBSTRING(STAT_TIME,1,10),',V_DIMENSION_SQL,';');
	
	SET @V_SQL_SCRIPT=CONCAT(SUBSTRING(@V_SQL_SCRIPT,1,LENGTH(@V_SQL_SCRIPT)-2),';');
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
	
	SET @V_SQL_SCRIPT=CONCAT('DELETE FROM ST_',V_STAT_TYPE,'_',V_TABLE_NAME,'  ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,V_FITER_SQL,'; ');
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
	
	
	SET @V_SQL_SCRIPT=CONCAT('INSERT INTO ST_DAY_',V_TABLE_NAME,' (PART_FD,STAT_TIME,',V_DIMENSION_SQL,V_METRIC_SQL,')  ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'SELECT PART_FD,STAT_TIME,',V_DIMENSION_SQL,V_METRIC_SQL,' ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'FROM ST_TMP_CUR_DAY_',V_TABLE_NAME,'; ');
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
END IF;
IF V_STAT_TYPE='MONTH' THEN 
	
	SET @V_SQL_SCRIPT=CONCAT('TRUNCATE TABLE ST_TMP_',V_TABLE_NAME,'; ');
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
	
	
	SET @V_SQL_SCRIPT=CONCAT('INSERT INTO ST_TMP_',V_TABLE_NAME,' (PART_FD,STAT_TIME,',V_DIMENSION_SQL,V_METRIC_SQL,')  ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'SELECT ',V_CONVERT_DIMENSION_SQL,V_METRIC_SQL,' ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'FROM ST_TMP_CUR_DAY_',V_TABLE_NAME,'; ');
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
	
	SET @V_SQL_SCRIPT=CONCAT('INSERT INTO ST_TMP_',V_TABLE_NAME,' (PART_FD,STAT_TIME,',V_DIMENSION_SQL,V_METRIC_SQL,')  ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'SELECT PART_FD,STAT_TIME,',V_DIMENSION_SQL,V_METRIC_SQL,' ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'FROM ST_',V_STAT_TYPE,'_',V_TABLE_NAME,' ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,V_FITER_SQL,'; ');
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
	
	SET @V_SQL_SCRIPT=CONCAT('DELETE FROM ST_',V_STAT_TYPE,'_',V_TABLE_NAME,'  ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,V_FITER_SQL,'; ');
	
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
	
	SET @V_SQL_SCRIPT=CONCAT('INSERT INTO ST_',V_STAT_TYPE,'_',V_TABLE_NAME,' (PART_FD,STAT_TIME,',V_DIMENSION_SQL,V_METRIC_SQL,')  ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,'SELECT PART_FD,STAT_TIME,',V_DIMENSION_SQL,' ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,V_SUM_METRIC_SQL,' ');
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,' FROM ST_TMP_',V_TABLE_NAME,' ');
	SET V_DIMENSION_SQL=SUBSTRING(V_DIMENSION_SQL,1,LENGTH(V_DIMENSION_SQL)-1);
	SET @V_SQL_SCRIPT=CONCAT(@V_SQL_SCRIPT,' GROUP BY PART_FD,STAT_TIME,',V_DIMENSION_SQL,'; ');
	INSERT INTO LOG_PROC_DETAIL (PROC_NAME,SQL_COMMENT)VALUES ('PROC_ST_BUILD',@V_SQL_SCRIPT);
	PREPARE STMT FROM @V_SQL_SCRIPT;
	EXECUTE STMT;
END IF;
END;




/*流量表增加CLI_MAC字段*/
DELETE FROM `CFG_APP_TABLE_ANALYSE_DETAIL` WHERE CFG_NAME='CLI_MAC' ;  

INSERT INTO `CFG_APP_TABLE_ANALYSE_DETAIL` (`APP_KIND`, `TBL_KEY_NAME`, `METRIC_GROUP`, `ANALYSE_TYPE`, `CFG_TYPE`, `CFG_NAME`, `DESCRIPTION`, `FIELD_INFO`, `TOPN_FLAG`, `SORT_ID`)
SELECT `APP_KIND`, `TBL_KEY_NAME`, `METRIC_GROUP`, `ANALYSE_TYPE`, `CFG_TYPE`, 'CLI_MAC', '客户端MAC', 'BIGINT(20) UNSIGNED', `TOPN_FLAG`, 18
 FROM CFG_APP_TABLE_ANALYSE_DETAIL WHERE CFG_NAME='CLI_IP' ;  

/*调整流量USR表CLI_IP、APP_TYPE索引顺序*/
UPDATE `CFG_APP_TABLE_INDEX` SET SORT_ID=2 WHERE ANALYSE_TYPE='USR' AND INDEX_FIELD='CLI_IP' ;  
UPDATE `CFG_APP_TABLE_INDEX` SET SORT_ID=5 WHERE ANALYSE_TYPE='USR' AND INDEX_FIELD='APP_TYPE' ;  

/*流量USR表增加CLI_DID字段的索引*/
DELETE FROM `CFG_APP_TABLE_INDEX` WHERE INDEX_FIELD='CLI_DID' ;  
INSERT INTO `CFG_APP_TABLE_INDEX` (`ANALYSE_TYPE`, `TABLE_PREFIX`, `INDEX_FIELD`, `INDEX_TYPE`, `SORT_ID`) VALUES 
  ('USR', 'TMP_CUR_DAY', 'CLI_DID', 'KEY', 1),
  ('USR', 'TMP', 'CLI_DID', 'KEY', 1),
  ('USR', 'HOUR', 'CLI_DID', 'KEY', 1),
  ('USR', 'DAY', 'CLI_DID', 'KEY', 1),
  ('USR', 'WEEK', 'CLI_DID', 'KEY', 1),
  ('USR', 'MONTH', 'CLI_DID', 'KEY', 1),
  ('USR', 'YEAR', 'CLI_DID', 'KEY', 1);

/*流量USR表增加CLI_MAC字段的的索引*/
DELETE FROM `CFG_APP_TABLE_INDEX` WHERE INDEX_FIELD='CLI_MAC' ;  
INSERT INTO `CFG_APP_TABLE_INDEX` (`ANALYSE_TYPE`, `TABLE_PREFIX`, `INDEX_FIELD`, `INDEX_TYPE`, `SORT_ID`) VALUES 
  ('USR', 'TMP_CUR_DAY', 'CLI_MAC', 'KEY', 3),
  ('USR', 'TMP', 'CLI_MAC', 'KEY', 3),
  ('USR', 'HOUR', 'CLI_MAC', 'KEY', 3),
  ('USR', 'DAY', 'CLI_MAC', 'KEY', 3),
  ('USR', 'WEEK', 'CLI_MAC', 'KEY', 3),
  ('USR', 'MONTH', 'CLI_MAC', 'KEY', 3),
  ('USR', 'YEAR', 'CLI_MAC', 'KEY', 3);

/*增加临时表的索引*/
DELETE FROM `CFG_APP_TABLE_INDEX` WHERE ANALYSE_TYPE='' AND TABLE_PREFIX IN ('TMP','TMP_CUR_DAY') AND INDEX_FIELD='APP_TYPE' AND INDEX_TYPE='KEY' AND `SORT_ID`=1 ;  
INSERT INTO `CFG_APP_TABLE_INDEX` (`ANALYSE_TYPE`, `TABLE_PREFIX`, `INDEX_FIELD`, `INDEX_TYPE`, `SORT_ID`) VALUES 
  ('', 'TMP', 'APP_TYPE', 'KEY', 1);
INSERT INTO `CFG_APP_TABLE_INDEX` (`ANALYSE_TYPE`, `TABLE_PREFIX`, `INDEX_FIELD`, `INDEX_TYPE`, `SORT_ID`) VALUES 
  ('', 'TMP_CUR_DAY', 'APP_TYPE', 'KEY', 1);
  

/*补充预留业务1在cfg_app_type中的信息*/
DELETE FROM `CFG_APP_TYPE` WHERE APP_TYPE IN (10139000,10139001);
INSERT INTO `CFG_APP_TYPE` (`APP_TYPE`, `APP_KIND`, `DESCRIPTION`, `TBL_KEY_NAME`, `APP_KEY_NAME`, `STATUS`, `REMARK`, `SORT_ID`) VALUES 
  (10139000, 1, '预留业务1', 'RESERVED1', '', 1, NULL, 59),
  (10139001, 1, '预留业务1子业务', 'RESERVED1_SUB', '', 1, NULL, 59);
  
/*重建流量USR表*/
CALL PROC_TOTAL_CALL_CREATE_TABLES('netems','ALLAPP',-1);

/*在所有摘要表中在CLI_MAC字段中建立索引；为提高摘要表建立索引的速度，首先清除摘要表*/

/* 清除摘要表数据*/

FLUSH TABLES;
TRUNCATE TABLE SM_FETION;
FLUSH TABLES;
TRUNCATE TABLE SM_IM_ACTION;
FLUSH TABLES;
TRUNCATE TABLE SM_MAIL;
FLUSH TABLES;
TRUNCATE TABLE SM_MSN;
FLUSH TABLES;
TRUNCATE TABLE SM_MSN_FILE;
FLUSH TABLES;
TRUNCATE TABLE SM_QQ;
FLUSH TABLES;
TRUNCATE TABLE SM_QQ_FILE;
FLUSH TABLES;
TRUNCATE TABLE SM_RC_FTP;
FLUSH TABLES;
TRUNCATE TABLE SM_RC_TELNET;
FLUSH TABLES;
TRUNCATE TABLE SM_SERVER_CONNECTIONS;
FLUSH TABLES;
TRUNCATE TABLE SM_UK;
FLUSH TABLES;
TRUNCATE TABLE SM_USERD;
FLUSH TABLES;
TRUNCATE TABLE SM_WEB;
FLUSH TABLES;
TRUNCATE TABLE SM_WEB_FILE_TRANS;
FLUSH TABLES;
TRUNCATE TABLE SM_WEB_LOGON;
FLUSH TABLES;
TRUNCATE TABLE SM_WEB_MAIL_ATT;
FLUSH TABLES;
TRUNCATE TABLE SM_WEB_MAIL_BODY;
FLUSH TABLES;
TRUNCATE TABLE SM_WEB_MAIL_BRIEF;
FLUSH TABLES;
TRUNCATE TABLE SM_WEB_POST;
FLUSH TABLES;
TRUNCATE TABLE SM_WEB_SEARCH;
FLUSH TABLES;
TRUNCATE TABLE SM_WEIBO;
FLUSH TABLES;
TRUNCATE TABLE SM_YMSG;


/*在所有摘要表中在CLI_MAC字段中建立索引*/
ALTER TABLE  SM_FETION ADD INDEX  IDX_SM_FETION_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_IM_ACTION ADD INDEX  IDX_SM_IM_ACTION_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_MAIL ADD INDEX  IDX_SM_MAIL_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_MSN ADD INDEX  IDX_SM_MSN_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_MSN_FILE ADD INDEX  IDX_SM_MSN_FILE_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_QQ ADD INDEX  IDX_SM_QQ_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_QQ_FILE ADD INDEX  IDX_SM_QQ_FILE_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_RC_FTP ADD INDEX  IDX_SM_RC_FTP_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_RC_TELNET ADD INDEX  IDX_SM_RC_TELNET_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_SERVER_CONNECTIONS ADD INDEX  IDX_SM_SERVER_CONNECTIONS_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_UK ADD INDEX  IDX_SM_UK_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_USERD ADD INDEX  IDX_SM_USERD_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEB ADD INDEX  IDX_SM_WEB_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEB_FILE_TRANS ADD INDEX  IDX_SM_WEB_FILE_TRANS_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEB_LOGON ADD INDEX  IDX_SM_WEB_LOGON_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEB_MAIL_ATT ADD INDEX  IDX_SM_WEB_MAIL_ATT_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEB_MAIL_BODY ADD INDEX  IDX_SM_WEB_MAIL_BODY_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEB_MAIL_BRIEF ADD INDEX  IDX_SM_WEB_MAIL_BRIEF_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEB_POST ADD INDEX  IDX_SM_WEB_POST_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEB_SEARCH ADD INDEX  IDX_SM_WEB_SEARCH_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_WEIBO ADD INDEX  IDX_SM_WEIBO_CLI_MAC (CLI_MAC) ;
ALTER TABLE  SM_YMSG ADD INDEX  IDX_SM_YMSG_CLI_MAC (CLI_MAC) ;



UPDATE CFG_PRODUCT_VARIABLES SET VALUE='1.1.3.3' WHERE VARIABLE_NAME='DB_VERSION';