为什么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;

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.

You can try many steps in a nutshell

  • First perform an EXPLAIN statement and act accordingly
  • Make sure the compared attributes are of equal length
  • Make your keys as short as possible
  • Consider adding indexes where you need too, (in the WHERE clause if the values are suitable for indexing, and you perform this query very often)
  • Make an ANALYZE TABLE
  • Avoid any redundant data or with NULL values as much as possible