What happens faster, a large combined query with more PHP, or a few small samples with less PHP?

I am running a cron task that makes a lot of requests on the server MySQL. The big problem is that the server is very slow sometimes.

I have a relatively large query with four tables left between them and 4 smaller queries with natural jointhat also attack the first table. After you select these queries, I process the results and group them using PHP.

What I'm planning is to somehow mix these 5 queries into one big query, and then let me PHPmake a few quick ones sort()when I need it.

I am also told that MySQLqueries are faster than PHPin terms of filtering and sorting, but I'm quite worried about this when I talk about the presence of 7 or 8 left joins. Some additional information about these requests (which I cannot copy due to company policy):

  • Each selected row and field will be visited at least once.
  • Each query is based on one main table with some wing tables.
  • Each request uses the same rule GROUP BY.
  • Currently, the code PHPbreaks some secondary queries into several arrays. He should, if using a large query, also sort the results by several parameters.

So, due to these problems, and perhaps as a rule of thumb:

, PHP PHP?

+4
2

, , . MySQL, . php , ( , , ), php .

, , , . , , . script, , , , . , , , , 0,2 0,002 .

. levenshtein ( , , 2 ). mysql, , . php levenshtein , , php levenshtein .

, . , 4 , 1 . , (, , ), . , , , , php ( usort ).

, . , php script SQL-, , SQL-, .

+7

SQL . , PHP , , SQL.

0

Source: https://habr.com/ru/post/1533875/


All Articles