MySQL query the first few rows

Source: Internet
Author: User

When a data table contains a large amount of data, you only need to check the values of some of the fields, instead of all the data, you only need to check a few rows. At this time, you can use limit


For example:

1. select * from tags limit 4; it is to take 4 rows of data and see what the values of id or other required fields are.
The query result is: id = 102 or...

2. explain select * from tags where id = 102; check whether the id or other fields in the table are valid for the index.

+ ---- + ------------- + ---------- + ------ + --------------- + ------ + --------- + ------- +
| Id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+ ---- + ------------- + ---------- + ------ + --------------- + ------ + --------- + ------- +
| 102 | SIMPLE | tags | ALL | NULL | 6226057 |
+ ---- + ------------- + ---------- + ------ + --------------- + ------ + --------- + ------- +

It can be seen that the id index is not used here [the index created for id is generally PRIMARY]




Author hllnihao

Related Article

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.