EDIT: usr_id, cat_ids, active, id_1, id_2, id_3 => INDEXED. And of course all id are primary key Here is my SQL tables, and the query I'm making with 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();
also controller:
$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();
So how can I speed up all this pagination stuff... because when there's 1,5k pages (15000 posts) it slows all down... I guess all info I could, I gave but be free to ask for some more info
You can get a more especific optimization tip by running an explain query from you tables.
http://dev.mysql.com/doc/refman/5.0/en/using-explain.html
It identifies where you can add indexes (and what kinf of indexes) to a better performance tunning.
More pratic information can be found here: http://www.sitepoint.com/using-explain-to-write-better-mysql-queries/
Hope it helps!