Database search optimization |
[eluser]zovar[/eluser]
I have a database with 1 million records. My search query (simplified) is as follows: $this->db->select('*')->from('user_data'); $this->db->where('name', 'Isaac'); $this->db->where('age >=', 20); $this->db->where('age <=', 100); $this->db->where('height >=', 20); $this->db->where('height <=', 100); $this->db->where('weight >=', 20); $this->db->where('weight <=', 100); $this->db->get(); The question is: will mysql apply all of these conditions to every table row, or will it first select all Isaacs and then search for age>=20 and age<100 etc etc If I have only 5 Isaacs in my database, will mysql spend tons of time on going through 1 million records and comparing age, weight, height when it already selected Isaacs first?
[eluser]benurv[/eluser]
It depends if you correctly index your tables or not (primary key & index) are the most important i think: http://dev.mysql.com/doc/refman/5.0/en/m...dexes.html you could enable benchmarking, and measure the differences, it times your query's and shows the result. see the CI output for more info. You could try playing with Mysql between 20 and 40 instead of WHERE >= 20 AND, ...
|
Welcome Guest, Not a member yet? Register Sign In |