MySQL Enhancing Performance without Cache

前端 未结 1 1743
余生分开走
余生分开走 2021-01-28 23:03

I am using MySQL version 5.5.14 to run the following query from a table of 5 Million rows:

SELECT P.ID, P.Type, P.Name, P.cty
     , X(P.latlng) as \'lat\', Y(P.         


        
1条回答
  •  -上瘾入骨i
    2021-01-28 23:09

    Good indexes are the ones with high selectivity. Your conditions are mostly range conditions and this poses a limit on the fields that can be used in a composite index.

    Possible indexes to investigate (composed from those fields that have an equality check with the addition in the end, of one field with a range check):

    (act, Type, tn, flA)
    
    (act, Type, tn, cDate)
    
    (act, Type, tn, nb)
    

    To check selectivity without creating indexes, you could use:

    SELECT COUNT(*)
    FROM PIG P 
    WHERE act='1' 
      AND Type = 'g' 
      AND tn = 'l' 
      AND flA >= '1615'
    

    and

    SELECT COUNT(*)
    FROM PIG P 
    WHERE act='1' 
      AND Type = 'g' 
      AND tn = 'l' 
      AND cDate >= NOW() 
    

    and

    SELECT COUNT(*)
    FROM PIG P 
    WHERE act='1' 
      AND Type = 'g' 
      AND tn = 'l' 
      AND nb <= '5' 
    

    and compare the output with the 742873 you have from the spatial index.

    0 讨论(0)
提交回复
热议问题