V
V
Vincent12017-01-10 16:21:02
MySQL
Vincent1, 2017-01-10 16:21:02

SQL query optimization?

SELECT A.name, B.phone, %еще 20 полей%... 
FROM  `alpha` d
LEFT OUTER JOIN beta B ON A.name= B.name
WHERE A.age > 20 LIMIT 5000, 3000

This request is not fulfilled due to exceeding some hosting limits.
If you specify offset in LIMIT =0, then the data will be received. But if offset=5000, then it doesn't work anymore.
As far as I understand, the engine still shovels these 5000 lines, despite the fact that they should not be in the output.
How to optimize the query so that you can receive data with any offset ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vincent1, 2017-01-10
@Vincent1

Solved the problem using subqueries.

SELECT A.name, B.phone, %еще 20 полей%... 
FROM  
  (SELECT * FROM `alpha` A.age > 20 LIMIT 5000, 5000) AS A
LEFT OUTER JOIN beta B ON A.name= B.name

Many thanks to everyone for the help.

E
Evgeny Bukharev, 2017-01-10
@evgenybuckharev

EXPLAIN SELECT A.name, B.phone, %еще 20 полей%... 
FROM  `alpha` d
LEFT OUTER JOIN beta B ON A.name= B.name
WHERE A.age > 20 LIMIT 5000, 3000

D
Dmitry Bay, 2017-01-10
@kawabanga

about explain correctly speak.
And why do you need to link tables without a key? try adding indexes on a.name b.name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question