donglanche9257 2017-07-05 00:25
浏览 32

为什么mysql查询需要很长时间才能收到结果?

I have these 2 tables with thousands of data and i will look for matches 1:1 on both tables. I have the query below, but when the limit is already beyond 1000 the return starts to slow down, it took almost an hour before I receive a result, I am using my local xampp as database for this and have a 4G(3.4G usable) RAM PC.

Is there any other way to enhance and make the query faster?

Thank you in advance for those who will help.

SELECT a.rNum,
        a.cDate,
        a.cTime,
        a.aNumber,
        a.bNumber,
        a.duration,
        a.tag,
        a.aNumber2,
        a.bNumber2,
        'hasMatch',
        a.concatDate,
        a.timeMinutes
FROM tableOne a
INNER JOIN
tableTwo b ON a.aNumber2 = b.aNumber2 
AND a.bNumber2 = b.bNumber2
WHERE a.hasMatch = 'valid'
AND (a.duration - b.duration) <= 3  
AND (a.duration - b.duration) >= -3 
AND TIMEDIFF(a.concatDate,b.concatDate) <= 3
AND TIMEDIFF(a.concatDate,b.concatDate) >= -3
LIMIT 0,100;
  • 写回答

2条回答 默认 最新

  • doudiandi6967 2017-07-05 00:28
    关注

    The obvious question is: do you have indexes?

    As written, the best indexes to try on on tableOne(aNumber1, aNumber2) and tableTwo(bNumber1, bNumber2).

    If you provide sample data, desired results, and an explanation of what you are trying to do, there might be further suggestions.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题