站点图标 谷姐靓号网

请教下数据库字段索引的问题-我是小小鸟

Rate this post

    SE LECT MAX(lastclick) as lastclick F ROM `manhua_arctype` W HERE reid NOT IN (0,45) LIMIT 0,1
    se lect a.typename,a.id,a.bookclickm f rom `manhua_arctype` a w here a.reid='8' and a.id<>'13587' order by bookclickm d esc limit 0,10

    Se lect a.id,a.typename,a.tuijian,a.typeimg,a.description,a.zuozhe,b.id as reid,b.typename as retypename,c.id as zuozheid F rom `manhua_arctype` a left join `manhua_arctype` b on(b.id=a.reid) left join `manhua_arctype` c on(c.typename=a.zuozhe) WHERE a.reid not in(0,45) and a.booksize<500000 order by a.bookclickm desc limit 0,7

    像上面的两个查询语句,都是从arctype中获取内容,
    现在用navicat设置的,把where后面的字段单独设置索引了,设置方式是
    名 栏位 索引类型 索引方式r
    reidreid Normal BTREE
    ID ID NORMAL BTREE
    BOOKCLICKM BOOOKLICKM NORMAL BTREE
    BOOKSIZE BOOKSIZE NORMAL BTREE

这样设置对吗?

发现一个问题
像第一个,用explain 查询以后,possible key显示 reid,reid2,reid3。
key 显示reid2
但是表里面只有字段reid,没有reid2和reid3

第二个查询以后,key显示是PRIMARY 但是表里没有这个字段

热议
2楼 loverhoc 前天23:07

not in 和 < 应该不走索引

3楼 Corei7 前天23:11

LOC是建政论坛

4楼 我是小小鸟 前天23:17

not in 和 < 应该不走索引

那应该用什么?

5楼 sdqu 前天23:21

explain xxxxxxxx
看下怎么索引的就知道了

6楼 HOH 前天23:33

自己看执行计划不就知道了

7楼 我是小小鸟 昨天01:03

explain xxxxxxxx
看下怎么索引的就知道了

explain 然后后面的查询语句吗?

8楼 iiss 昨天02:58

explain后面加上你的查询语句,能知道那些走了索引,那些是全表扫描,一点一点优化

9楼 我是小小鸟 半小时前

explain后面加上你的查询语句,能知道那些走了索引,那些是全表扫描,一点一点优化 ...

发现一个问题
像第一个,用explain 查询以后,possible key显示 reid,reid2,reid3。
key 显示reid2
但是表里面只有字段reid,没有reid2和reid3

第二个查询以后,key显示是PRIMARY 但是表里没有这个字段

10楼 我是小小鸟 23分钟前

not in 和 < 应该不走索引

not in 和>应该怎么设置会比较优化?

申明:本文内容由网友收集分享,仅供学习参考使用。如文中内容侵犯到您的利益,请在文章下方留言,本站会第一时间进行处理。

退出移动版