当前位置:网站首页>MySQL ten million level sub table optimization
MySQL ten million level sub table optimization
2022-07-20 08:09:00 【Andy Lau in IT industry】
demand : With the increase of data volume, a single table can no longer support business , Ten million level data query is slow
Mysql Data optimization scheme :
- Scheme 1 : Use myisam Optimize the horizontal table
- Option two : Use mysql Partition optimization
One :Myisam Horizontal zoning
1、 Create a horizontal sub table user_1:
-- Create a horizontal sub table
create table user_1(
id varchar(50) PRIMARY key COMMENT ' Primary key id',
user_name varchar(50) DEFAULT null COMMENT ' User name ',
creator varchar(50) DEFAULT null COMMENT ' The creator ',
create_date datetime DEFAULT null COMMENT ' Creation time ',
updater varchar(50) DEFAULT null COMMENT ' Update the ',
update_date datetime DEFAULT null COMMENT ' Update time '
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=' user 1 surface ';
2、 Create a horizontal sub table user_2:
create table user_2(
id varchar(50) PRIMARY key COMMENT ' Primary key id',
user_name varchar(50) DEFAULT null COMMENT ' User name ',
creator varchar(50) DEFAULT null COMMENT ' The creator ',
create_date datetime DEFAULT null COMMENT ' Creation time ',
updater varchar(50) DEFAULT null COMMENT ' Update the ',
update_date datetime DEFAULT null COMMENT ' Update time '
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=' user 2 surface ';
3、 Create a horizontal sub table user
-- Create a master table
create table user(
id varchar(50) PRIMARY key COMMENT ' Primary key id',
user_name varchar(50) DEFAULT null COMMENT ' User name ',
creator varchar(50) DEFAULT null COMMENT ' The creator ',
create_date datetime DEFAULT null COMMENT ' Creation time ',
updater varchar(50) DEFAULT null COMMENT ' Update the ',
update_date datetime DEFAULT null COMMENT ' Update time '
)ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 INSERT_METHOD=LAST UNION=(
`user_1`,`user_2`);
4、 Add partition user_3
create table user_3(
id varchar(50) PRIMARY key COMMENT ' Primary key id',
user_name varchar(50) DEFAULT null COMMENT ' User name ',
creator varchar(50) DEFAULT null COMMENT ' The creator ',
create_date datetime DEFAULT null COMMENT ' Creation time ',
updater varchar(50) DEFAULT null COMMENT ' Update the ',
update_date datetime DEFAULT null COMMENT ' Update time '
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=' user 3 surface ';
Initialization data
-- insert data
insert into user_1(`id`,`user_name`,`create_date`,`update_date`) values ('1',' Zhang San ',now(),now());
insert into user_1(`id`,`user_name`,`create_date`,`update_date`) values ('2',' Li Si ',now(),now());
insert into user_2(`id`,`user_name`,`create_date`,`update_date`) values ('1',' Wang Wu ',now(),now());
insert into user_3(`id`,`user_name`,`create_date`,`update_date`) values ('3',' Zhao Liu 3',now(),now());
insert into user(`id`,`user_name`,`create_date`,`update_date`) values ('4',' laozhao 1',now(),now());
Verify the data results : adopt
5、 Add the partition again
alter table user UNION=(`user_1`,`user_2`,`user_3`);
Parameter description
1: table ENGINE It has to be for :MyISAM, The total table must be MRG_MyISAM
2:INSERT_METHOD: The default location for inserting data into the master table :
0: Inserting... Is not allowed
1: Allow to insert
FIRST:merge First table of
LAST:merge The last table of
An unexpected error occurred
1168 - Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
Problem location :
- table MERGE The engine is only applicable to MYISAM surface
- union A table that does not exist or is not in the same database
- The structure of the table is inconsistent
Official website address :https://dev.mysql.com/doc/refman/8.0/en/merge-storage-engine.html
边栏推荐
猜你喜欢
. Net full scene development has finally arrived
Spiderpi convenient operation manual
四剑客与Code Review的恩怨情仇:“始乱终弃”到“浪子回头”
Where is Jay Chou's album "the greatest work"? Dangbei box enjoys chairman Zhou's latest MV
Yolov7 - configure yolov7 (I)
Improvement 21 of yolov5: cnn+transformer - replace the backbone network with fast and strong lightweight backbone efficientformer
Summary of interview questions (4) TCP / IP four-layer model, three handshakes and four waves, one more and one less. No, the implementation principle of NiO
This free code snippet manager is open source!
Comparative analysis of single sign on SSO of JWT, CAS, oauth2 and SAML
一篇文章掌握Mysql
随机推荐
Etcd database source code analysis -- ServerV2 interface implementation
[signal conditioning] sharing practical experience of building CE amplifier with "crystal triode"
MySQL获取当天,昨天,本周,上周,本月,上月的起始时间和结束时间的方法
An article enables you to thoroughly understand the definitions of common terms about performance testing
WinForm layout and control adaptive resolution and prevention of dislocation
How to customize Net6.0 logging
Overlay number
SSM环境整合
Thymeleaf 视图集成
【信号调理】用“晶体三极管”搭建CE放大器的实操经验分享
Selnium get JS content
Idea SVN trunk merge branch version missing ranges exception error:svn: e195016
Mysql 面向企业级开发(一)
BERT-tutorial
SQL SERVER 发送邮件失败 提示必须制定收件人
四剑客与Code Review的恩怨情仇:“始乱终弃”到“浪子回头”
21特征值和特征向量
Problème de partition des entiers
STM32 SCT memory control
上海域格4G模块PPP拨号相关问题