codeigniter mysql查询_MySQL查询性能和Codeigniter (MySQL Query Performance and Codeigniter)

2014-02-09 10:11:49

1

I have this MySQL query which I am loading in to my home controller and after running Codeigniter's $this->output->enable_profiler(TRUE); I get an execution time of 5.3044

The Query inside my model:

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();

}

}

Is there anything I can do here to improve the execution time and therefore increase my page load?

Edit

Explain Results

ojfLC.png

MySQL Workbench Visual Explain

wbis5.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值