table
id
title
lid
status
...
....$sql="select id,title from table where lid=1 and status"这个要怎么索引呢?
PRIMARY KEY  (`id`)
index `status` (`status`)
index `lid` (`lid`)
我原来是这样索引的这样可以了吗?
后来又看到关于将where 后面的做一个索引
我又加了
index `lid` (`lid`,'id')这个有没有必要?index `lid_status` (`lid`,'status')我加了这个但是这个不知道要不要把id增加到里面去,比如index `lid_status` (`lid`,'status','id')这个有必要吗?还有一个问题
我在phpmyadmin里面增加索引
比如这个
index `lid_status` (`lid`,'status')

index `lid_status` ('status',`lid`)
这两个的顺序,phpmyadmin里面显示的结果是不一样的
基数不一样
这个有影响吗?谢谢

解决方案 »

  1.   

    比如这个
    index `lid_status` (`lid`,'status')

    index `lid_status` ('status',`lid`)
    这两个索引中选择一个,比如LID的基大,则用第一个,否则反之。
      

  2.   

    具体选择哪个还要看一下搜索
    index 'lid_status'('lid','status')
    index 'lid_status'('status','lid')
      

  3.   

    还没有回答这个$sql="select id,title from table where lid=1 and status"我原来是这样索引的
    index `status` (`status`)
    index `lid` (`lid`)这样可以了没有?
    还是一定要写成index 'lid_status'('lid','status')这样
      

  4.   

    我去掉了索引,再分别创建
    index `status` (`status`)
    index `lid` (`lid`)

    index 'lid_status'('lid','status'
    做了一万次的查询,这三个sql花的时间基本一样,奇怪