当前位置:网站首页>Linux server development, MySQL index principle and optimization
Linux server development, MySQL index principle and optimization
2022-07-07 07:54:00 【Tuen Mun pheasant calls me chicken】
Recommend a free open course of zero sound College , Personally, I think the teacher spoke well , Share with you :Linux,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK, Streaming media ,CDN,P2P,K8S,Docker,TCP/IP, coroutines ,DPDK Etc , Learn now
1. summary
- Indexes are physical concepts , Constraints are logical concepts .
- The difference between a primary key index and a unique index is that the primary key index cannot be empty , A unique index can have one NULL value .
- Component table PRIMARY KEY Create a primary key for the display , If it is not created, it will be in UNIQUE NOT NULL Select the first one as the primary key . If there is no non empty unique index ,MySql Then automatically generate 6 byte _rowid A primary key .
- A foreign key constraint is a constraint , To ensure the integrity of the two tables , It's transactional , Try not to use .

2.B+ Trees
The full name of binary tree is balanced binary search tree ,B+ Tree is a multi-path balanced search tree , A characteristic of the search tree is that traversal in middle order is an ordered structure . The balance is the height of the tree , The aim is to provide a stable search time complexity , It is the time complexity that remains stable after adding, deleting, modifying and checking . If it becomes a linked list, it will become O(n) Time complexity of , Is not a balanced .B+ The tree is a very balanced , It is mainly reflected in that leaf nodes are on the same layer , The height of each link is the same .
The height of the tree represents the number of comparisons , Red and black trees are tall and thin , Used in memory ; and B+ The tree is short and plump , Used to access disks . One disk IO yes 10ms about , A memory access 100us about , Millions of differences .
B+ How the tree maps to the disk ? A node is 16K The data of , When accessing disk data, the size of the data pulled is usually 4K or 8K, It's exactly an integral multiple , The configuration file can also be modified .B+ One node of the tree must store at least two rows of data . If you exceed 16K, The excess will be mapped to the shared table space . Non leaf nodes store index information , Leaf nodes store data information .
B+ Tree range query LIMIT1,5, Adjacent leaf nodes refer to each other , Avoid backtracking queries .
Auto increment can be used if the data is large bigint type , If every second 1 Billion data , need 5849 It takes years to run out !
myisam in frm At the end is the table information file ;myd It's a data file , Use heap table to organize storage ;myi Is the index file , use B+ Tree organization storage .
inodb in frm Is the table information structure ;bbd It's a data file , use B+ A clustered index created by a tree primary key . When using a secondary index to find , Will find the primary key id, Through the primary key id Find row data , This is called a return table query .
inodb By segment 、 District 、 Page composition , Segments are divided into data segments , Index segment , Rollback segments, etc ; The size of the area is 1MB(1 Zones by 64 Composed of consecutive pages ); The default value of the page is 16K; Page is a logical page , The physical size of the disk is generally 4K perhaps 8K; In order to ensure the continuity of pages in the area , The storage engine usually requests from the disk at one time 4-5 Districts .

- Buffer pool
- Change buffer: Cache non unique indexes DML Add, delete and change operation , The cache first . If it is a unique index, write the log first , Then the asynchronous thread brushes the disk , The non unique index will be written to the cache and then flushed .
- Log buffer
- LRU The algorithm switches out the rarely used data , This is the cached hot data policy . The ring buffer has no data movement .
Left most matching principle
For composite indexes , Match from left to right , encounter <>between like Just stop matching .
Overlay index
Data can be found through the secondary index , Instead of using a clustered index . The secondary index data contains less , Therefore, the tree height is generally lower than that of the clustered index , So there will be fewer disks io. Query clustered indexes and auxiliary indexes will not be queried back to the table .
Index failure
- select … where A and B if A and B One of the does not contain an index , The index becomes invalid
- The index field participates in the operation , The index becomes invalid .from_unixtime(idx)=‘2021-04-30’;
- Implicit conversion of index field , The index becomes invalid .‘1’ Implicitly convert to 1;
- LIKE Fuzzy query , wildcard % start , The index becomes invalid .select *from user where name like ‘%ark’;
- Use... On index fields NOT <> != Index failure .id<>0, Then change to idx>0 or idx<0;
- In the composite index , The first column index is not used , The index becomes invalid .
边栏推荐
- 【webrtc】m98 screen和window采集
- [UVM foundation] what is transaction
- Tianqing sends instructions to bypass the secondary verification
- Linux server development, SQL statements, indexes, views, stored procedures, triggers
- 2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
- Leetcode 40: combined sum II
- [UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
- 今日现货白银操作建议
- Qt学习27 应用程序中的主窗口
- vus. Precautions for SSR requesting data in asyndata function
猜你喜欢

Ansible

leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
![[P2P] local packet capturing](/img/4e/e1b60e74bc4c44e453cc832283a1f4.png)
[P2P] local packet capturing

2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct

解决问题:Unable to connect to Redis

Operation suggestions for today's spot Silver

知识点滴 - 关于苹果认证MFI

Why should we understand the trend of spot gold?

2022焊工(初级)判断题及在线模拟考试

2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
随机推荐
[UTCTF2020]file header
[UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
Solve could not find or load the QT platform plugin "xcb" in "
Six methods of flattening arrays with JS
解决:Could NOT find KF5 (missing: CoreAddons DBusAddons DocTools XmlGui)
3D reconstruction - stereo correction
padavan手动安装php
mysql多列索引(组合索引)特点和使用场景
Iterable、Collection、List 的常见方法签名以及含义
Numbers that appear only once
Linux server development, MySQL stored procedures, functions and triggers
[UVM foundation] what is transaction
dash plotly
有 Docker 谁还在自己本地安装 Mysql ?
A bit of knowledge - about Apple Certified MFI
paddlepaddle 29 无模型定义代码下动态修改网络结构(relu变prelu,conv2d变conv3d,2d语义分割模型改为3d语义分割模型)
What are the positions of communication equipment manufacturers?
C语言航班订票系统
The principle and implementation of buffer playback of large video files
Why should we understand the trend of spot gold?