表定义:
create table HISLIST
(
ID INTEGER not null,
SERVICE_CODE VARCHAR2(14),
USER_NAME VARCHAR2(30),
CERTIFICATE_CODE VARCHAR2(20),
ONLINE_TIME VARCHAR2(21),
OFFLINE_TIME VARCHAR2(21)
)
定义的索引:
ID主键
CERTIFICATE_CODE 索引1
ONLINE_TIME 索引2
表中有1200万记录
第一个查询语句:查询结果4条记录,用时20ms.
select count(id)
from HISLIST
where online_time >= '2011-04-13 00:00:00'
and online_time <= '2011-05-13 12:00:00'
and certificate_code = '643121198011000555';
第二个查询语句:查询结果40000条记录,用时40000ms.
select count(id)
from HISLIST
where online_time >= '2011-04-13 00:00:00'
and online_time <= '2011-05-13 12:00:00'
and certificate_code = '643121198011000111';
后将ONLINE_TIME 索引2改为DESC类型的,查询语句如下
select count(id)
from pblog_hisclientlist
where online_time between '2011-04-13 00:00:00' and '2011-04-14 00:01:00'
and certificate_code = '643121198011000111';
效果和原来一样,
请大家帮忙分析一下原因,是索引的建的原因,还是SQL写的有问题。
------解决方案--------------------------------------------------------
帮你回一下。