我有一个Laravel 5.2应用程序,我需要对数据库进行高级查询,所以我试图使用DB::raw
表达式,主要是我的查询是这样的:
SELECT * FROM TableA AS s
LEFT JOIN TableB AS l FORCE INDEX FOR JOIN (idx_1)
ON ((s.mid = l.mid) AND (l.id = 1))
LEFT JOIN TableC AS f FORCE INDEX FOR JOIN (idx_C_1)
ON (s.mid = f.mid)
LEFT JOIN TableD as bl FORCE INDEX FOR JOIN (idx_D_1)
ON ((bl.ACid = s.ACid) AND ((bl.userid = 1) OR (bl.userid = -1)) AND (bl.type = 1))
LEFT JOIN TableE AS wl FORCE INDEX FOR JOIN (idx_E_1)
ON ((wl.sid = s.sid) AND ((wl.userid = 1) AND (wl.type = 2)))
LEFT JOIN TableF AS gwl FORCE INDEX FOR JOIN (idx_F_1)
ON ((gwl.sid = s.sid) AND ((gwl.userid = -1) AND (gwl.type = 2)))
WHERE (bl.sid IS NULL)
所以,它只是被Laravel困扰并且没有向我显示响应,所以我在PHPmyAdmin中执行它并且响应非常快。在Laravel我有这个:
$query=DB::select(DB::raw(TheQueryAbove))
->orderBy('s.reversestamp', 'asc')
->offset(0)
->limit(26)
->paginate(10);
那么,为什么需要这么长时间?或者我如何测试它以找到原因?我已经尝试过:dd(DB::select(DB::raw(TheQueryAbove)))->toSql();
没有成功,它甚至没有打印出来。谢谢!