当前位置:网站首页>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 .
边栏推荐
- Problem solving: unable to connect to redis
- 今日现货白银操作建议
- Cnopendata geographical distribution data of religious places in China
- 微信小程序中使用wx.showToast()进行界面交互
- leanote私有云笔记搭建
- buuctf misc USB
- dash plotly
- 2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
- Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
- [Stanford Jiwang cs144 project] lab3: tcpsender
猜你喜欢

You Li takes you to talk about C language 6 (common keywords)

padavan手动安装php

2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
![[experience sharing] how to expand the cloud service icon for Visio](/img/42/dba9f78f3fb2049dad8b343b0b36e5.png)
[experience sharing] how to expand the cloud service icon for Visio

MySQL multi column index (composite index) features and usage scenarios

The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)

Visualization Document Feb 12 16:42

2022年茶艺师(中级)考试试题及模拟考试

misc ez_ usb

Use and analysis of dot function in numpy
随机推荐
Qt学习28 主窗口中的工具栏
【webrtc】m98 screen和window采集
Route jump in wechat applet
【数学笔记】弧度
解决:Could NOT find KF5 (missing: CoreAddons DBusAddons DocTools XmlGui)
【p2p】本地抓包
Redis technology leak detection and filling (II) - expired deletion strategy
Linux server development, MySQL process control statement
Is the test cycle compressed? Teach you 9 ways to deal with it
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
开源生态|打造活力开源社区,共建开源新生态!
[VHDL parallel statement execution]
pytest+allure+jenkins環境--填坑完畢
pytest+allure+jenkins环境--填坑完毕
C语言通信行程卡后台系统
numpy中dot函数使用与解析
Visualization Document Feb 12 16:42
buuctf misc USB
2022 welder (elementary) judgment questions and online simulation examination