添加第3个INNER JOIN后,mySQL查询需要更长时间

时间:2013-05-23 19:47:18

标签: mysql

向查询添加其他联接时出现问题。

此查询需要几乎整整一分钟才能运行:

SELECT * FROM jos_mls AS mls
        INNER JOIN jos_activeagents AS active ON mls.MSTLISTBRD = active.AGENTUID
        INNER JOIN jos_agents AS agents ON active.AGENTUID = agents.AGTBRDIDMM
        INNER JOIN jos_clstmp AS cl ON mls.MSTMLSNO = cl.MSTMLSNO
    WHERE mls.MSTACTSTA != 'Inactive'
    AND mls.MSTLISTDT >= SUBDATE(CURDATE(), INTERVAL 1 DAY)

如果我省略了行INNER JOIN jos_clstmp AS cl ON mls.MSTMLSNO = cl.MSTMLSNO,则只需不到一秒钟。

jos_clstmp表只有两列。密钥和时间戳。我不认为它会给这个过程增加那么多,但它正在杀死它。

1 个答案:

答案 0 :(得分:1)

INNER JOIN jos_clstmp AS cl ON mls.MSTMLSNO = cl.MSTMLSNO

同时执行两列

mls.MSTMLSNO and cl.MSTMLSNO

有一个键/索引?