我有一个MySQL查询语句,我加载到我的主页控制器中,在运行Codeigniter的 $this->output->enable_profiler(TRUE);
后,我得到了一个执行时间为5.3044
在我的模型中的查询:
class Post extends CI_Model {
function stream($uid, $updated, $limit) {
$now = microtime(true);
$sql = "
SELECT
*
FROM
vPAS_Posts_Users_Temp
WHERE
post_user_id = ?
AND post_type !=4
AND post_updated > ?
AND post_updated < ?
UNION
SELECT
u.*
FROM
vPAS_Posts_Users_Temp u
JOIN
PAS_Follow f
ON f.folw_followed_user_id = u.post_dynamic_pid
WHERE u.post_updated > ?
AND post_updated < ?
AND (( f.folw_follower_user_id = ? AND f.folw_deleted = 0 )
OR ( u.post_passed_on_by = f.folw_follower_user_id OR u.post_passed_on_by = ? AND u.post_user_id != ? AND u.post_type =4 ))
ORDER BY
post_posted_date DESC
LIMIT ?
";
$query = $this->db->query($sql, array($uid, $updated, $now, $updated, $now, $uid, $uid, $uid, $limit));
return $query->result();
}
}
有什么我可以在这里做的来提高执行时间,从而增加我的页面载入速度吗?
编辑
解释结果
MySQL Workbench可视化解释
SELECT * FROM
,而是指定您需要的列。此外,我可以假设vPAS_Posts_Users_Temp是一个视图吗?如果是这样,请提供该视图的定义。 - deroby