2013-09-04 2 views
1

동적으로 계산 된 열이 MySQL의 쿼리 캐시를합니까? 나는 정확히 동일한 입력에 대해 mysql이 하나의 쿼리 범위를 넘어서 결과를 캐시 할 것인가?내가 MySQL의 쿼리를

그렇지 않은 경우 각 함수의 가능한 최소 시간이되도록 쿼리를 변경하면 어떻게됩니까?

+0

쿼리 캐시 상태 및 유지 관리를 수행 할 수 있습니다 http://dev.mysql.com/doc/refman/5.0/en/query-cache-status-and-maintenance.html – fancyPants

답변

1

MySQL은 하위 쿼리를 사용하여이 문제를 방지하기 위해, 모든 반환 된 행에 대해이 기능을 네 번을 부를 것이다, 그래서 대신

SELECT * 
FROM song 
ORDER BY Substr(pre_calculated_soundex, 1, 1) = 
        Substr(Soundex("aaaa"), 1, 1) 
               + Substr(pre_calculated_soundex 
        , 2, 1) = 
        Substr 
        (Soundex("aaaa"), 2, 1) 
        + Substr(pre_calculated_soundex, 3, 1) 
        = Substr(Soundex("aaaa"), 3, 1) 
         + Substr(pre_calculated_soundex, 4, 1 
        ) 
         = Substr(Soundex("aaaa"), 4, 1) 

의 당신은

SELECT * from (select *, Soundex("aaaa") as current_soundex from song) 
ORDER BY 
      Substr(pre_calculated_soundex, 1, 1) = Substr(current_soundex , 1, 1) 
      + Substr(pre_calculated_soundex, 2, 1) = Substr(current_soundex , 2, 1) 
      + Substr(pre_calculated_soundex, 3, 1) = Substr(current_soundex , 3, 1) 
      + Substr(pre_calculated_soundex, 4, 1) = Substr(current_soundex , 4, 1) 
관련 문제