我有一個查詢是這樣的:PHP MySQL的儲蓄查詢結果
$get_feed_amount = mysql_query("
SELECT COUNT(*) as num
FROM `migo_feeds`
WHERE
(
(
feed_type='10' ||
feed_type='11' ||
feed_type='28' ||
feed_type='27' ||
feed_type='30' ||
feed_type='31'
)
AND
(
from_id IN (
SELECT DISTINCT from_id
FROM `migo_relations`
WHERE (
(to_id='".$_SESSION['user_id']."')
AND
(rel_processed='1' AND rel_accepted='1')
)
)
OR
to_id IN (
SELECT DISTINCT from_id
FROM `migo_relations`
WHERE (
(to_id='".$_SESSION['user_id']."')
AND
(rel_processed='1' AND rel_accepted='1')
)
)
OR
from_id=".$_SESSION['user_id']."
OR
to_id=".$_SESSION['user_id']."
)
AND
feed_deleted='0'
);
");
,你可以看到即時在此查詢
也是後來我做查詢,這樣的媒體鏈接選擇朋友兩次:
$migo_groups = mysql_query("
SELECT
group_id,
group_title,
group_desc,
group_cat_name,
group_area,
group_city,
group_quarter,
group_pic,
group_tmb,
group_members_amount
FROM
`migo_groups`
WHERE (
group_type=1
AND
group_id IN (
SELECT group_id
FROM `migo_group_membership`
WHERE (
membership_type IN (1,2,3)
AND
to_id IN (
SELECT DISTINCT from_id
FROM `migo_relations`
WHERE (
(to_id='".$_SESSION['user_id']."')
AND
(rel_processed='1' AND rel_accepted='1')
)
)
)
)
)
ORDER BY RAND() LIMIT 4;
");
再次挑選朋友.. 這似乎有點浪費資源。特別是如果表格非常大,事情可能需要永久加載,甚至根本不需要加載。
我的問題是,我可以在開始時只是做一個朋友查詢,並在任何地方使用結果?這有什麼好處?
我在想也許是將數據保存在一個數組或其他東西中,是不是很糟糕?什麼是運行事物的最佳方式?
問候, 亞歷山大
嘗試使用緩存。 – pltvs 2011-06-07 11:38:24
我該怎麼做? – Alexander 2011-06-07 11:39:02
你可以使用mysql視圖 – 2011-06-07 11:42:43