当前位置:网站首页>What is the commonly heard sub table of MySQL? Why does MySQL need tables?
What is the commonly heard sub table of MySQL? Why does MySQL need tables?
2022-06-12 02:47:00 【When the wind blows】
Why should we divide the tables
A single table is accessed and written frequently , At this time, tables can be divided according to certain business rules , This will reduce the pressure on the single gauge , The interaction between the various modules can also solve the problem frequently . It is generally recommended to control in 20 The left and right fields are appropriate
Another example is the user information table , We put the basic information of users ( Such as user id, user name ) Put it in a table , Then put other user extension information in other tables , This is because basic information is accessed very frequently , In addition, it is convenient for us to use mencache Wait for the cache to replace the query function of this table , If caching is enabled , Program changes will also be very small .
There are two ways to split a table :
1 Horizontal segmentation : Place data rows in two separate tables based on the values of one or more columns of data .
For example, the same fields are stored in two tables In some way such as 1-100 Data in user1 surface The first 101-200 Pieces of data are stored in user2 surface Or take the mold, such as the user ID%100, branch 100 A watch Bottom example :user*
CREATE TABLE `user{
{
1-100}}` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL DEFAULT '0' COMMENT ' Owner uid',
`source_id` int(11) NOT NULL DEFAULT '0' COMMENT ' resources id',
`type_mark` int(10) NOT NULL DEFAULT '0' COMMENT ' The resource type ',
......
`create_time` char(10) DEFAULT '0' COMMENT ' Input time ',
`update_time` char(10) DEFAULT '0' COMMENT ' Update time ',
PRIMARY KEY (`id`),
UNIQUE KEY `st_index` (`source_id`,`type_mark`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT=' User resource access records ';
Horizontal segmentation is usually used in the following situations . Or monthly access that the user operation log is not often viewed
• The watch is big , After segmentation, it can reduce the number of pages of data and index that need to be read during query , At the same time, it also reduces the number of layers of index , Improve query speed .
• The data in the table is inherently independent , For example, the data of each region or different periods are recorded in the table , In particular, some data are commonly used , Other data are not commonly used .
• You need to store data on multiple media .
Horizontal segmentation adds complexity to the application , It usually requires multiple table names when querying , To query all data, you need union operation . In many database applications , This complexity will outweigh the benefits it brings , Because it's just The keywords to be indexed are not large , When the index is used for queries , Add two to three times the amount of data in the table , Query also increases the number of times to read an index layer disk .
2 Vertical segmentation : Put the main code and some columns in a table , Then put the main code and other columns in another table .
If some columns in a table are commonly used , And other columns are not often used , Then vertical segmentation can be used , In addition, vertical segmentation can make data rows smaller , One data page can hold more data , It will be reduced when querying I/O frequency . The disadvantage is the need to manage redundant columns , To query all data, you need join operation .
adopt uid Associate two tables
CREATE TABLE `user` (
`uid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_name` varchar(50) DEFAULT '' COMMENT ' User login ',
`password` char(32) DEFAULT '' COMMENT ' User login password ',
`is_del` tinyint(1) unsigned DEFAULT '1' COMMENT '1, normal 2, Delete ',
`create_time` char(10) DEFAULT '0' COMMENT ' Input time ',
`update_time` char(10) DEFAULT '0' COMMENT ' Update time ',
PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT=' User basic table ';
CREATE TABLE `user_info` (
`uid` int(11) unsigned NOT NULL,
`head_img` varchar(50) DEFAULT '' COMMENT ' Head portrait ',
`nick_name` varchar(50) DEFAULT '' COMMENT ' nickname ',
`sign_content` varchar(255) DEFAULT '' COMMENT ' Individuality signature ',
`update_time` char(10) DEFAULT '0' COMMENT ' Update time ',
PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT=' User information sheet ';
边栏推荐
- Force deduction solution summary 467- unique substring in surrounding string
- Start stop script and distribution script of shell
- ARD3M电动机保护器在煤炭行业中的应用
- Bochuang smart sprint technology innovation board: annual revenue of RMB 1.1 billion, book value of accounts receivable of RMB 300million
- Selection (045) - what is the output of the following code?
- [digital signal processing] correlation function (energy signal | cross correlation function of energy signal | autocorrelation function of energy signal)
- What are the solutions across domains?
- Restful interface design specification [for reference only]
- 跨域有哪些解决方法?
- Abaqus中批量对节点施加集中力荷载
猜你喜欢

Abaqus中批量对节点施加集中力荷载

Maya Front Office Rendering plug - in Mel script Tool

One article to show you how to understand the harmonyos application on the shelves

安科瑞抗晃电产品在河北某化工项目的应用

Introduction to architecture - who moved my cake

errno: -4078, code: ‘ECONNREFUSED‘, syscall: ‘connect‘, address: ‘127.0.0.1‘, port: 3306; Postman error

errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000

Calculus review 2
![[high code file format API] downing provides you with the file format API set Aspose, which can create, convert and operate more than 100 file formats in just a few lines of code](/img/df/f4d311308e9e76c5ae9fdc11c926b8.jpg)
[high code file format API] downing provides you with the file format API set Aspose, which can create, convert and operate more than 100 file formats in just a few lines of code

博创智能冲刺科创板:年营收11亿 应收账款账面价值3亿
随机推荐
DbNull if statement - DbNull if statement
Force deduction solution summary 933- number of recent requests
oracle之用户和表空间
Force deduction solution summary -04.06 Successor
$. map(data,function(item,index){return XXX})
El upload upload file
2022 western style pastry (technician) recurrent training question bank and online simulated examination
errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000
Calculus review 2
函数模板 Function Templates
A single quarter of educational technology revenue of 230million: a year-on-year decrease of 51% and a sharp narrowing of net loss
Force deduction solution summary interview question 17.11- word distance
2022 Fujian Provincial Safety Officer C certificate (full-time safety officer) examination simulation 100 questions and answers
WPS表格 学习笔记 - 高亮显示重复值
跨域有哪些解决方法?
Apply concentrated load to nodes in batch in ABAQUS
maya前台渲染插件mel脚本工具
Transformation of geographical coordinates of wechat official account development
【点云压缩】Sparse Tensor-based Point Cloud Attribute Compression
Force deduction solution summary 699- dropped blocks