MySQL (optimized) query an efficiency comparison that filters a field and queries a field directly on that bar

Source: Internet
Author: User

 

Check all, 10,000 times,

$sql = "SELECT * from Mh_user where (username= ' 333 ') and (password= ' xxx ')";

Total Time 1.1420359611511

Query the username field, 10,000 times.

$sql = "Select username from Mh_user where (username= ' 333 ') and (password= ' xxx ')";
for ($i =0; $i < 10000; $i + +) {
$result = $this->db->select ($sql);
}

Total Time 0.94627690315247

Also can be seen, in apache2.4.4, MySQL 5.6.12, PHP 5.4.12, up to million times per second (table structure is simple, small capacity situation),

If the table is large, the effect may be more obvious, the first query a field

MySQL (optimized) query an efficiency comparison that filters a field and queries a field directly on that bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.