Speed of reading mysql from php

Source: Internet
Author: User
The speed of php reading mysql is a database with about 10 thousand records.

Select id, old_id, iid, title1, page_type from mayi_news where page_type = 'test'

The speed is 32 milliseconds.

Select id, old_id, iid, title1, page_type from mayi_news where page_type = 'test' order by id desc

The speed is 480 milliseconds.

Why are there so many differences?



Another question is: I recently checked that the moderator provided the EXPLAIN test performance. I don't know how to optimize the following results?


Reply to discussion (solution)

Extra columns have filesort
Indicates that temporary files are used as the carrier of the index tree during sorting, which obviously causes a speed decrease.
Observe that the possible_keys and Key columns are empty, indicating that no index is used.
Therefore, you can create an index on id and page_type and observe the effect.

Is id a primary key? why is there such a big difference in sorting by primary key?

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.