dongle7553 2009-01-06 22:23
浏览 48
已采纳

我的MySQL查询出了什么问题?

I'm not getting any errors as such just a minor performance issue.

EXPLAIN
SELECT
a.nid,
a.title,
a.uid,
b.parent,
b.weight,
c.name,
d.value
FROM table1 AS a INNER JOIN table2 AS b ON a.vid = b.vid AND a.status = 1
INNER JOIN table3 AS c ON c.uid = a.uid
INNER JOIN table4 AS d ON d.content_id = a.nid AND d.value_type = 'percent' AND d.function = 'average'

When I look at which tables are being referenced, everything is fine, but from table4 where it should only be selecting the "value" field, I'm getting an ALL being called...

id  select_type     table   type      possible_keys                                   key     key_len   ref                   rows  Extra
1   SIMPLE          a     ref     PRIMARY,vid,status,uid,node_status_type,nid   status  4         const                 1    
1   SIMPLE          b     eq_ref    PRIMARY                                         PRIMARY 4         databasename.a.vid    1    
1   SIMPLE          c     eq_ref    PRIMARY                                         PRIMARY 4         databasename.a.uid    1   Using where
1   SIMPLE          d     ALL     NULL                                          NULL      NULL      NULL                  2     Using where

As you can see, it's selecting * from the final table (d). Why is it doing this when I only need ONE field selected from it? Can anyone help me out?

  • 写回答

3条回答 默认 最新

  • ds000001 2009-01-06 22:26
    关注

    ALL means all rows, not all columns. Since it says there are no possible keys, I'd guess that you don't have an index on d.content_id or d.value_type or d.function.

    If you wanted to be fancy, you could put an index across all 3 of those columns.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算