dongqiao9015 2012-12-04 16:13
浏览 68
已采纳

更改Query的限制而不在CodeIgniter中再次执行它

Is it possible to change the limits of a Query without executing it again.

Here is my code:

$this->db->select("SQL_CALC_FOUND_ROWS e.emp_no, e.birth_date, e.first_name, e.last_name, e.gender, e.hire_date, t.title, s.salary, d.dept_name", FALSE)
            ->from('employees AS e')
            ->join('titles AS t', 'e.emp_no = t.emp_no')
            ->join('salaries AS s', 't.emp_no = s.emp_no')
            ->join('dept_emp AS de', 's.emp_no = de.emp_no')
            ->join('departments AS d', 'de.dept_no = d.dept_no')
            ->join('dept_manager AS dm', 'd.dept_no = dm.dept_no')
            ->order_by($sort_by, $sort_order)
            ->group_by('e.emp_no')
            ->where('t.title', $title)
                        ->limit($limit, $offset);


    $ret['rows'] = $q->get()->result(); 

I am using pagination so if I keep loading a query that return about 100,000 rows it slows down the return.

I wanted to make it faster by running the query once then changing the limit dynamically.

  • 写回答

2条回答 默认 最新

  • duanhuanzhi6431 2012-12-04 16:24
    关注

    The limit doesn't slow down your application. "SQL_CALC_FOUND_ROWS" does. It's known fact that it can slow down a query, and i mean SLOW. Check this post for benchmarks and explanation of how it works: http://www.mysqlperformanceblog.com/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应