0

我的查询

      SELECT Info.InfoID,
      SessionInfo.SessionInfoID,
      SessionInfo.ANI,
      ANumber.ANumber,
      tmfInfo.PTime,
      tmfInfo.PTry,
      SessionInfo.CardID,
      tmfInfo.Status
 FROM tmfInfo,
      SessionInfo,
      ANumber ,
      ANumberLog,
      ANumberGroup,
      ANumberGroupLog
WHERE (tmfInfo.IVRSessionInfoID = SessionInfo.IVRSessionInfoID)
  AND (SessionInfo.ANumberLogID = ANumber.ANumberLogID)
  AND (ANumber.AccessNumberLogID = ANumberLog.ANumberLogID)
  AND (ANumberrLog.ANumberGroupID = ANumberGroup.ANumberGroupID)
  AND (ANumberGroup.ANumberGroupLogID = ANumberGroupLog.ANumberGroupLogID)
  AND (SessionInfo.SessionCallTime >= '2013-08-01 00:00:00'
  AND (SessionInfo.SessionCallTime <= '2013-08-01 23:59:59')
  AND (ANumberLog.IsDeleted = '0')
  AND (ANumberLog.IsActive = '1')
  AND (ANumberGroupLog.IsDeleted = '0')
  AND (ANumberGroupLog.IsActive = '1')
 ORDER BY SessionInfo.SessionCallTime,tmfInfo.PTime DESC;

解释查询结果


     id select_type table   type    possible_keys   key key_len ref  rows   Extra   
       1    SIMPLE  DtmfInfo    ALL SessionInfoID                 1728919   Using temporary; Using filesort 
      1 SIMPLE  SessionInfo eq_ref  PRIMARY,SessionCallTime,ANumberLogID    PRIMARY 8   IVRDtmfInfo.SessionInfoID   1   Using where 
      1 SIMPLE  Anumber ref AnumberLogID    AnumberLogID    5   SessionInfo.ANumberLogID    1   Using where 
     1  SIMPLE  AnumberLog  eq_ref  PRIMARY,AcumberGroupID,IsActive,IsDeleted   PRIMARY 4   SessionInfo.ANumberLogID    1   Using where 
      1 SIMPLE  AnumberGroup    eq_ref  PRIMARY,ANumberGroupLogID   PRIMARY 4   AnumberLog.ANumberGroupID   1       
      1 SIMPLE  AnumberGroupLog eq_ref  PRIMARY,IsActive,IsDeleted  PRIMARY 4   Using where Using where Using where 

我在没有使用索引的 SessionInfoID 字段查询 DtmfInfo 表上有一个索引...。

任何帮助/解释都会有所帮助。使用 mysql 5.5.14

4

2 回答 2

0

查看您的查询后,我的建议是:

您可以使用 ... AND SessionInfo.SessionCallTime BETWEEN '2013-08-01 00:00:00' AND '2013-08-01 23:59:59'

我更喜欢在这部分使用 JOINS: (SessionInfo.ANumberLogID = ANumber.ANumberLogID) AND (ANumber.AccessNumberLogID = ANumberLog.ANumberLogID) AND (ANumberrLog.ANumberGroupID = ANumberGroup.ANumberGroupID) AND (ANumberGroup.ANumberGroupLogID = ANumberGroupLog.ANumberGroupLogID)

像这样修改:

SELECT * FROM tmfInfo
INNER JOIN ANumber USING (ANumberLogID) INNER JOIN ANumberLog USING (ANumberLogID) ...

当然,FORCE INDEX 可以减少您的查询时间。有时,MySQL 不会选择最佳 INDEX。

我希望它有帮助!

于 2014-01-22T15:59:44.553 回答
0

我认为你必须使用 FORCE INDEX :

查询将是这样的:

    选择信息.InfoID,
          SessionInfo.SessionInfoID,
          会话信息.ANI,
          ANumber.ANumber,
          tmfInfo.PTime,
          tmfInfo.P试试,
          SessionInfo.CardID,
          tmfInfo.状态
     FROM tmfInfo FORCE INDEX (index_name) 内连接 SessionInfo on mfInfo.IVRSessionInfoID = SessionInfo.IVRSessionInfoID ,
          一个号码 ,
          ANumberLog,
          ANumberGroup,
          ANumberGroupLog
    在哪里
      (SessionInfo.ANumberLogID = ANumber.ANumberLogID)
      AND (ANumber.AccessNumberLogID = ANumberLog.ANumberLogID)
      AND (ANumberrLog.ANumberGroupID = ANumberGroup.ANumberGroupID)
      AND (ANumberGroup.ANumberGroupLogID = ANumberGroupLog.ANumberGroupLogID)
      AND (SessionInfo.SessionCallTime >= '2013-08-01 00:00:00'
      和 (SessionInfo.SessionCallTime
于 2013-09-26T15:14:05.673 回答