MySQL uses the pit

Source: Internet
Author: User

One:

MySQL defaults to the physical order of the installation records, and if you do not order BY, you may not get the expected results.

(1) Get the ID of two time points (soon)

$sql = ' Select id from apply_info where create_time< {$now} limit 1 '; (To add order by id DESC)

Get Idnow

$sql = ' Select id from apply_info where create_time>= {$yesterday} limit 1 ' (to add order by ID ASC)

Get Idyt

(2) 1000 per fetch

do{

Select User_mobile,user_from from Apply_info where ID <= {$idNow} limit 1000;

Idnow-= 1000;

Todo

} while (Idnow >= idyt)

Two:

Explain can be misleading when using limit

(1) Explain estimated number of rows, regardless of limit, may be too many rows to check for queries

(2) similar to select ... Queries from TBL LIMIT n are reported as slow queries because they are not used, (if n is small, real fast)

Profile settings Min-examined-row-limit=num of rows, number of rows checked >= This amount of queries will be reported as slow queries to avoid miscalculation

(3) Similar to this select: From TB where key_part1=? Order BY Key_part2 limit N,explain also estimates excessive number of check rows

MySQL uses the pit

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.