Mysql query optimization, sorting, and other special use - Annual Summary

A. Optimization

Table 1. Data related query optimization

                            1. The first implementation where filtered and joint investigation;
                            2 suitable combination index,
                            3. field values:
                                1) make use of a digital type
                                2) setting default values, to avoid the use of field where null =;
                            4. certain keywords caution / character (! in, =, *) , the appropriate use exists / not exists;

2.limit optimization

    Normal:
           the SELECT * `key` the FROM table1 the WHERE> 1000000 the LIMIT 100000,5;
     inline: a table inline - temporary table (a table using the result set derived limit)
           the SELECT * a the FROM table1
           the INNER the JOIN (the SELECT` key` AS id FROM table1 WHERE `key`> 1000000 LIMIT 100000,5) b ON a.`key` = b .id;

3. Sort optimization:
                                

  1) to make use of the positive sequence index ordering, without using a separate order by

  2) When using the index order: combination index - index and field index sort fields in combination where

 

II. Query result set sorting number

       SELECT @rank: = @ rank + 1 AS rank_no // @ rank temporary variables, @rank: = @ rank + 1 the initial value + 1'd
       FROM 
                 (the SELECT Field FROM table ORDER BY `key` DESC) a, // results set sorting
                 (SELECT @rank: = 0) b // temporary variable initial value

III. Other

1. The initial value of a specified increment primary key

     alter table tbname auto_increment = x;

2.lpad ((str, just padstr))

         Padstr of string str, fill the left until it reaches the length len characters in length, then return str, len If the length is longer than str, it will be amputated to len characters;

3. Given a date, returns a few days

        TO_DAYS(date)

4. Analyzing whether the value of a field containing a specified character string

        INSTR (filed, String)

5.replace into: This line has a data replacement (primary key or unique index determination)

 

Need to modify the data source configuration after 6.java project mysql jar 6.0 upgrade package  


     1.<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property> 
     2.url 多加时区配置 serverTimezone=GMT%2B8

Published 21 original articles · won praise 10 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_37794901/article/details/104058627