MySQL optimization --- single score sheet, district, sub-libraries

A points table:

  Horizontal partition table: The condition data is divided into N table (e.g.: Goods table has month column, the table may be horizontally divided by month).

    Usage scenarios: a table too much data, too slow query efficiency.

     When you need to simultaneously query multiple tables are grouped table level:

       In two SQL plus intermediate block union, you will be able to merge two table data show.

      Union : merging data de-duplication.

       Union all: the data do not show the combined weight.

 

  Vertical table: The field of the table split out into a table, the relationship between two tables establish one foreign key.

    Usage scenarios: some table records the number is not much , but the field is very long, large table space, you need to perform a large number of tables when retrieving the I / O , seriously degrade the performance.

     When you need to use both two data tables, two tables can query by left join.

 

Second, the sub-library: (configuring multiple data sources)

    Vertical libraries : Depending on the different services into different database tables.

    Level sub-library: the same table of data into different databases.

 

Third, the partition:

    Table has not changed, but from a stored table data file is divided into a plurality of files, the user perceives less.

    Zoning role:     

       select *f rom dept where id in (1m2,3,4)

 

      From MySQL 5.1 adds partition ( Partition) function, the advantage has become increasingly obvious:

 

          - compared to a single disk or file system partition, you can store more data

 

          - it is easy to remove unused or outdated data

 

          - Some queries can be greatly optimized queries can be complicated

 

          - involving SUM () / COUNT () When aggregate functions, etc., may be concurrently

 

          --IO throughput greater (multiple servers)

     Zoning way:       

        Common regional approach:

 

          The Range (range )       - Based on a given continuous space, the data assigned to different partitions. 1-1011-20

 

          List (predefined list)  - Similar Range partition, the difference in List partition is based on a list of enumerated values from the partition, and the   Range partitioning is a continuum range given partition 1, 2 , 3 4 , 5, 6

 

          Hash (hash) - This mode allows the table through one or more columns Hash Key calculated by the final Hash partition corresponding to different values of code data area. For example, you can create a table of primary key partition table. The partition according to a given number, the data assigned to different partitions.

 

          Key (key value) - The above Hash an extension mode, where the Hash Key is MySQL generated by the system.

 

Guess you like

Origin www.cnblogs.com/wanghj-15/p/11470448.html