Welcome Guest, Not a member yet? Register   Sign In
when use order_by/group_by with join evrything slow
#1

[eluser]elbana[/eluser]
iam new with codeigniter i try to get data but evrything become slow

Code:
public function last_updates()
{
  
       $this->db->select('p.* , v.*');
       $this->db->from('prog as p');
       $this->db->join('prog_ver as v','v.mslug = p.slug');
       $this->db->where('p.os','Windows');
       $this->db->where('p.status',0);
       $this->db->group_by('p.adddate');
       $this->db->order_by('v.reldate',"DESC");
       $this->db->limit(10);

      $query = $this->db->get();
  return $query->result_array();
}
when i stop order_by and group_by functions it go fast
#2

[eluser]CroNiX[/eluser]
If you run that query in straight sql, it would be just as slow because of all of the extra processing "group by" has to do. The main way to speed those up are to make sure those fields have an index. Anything you "sort by", "group by", use "where" on, etc should be indexed, especially on larger tables or tables that can grow large. Its also a lot faster to select individual fields than use select *. You should read up on db indexes.
http://www.informit.com/articles/article.aspx?p=377652
#3

[eluser]elbana[/eluser]
thanks , but what i have to change in my code after create the indexs
#4

[eluser]elbana[/eluser]
thanks alot it work very fast now
#5

[eluser]CroNiX[/eluser]
Glad it helped.




Theme © iAndrew 2016 - Forum software by © MyBB