日期:2014-05-19  浏览次数:20499 次

关于表建索引的问题

一个表tb_01共有50个字段,其中关建字段内容如下:

id_shch_b,   page_no,   gx_int,   gongxh,   gx_int_q,   gx_int_x,   gongxh_q,   gongxh_x,   ......
DA0000001,   1                 1               A1 0                   3
DA0000001,   1                 3               B1 1                   4
DA0000001,   1                 4               C1 3                   6
DA0000001,   1                 6             D1   4                   8
DA0000001,   1                 8               E1 6                   0
...
DA0000005,   3                 1               A1 0                   2
DA0000005,   3                 2               A2 1                   3
DA0000005,   3                 3               A5 2                   6
DA0000005,   3                 6               A6 3                   7
DA0000005,   3                 7               B3 6                   0
...

其中,id_shch_b,   page_no,   gx_int是主键值。


但常用的查条件会是:
select   *   from   tb_01   where   id_shch_b= ' '   and   page_no= ' '   and   gx_int_q= ' '
select   *   from   tb_01   where   id_shch_b= ' '   and   page_no= ' '   and   gx_int_x= ' '
select   *   from   tb_01   where   id_shch_b= ' '   and   page_no= ' '   and   gx_int= ' '

select   a.*,   b.gongxh
from   tb_01   a
left   outer   join   tb_01   b   on   a.id_shch_b=b.id_shch_b   and   a.page_no=b.page_no   and   a.gx_int=b.gx_int_q
where   A.id_shch_b= ' '   and   A.page_no= ' '   and   A.gx_int= ' '


因为gx_int_q,   gx_int_x两个字段,经常参于查询,为了提高查询的速度,请问题应该如何建索引。

需要另外建如下两个索引吗?
id_shch_b,   page_no,   gx_int_x
id_shch_b,   page_no,   gx_int_q


因为其它查询的需要,现在已经新建了5个索引了,因为索引太多,存盘速度明显变慢。请问应该如何优化索引呢?




------解决方案--------------------
看看id_shch_b, page_no, gx_int_x
id_shch_b, page_no, gx_int_q 的分布情况
前导列索引设置最为重要
------解决方案------