Mysql improve SELECT speed

后端 未结 8 845
借酒劲吻你
借酒劲吻你 2021-01-02 05:24

I\'m currently trying to improve the speed of SELECTS for a MySQL table and would appreciate any suggestions on ways to improve it.

We have over 300 million records

8条回答
  •  走了就别回头了
    2021-01-02 06:07

    Try inserting just the needed dates into a temporary table and the finishing with a select on the temporary table for the tags and ordering.

    CREATE temporary table foo
    SELECT date, value 
    FROM table 
    WHERE date BETWEEN 'x' and 'y' ;
    
    ALTER TABLE foo ADD INDEX index( tag );
    
    SELECT date, value 
    FROM foo 
    WHERE tag = "a" 
    ORDER BY date;
    

    if that doesn't work try creating foo off the tag selection instead.

    CREATE temporary table foo
    SELECT date, value 
    FROM table 
    WHERE tag = "a";    
    
    ALTER TABLE foo ADD INDEX index( date );
    
    SELECT date, value 
    FROM foo 
    WHERE date BETWEEN 'x' and 'y' 
    ORDER BY date;
    

提交回复
热议问题