以下問題讓我頭疼。MySQL查詢緩存,複雜SQL查詢
我已經建立了我的MySQL服務器來使用「查詢Chaching」。
set global query_cache_size = 10000000;
看來我的查詢緩存發揮作用是因爲
SHOW STATUS LIKE 'Qcache%';
輸出如下
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 47223976 |
| Qcache_hits | 6709 |
| Qcache_inserts | 2314 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 365 |
| Qcache_queries_in_cache | 441 |
| Qcache_total_blocks | 960 |
+-------------------------+----------+
但是,nevertheles以下(複雜的查詢,有內選擇等)不會被緩存。
它還有至少0.8秒檢索此查詢的數據。我怎樣才能把mysql的這個查詢的結果存放在它的緩存中?
我試圖刪除內部的選擇,但這並沒有區別。
SELECT p.id
AS
project_id,
p.code
AS project_code,
p.title
AS project_title,
p.start_date
AS project_start_date,
p.end_date
AS project_end_date,
p.modf
AS project_modf,
(p.budget * (SELECT 1/r.VALUE
FROM exchange_rates r
WHERE r.class_currency_id = p.class_budget_currency_id))
AS
project_budget,
(SELECT z.txt
FROM sys_labels z
WHERE z.id = ps.value_label_id
AND z.lng = 'en')
AS project_status,
(SELECT z.txt
FROM sys_labels z
WHERE z.id = ps.data_label_id
AND z.lng = 'en')
AS project_color,
GROUP_CONCAT(DISTINCT pt.class_topic_id)
AS projects_thematic_area_ids,
u.id
AS project_owner_id
FROM projects AS p
LEFT JOIN projects_thematic_areas AS pt
ON pt.project_id = p.id
LEFT JOIN sys_users AS u
ON u.id = p.owner_uid
LEFT JOIN class_data s
ON s.id = p.class_status_id
LEFT JOIN class_data AS ps
ON ps.id = s.id
LEFT JOIN sys_labels AS prdz1
ON prdz1.id = prd.value_label_id
AND prdz1.lng = 'en'
LEFT JOIN sys_labels AS prdz2
ON prdz2.id = prd.data_label_id
AND prdz2.lng = 'en'
LEFT JOIN projects_locations AS pl
ON pl.project_id = p.id
LEFT JOIN class_data AS l
ON l.id = pl.class_location_id
LEFT JOIN class_data AS r
ON r._lft <= l._lft
AND r._rgt >= l._rgt
AND r._level = 1
AND r.class_id = 5
LEFT JOIN class_data AS c
ON c._lft <= l._lft
AND c._rgt >= l._rgt
AND c._level = 2
AND c.class_id = 10
LEFT JOIN projects_donors AS pd
ON pd.project_id = p.id
LEFT JOIN institutions AS i
ON pd.inst_id = i.id
LEFT JOIN class_data AS ic
ON ic.id = i.class_country_id
LEFT JOIN projects_deliverables AS d
ON d.project_id = p.id
WHERE 1 = 1
AND p.is_del = "f"
AND p.is_active = "t"
GROUP BY p.id
ORDER BY p.modf DESC,
p.code DESC
任何幫助apprechiated ....
問候
J.