Mysql- sub-library sub-table partition

Big Data - points table partitioning and warehouses
set of questions:
? 1, when the sub-table data two tables are the same as if it only reduces the amount of access the table, but if the data is more or does not improve the efficiency of query
A: min table is a table of the data according to certain rules of conduct split into three tables, the data is complete data for all three tables of
2, if a sub-library sub-table combination, then a reading library, a library write, then how the data is consistent when it
why should separate database table data:
a database, a table, over time, increase the amount of customers, a data sheet is very easy to raise an even more and more on the order,
then we modify and query very time-consuming, so the need for data segmentation operation.
Partitions: a data table is divided into N blocks, in the end only logically a table, but the underlying physical block is composed of N

Sub-table: the table is to a certain rule decomposed into N separate entity table having storage space. The system needs to read and write in accordance with defined rules indicate corresponding word, then operate it.

Sub-libraries: that is divided into multiple database instances, each table name in the same database instance
when partition points table:
1, when not many people particularly large, but the data can be accessed only partition
 2, particularly when the data access people for a long table and partition dividing binding
when dividing library:
when all the data is insufficient to store a database
sub-rule repository: 1 vertical resolution: depending on the service types in different databases store different data information ( preferably 0 coupling)
vertical library -> sub-library levels -> separate read and write
to the partition table processing:
through the part table and creating summary table (table summarizes the data from all points), is added to the data summary table problems created template data to draw some kind of calculation rules add to what points table, so that the total of the table primary key violation does not occur in
the data when the query is the same, some rules are queried what points table
partitioning code analysis:

The CREATE  TABLE  the IF  the NOT  EXISTS ` User ` (    
   `id` int ( . 11 ) the NOT  NULL the AUTO_INCREMENT the COMMENT ' user ID ' ,    
   ` name` VARCHAR ( 50 ) the NOT  NULL  the DEFAULT  '' the COMMENT ' name ' ,    
   `sex` int ( . 1 ) the NOT  NULL  the DEFAULT  ' 0 ' the COMMENT ' 0 for men and 1 for women ' ,   
   PRIMARY KEY (`id`)   
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1

PARTITION BY RANGE (id) (   
     PARTITION p0 VALUES LESS THAN (3),   
     PARTITION p1 VALUES LESS THAN (6),   
     PARTITION p2 VALUES LESS THAN (9),
     PARTITION p3 VALUES LESS THAN (12),   
     PARTITION p4 VALUES LESS THAN MAXVALUE   
);

Create a user, and partition processing by id

old  table  user  drop partition p2;

 Delete partition information, but also delete the data in the partition

alter table user partition by RANGE(id)
(PARTITION p1 VALUES less than (5),   
PARTITION p2 VALUES less than (10),   
PARTITION p3 VALUES less than MAXVALUE);

 Rearrangement partition information

alter table user1 add partition(partition p4 values less than MAXVALUE);

 Add partition information

alter table user1 add partition(partition p4 values less than (17));

Add partition information, the use of the premise, no MAXVALUE
partition table code execution analysis :

The CREATE  TABLE  the IF  the NOT  EXISTS `user1` (    
  ` id` int ( . 11 ) the NOT  NULL the AUTO_INCREMENT the COMMENT ' user ID ' ,    
  `name` VARCHAR ( 50 ) the NOT  NULL  the DEFAULT  '' the COMMENT ' name ' ,    
  ` sex` int ( . 1 ) the NOT  NULL  the DEFAULT  ' 0 ' the COMMENT ' 0 for men and 1 for women ' ,   
   PRIMARY KEY (`id`)   
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
            
CREATE TABLE IF NOT EXISTS `user2` (   
   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',   
   `name` varchar(50) NOT NULL DEFAULT '' COMMENT '名称',   
   `sex` int(1) The NOT  NULL  the DEFAULT  ' 0 ' the COMMENT ' 0 to M, M 1 ' ,   
    a PRIMARY  KEY ( `id`)    
) ENGINE = MyISAM   the DEFAULT the CHARSET = UTF8 the AUTO_INCREMENT = 1

Create two tables of information

create table  user_total like user1;

Create a summary table summary table from user1

ALTER TABLE user_total ENGINE=MRG_MYISAM UNION=(user1,user2) INSERT_METHOD=LAST;

Change the data source table of the total, from tables and table user1 user2

Note: When using, you need to re-partition table partition, the first partition subdivision table engine will not be used again in the partition table, partition table can not be created

Guess you like

Origin www.cnblogs.com/lixianglong/p/12195124.html