编辑: usr_id,cat_ids,活动,id_1,id_2,id_3 => 索引。当然,所有 id 都是主键这是我的 SQL 表,以及我使用 codeigniter 进行的查询:
function getAllPosts($limit = 0, $start = 0)
{
$data = $this->db->select('p.*, u.nickname, u.usr_status, u.usr_rating, pc.*, c1.category as category_1, c2.category as category_2, c3.category as category_3')
->from('posts p')
->join('users u', 'p.usr_id = u.id', 'inner')
->join('post_categories pc', 'p.cat_ids = pc.id', 'inner')
->join('categories c1', 'pc.id_1 = c1.id', 'inner')
->join('categories c2', 'pc.id_2 = c2.id', 'left')
->join('categories c3', 'pc.id_3 = c3.id', 'left')
->limit($limit, $start)
->order_by('p.id', 'desc')
->where('p.active', 1)
->get()
->result_array();
也是控制器:
$config['base_url'] = base_url() . 'posts/'. $base_url;
$config['total_rows'] = $this->db->count_all('posts');
$config['per_page'] = 10;
$config['num_links'] = 5;
$config['use_page_numbers'] = TRUE;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$page = $this->uri->segment(3);
$data['posts'] = $this->m_posts->getAllPosts($config['per_page'], $page);
$data['pagination'] = $this->pagination->create_links();
那么我怎样才能加快所有这些分页的东西......因为当有 1,5k 页(15000 个帖子)时,它会减慢速度......我想我能提供的所有信息,但我可以自由地询问更多信息