由于开发经验较少,数据量较大(千万级,日有40万条数据左右),导致这个分页jsp页面做的效率非常低,通过一系列的优化后,效果明显得到了提高,记录一下笔记:
1、分页获取的list对象集合由于没有预料到数据量的大小,是直接一次性读取然后展示到前台的,导致查询展示效率非常低:
更改SQL语句,改为按照当前需要展示的数据行数,通过SQL的ROWNUM来进行控制查询的数据量大小,(插入数据时,打开一个数据库连接即一次性插入100条数据(可以配置的模式)):
SELECT BRAS_ADDRESS, APPLYTIMES, ALLFAILTIMES,SUCCESSRATE, RN
FROM
(SELECT BRAS_ADDRESS, APPLYTIMES, ALLFAILTIMES,SUCCESSRATE, ROWNUM AS RN
FROM
(SELECT BRAS_ADDRESS, APPLYTIMES, ALLFAILTIMES,1-ALLFAILTIMES/DECODE(APPLYTIMES,0,1,APPLYTIMES) AS SUCCESSRATE
FROM
(SELECT BRAS_ADDRESS,
SUM(DECODE(AUTNCOUNTTYPE,'REQ_CHALLENGE',APPLYTIMES,0)) AS APPLYTIMES,
SUM(DECODE(AUTNCOUNTTYPE,'ACK_CHALLENGE',APPLYTIMES,'ACK_AUTH',APPLYTIMES,'REQ_LOGOUT',APPLYTIMES,0)) AS ALLFAILTIMES
FROM T_BRAS_XXXX
WHERE READTIME between TO_DATE('2012-06-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
and TO_DATE('2012-06-12 23:59:59','yyyy-MM-dd HH24:mi:ss')
GROUP BY BRAS_ADDRESS
)
ORDER BY SUCCESSRATE
)
WHERE ROWNUM <= 180
)
WHERE RN > 165 2、建立索引,建立索引的字段不能使用函数避免索引失效;
3、建立分区表,将间隔5天的数据放在一个表中:
----------------------删除原表,新建分区表
--删除表
drop table T_BRAS_XXXX;
commit;
--创建分区表:利用Oracle11g INTERVAL进行分区的方法
create table T_BRAS_XXXX
(
BRAS_XXXX_ID integer NOT NULL PRIMARY KEY,
BRAS_XXXX VARCHAR2(64),
AUTNCOUNTTYPE VARCHAR2(50),
SUCCESSTIMES NUMBER,
APPLYTIMES NUMBER,
INTERVALTIME NUMBER,
UPDATETIME DATE DEFAULT SYSDATE,
READTIME DATE
)
PARTITION BY RANGE (READTIME)
INTERVAL (NUMTODSINTERVAL(5,'day'))
(
PARTITION T_BRAS_XXXX_PART01 VALUES LESS THAN (TO_DATE('2012-07-01 00:00:00','yyyy-MM-dd HH24:mi:ss'))
)
--保留原来创建的BRAS_XXXX_ID自增序列
--创建索引
create index idx_t_bras_XXXX on t_bras_XXXX(readtime,bras_address);
commit;
--查看分区是否成功:
select table_name,partition_name from user_tab_partitions where table_name='T_BRAS_XXXX';