索引在mysql中运行不正常

时间:2013-09-12 09:25:59

标签: mysql sql

我有一个像这样的查询:

SELECT SQL_NO_CACHE u.userid  AS userid , 
    u.userrname , pmdate  , pmid , pmmessage , imagelink  
FROM `privatemessagereceiver` JOIN privatemessage  
      ON pmrtouserid = '1' AND pmrpmid = pmid 
    JOIN user u ON u.userid = pmuserid 
    JOIN  image i ON i.imageid = u.userprofileimageid 
ORDER BY pmr_date DESC

解释:

SIMPLE  privatemessagereceiver  ref pmrpmid,pmrtouserid pmrtouserid 4   **const**   3116    Using where; Using filesort

它在索引上运行良好,执行

只需 0.0006

但是当我像这样使用那个查询时:

 SELECT SQL_NO_CACHE result.* 
 FROM ( 
    SELECT u.userid  AS userid , 
       u.userrname , pmdate  , pmid , pmmessage , imagelink  
    FROM `privatemessagereceiver` JOIN privatemessage  
           ON pmrtouserid = '1' AND pmrpmid = pmid 
       JOIN user u ON u.userid = pmuserid 
       JOIN  image i ON i.imageid = u.userprofileimageid 
    ORDER BY pmr_date DESC 
 ) as result

解释:

PRIMARY <derived2>  ALL NULL    NULL    NULL    NULL    3117    
2   DERIVED privatemessagereceiver  ALL pmrtouserid pmrtouserid 4       7054    Using where; Using filesort

1.1秒执行!

=============================================== =============== 似乎第二个查询不使用索引,因为您可以看到const未定义。我也使用了使用指数和力量指数,但这不起作用......

问题是什么,如何解决?

0 个答案:

没有答案