MySQL in query optimization

Source: Internet
Author: User
Tags mysql in

November 29, 2014 21:01:01

Scenario: Sometimes there are very many discontinuous values in the select in statement that query the database, which can affect query efficiency

Method: Convert a select in query into multiple select between and statements

Code: Core code (ID to sort order)

1      Public functionGroup()2     {3         //$a = array (1,2,3,5,7,8,9);4         $a=Array(1,3,4,5,7,8,9);5         $len=Count($a);6         $cur= 0;//subscript of the currently traversed element7         $pre=$a[0]; The value of the previous element8 9         $new=Array(' 0 ' + =Array($a[0]));Ten          for($i= 1;$i<$len;$i++) { One             if(($a[$i] -$pre) = = 1 ) { A                 $new[$cur][] =$a[$i]; -}Else { -                 $cur=$i; the                 $new[$cur][] =$a[$i]; -             } -             $pre=$a[$i]; -         } +  -         Print_r($new); +}

Results

1 Array2 (3[0] = =Array4         (5[0] = 16         )7 8[1] = =Array9         (Ten[0] = 3 One[1] = 4 A[2] = 5 -         ) -  the[4] = =Array -         ( -[0] = 7 -[1] = 8 +[2] = 9 -         ) +  A)

MySQL in query optimization

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.