我正在使用codeigniter和mysql並應用於具有200 MB內存和1 GB CPU的服務器,在 表中獲得40.000行(index:idx_cat)和44行(index:primary)類別和我需要得到最高的,然後4在每個類別中,這是我的查詢codeigniter,mysql查詢性能問題
SELECT id,title,preview,created,image,dummy,name
FROM
(
select news.id AS id,news.title AS title,preview,created,news.image,category_id ,
@num := if(@cat = category_id, @num + 1, 1) as row_number,
@cat := category_id as dummy,
name,d_order
from news use index (idx_cat) inner join category b on category_id=b.id
where
news.category_id in (9,8,3,35,57,56,15,58,41,42,43,44,34,52,37,38,36,11) and
news.status = 1
having row_number <= 4
order by dummy ASC,news.created desc
) as a
order by d_order ASC,created DESC
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL **29639** Using filesort
2 DERIVED b ALL PRIMARY,id NULL NULL NULL **44** Using where; Using temporary; Using filesort
2 DERIVED news ref idx_cat idx_cat **4** b.id 846 Using where
,並得到了其他6個簡單的加入像
select id,name from others a inner join b on a.cat_id = b.id
該網站加載相當快大約1秒或2秒之上,但如果在另一個選項卡中打開,而加載它的速度慢一點5-7s。
奇怪的是,CPU使用率達到100%,內存使用得到了+ _ 40 MB來完成一個視圖(確定沒有其他打開),但CI概要其只是用戶4MB。
我也有加載模型,助手,和圖書館點播只是兩個(網址和形式),我把自動載入文件。
如果我開那麼5到10個窗口它說出來的內存,有你們這個東西是什麼發生任何建議,這是推動我瘋了-_-
很久沒有互聯網了,我有這個,它的工作原理非常感謝:D –