日期:2014-05-16  浏览次数:20944 次

为什么加了索引执行更慢了呢?
表结构如下:
SQL code
-- Create table
create table T_GG_MOBILENO_SENDABLE
(
  sendable_id          NUMBER(10) not null,
  mobileno_id          NUMBER(10),
  mobileno             NUMBER(11),
  mobileno_kind        NUMBER(4),
  mobileno_age         NUMBER(4),
  mobileno_money       NUMBER(8),
  mobileno_area        NVARCHAR2(6),
  mobileno_sex         NUMBER(1),
  mobileno_double      NUMBER(1),
  mobileno_treble      NUMBER(1)
)
tablespace GXT
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Create/Recreate indexes 
create index INDEX_T_GG_MOBILENO_AGE on T_GG_MOBILENO_SENDABLE (MOBILENO_AGE)
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create index INDEX_T_GG_MOBILENO_AREA on T_GG_MOBILENO_SENDABLE (MOBILENO_AREA)
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create index INDEX_T_GG_MOBILENO_DOUBLE on T_GG_MOBILENO_SENDABLE (MOBILENO_DOUBLE)
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create index INDEX_T_GG_MOBILENO_KIND on T_GG_MOBILENO_SENDABLE (MOBILENO_KIND)
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create index INDEX_T_GG_MOBILENO_MONEY on T_GG_MOBILENO_SENDABLE (MOBILENO_MONEY)
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create index INDEX_T_GG_MOBILENO_SENDABLE on T_GG_MOBILENO_SENDABLE (MOBILENO)
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create index INDEX_T_GG_MOBILENO_SEX on T_GG_MOBILENO_SENDABLE (MOBILENO_SEX)
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create index INDEX_T_GG_MOBILENO_TREBLE on T_GG_MOBILENO_SENDABLE (MOBILENO_TREBLE)
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Create/Recreate primary, unique and foreign key constraints 
alter table T_GG_MOBILENO_SENDABLE
  add constraint PK_T_GG_MOBILENO_SENDABLE primary key (SENDABLE_ID)
  using index 
  tablespace GXT
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );




SQL语句:
SQL code

select  count( distinct( MOBILENO))
  from t_gg_mobileno_sendable a
 WHERE (MOBILENO_KIND = 1
        and MOBILENO_AGE >= 0 and MOBILENO_AGE <= 99 and
       MOBILENO_MONEY between 0 and 999)



Where后面的条件是动态的 所以有的索引暂时没有用到

这是为什么捏?如果对count加强制索引 怎么加?



------解决方案--------------------


贴下执行计划.
------解决方案--------------------

把表分析一下,在看看执行计划,是否有变。
------解决方案--------------------
索引的规则挺多的,应该是某些索引失效

------解决方案--------------------
MOBILENO_AGE
MOBILENO_MONEY 的查询条件都要+ >0 的条件么?
------解决方案--------------------
还是看下执行计划 看下究竟慢在哪里
------解决方案--------------------
同上。没有环境分析不出来,贴出执行计划帮你分析
------解决方案--------------------