As a group, having limited work

Can someone explain how the working group + + + restriction works? MySQL query:

    SELECT
        id,
        avg(sal)
    FROM
        StreamData 
    WHERE
        ...
    GROUP BY
        id 
    HAVING
        avg(sal)>=10.0 
        AND avg(sal)<=50.0   
    LIMIT 100

A request without restrictions and availability of offers is executed within 7 seconds, with a restriction - instantly, if the condition covers a large amount of data or ~ 7 seconds otherwise. The documentation says that the limit is executed after that after the group, this means that the request should always be executed within ~ 7 seconds. Please help figure out what is limited by the LIMIT clause.

+4
source share
4 answers

LIMIT 100 MySQL 100 . , Java, - , MySQL . , LIMIT 100 .

+3

SQL:

  • (FROM, JOIN)
  • (WHERE)
  • ( , , GROUP BY)
  • (HAVING)
  • (LIMIT, OFFSET)

, , , .

, , , .

+2

MySQL , , SQL_CALC_FOUND_ROWS. SELECT FOUND_ROWS(). 13.14 " ".

http://dev.mysql.com/doc/refman/5.7/en/limit-optimization.html

, , . , 100, , , .

+1
 SELECT
        id,
        avg(sal)
    FROM
        StreamData 
    WHERE
        ...
    GROUP BY
        id 
    HAVING
    avg(sal)>=10.0 
    AND avg(sal)<=50.0   
LIMIT 100
-1

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


All Articles