当前位置:网站首页>On database optimization (taking MySQL as an example)
On database optimization (taking MySQL as an example)
2022-06-09 07:17:00 【The first person in the examination】
Database optimization follows a funnel rule , Here's the picture :

The funnel rule of database optimization can be basically divided into 5 A hierarchical :
- Reduce data access ( Reduce disk access )
- Indexes , Reduce full table scanning
- Return less data ( Reduce network transfers or disk access )
- Return the required data according to the actual business requirements
- Reduce the number of interactions ( Reduce network transmission )
- cache
- stored procedure
- Batch query
- Reduce servers CPU expenses ( Reduce CPU Several memory overhead )
- Batch processing
- Handle a large number of operations on the client side
- Use more resources ( Increase resources )
Hardware resources
For the above figure, we have studied an optimization direction :

PS: Let's talk about the actual development , Basically is sql Optimize , At most, it is database table structure optimization ( Sub database and sub table )
Talk about sql The idea of optimization :
First of all, when we sql The statement execution time has reached 3s When above , It's unacceptable , It is usually a millisecond response , We need to turn on mysql Slow query log of database ( Need to be in mysql Configuration in the configuration file ), Locate the slow execution sql After the statement , We use... For this statement explain Keyword to view its execution plan , Analyze whether the index failure caused the full scan .
Here are some common cases of index failure :

Let's talk about the optimization of database table structure ( That is, sub database and sub table ):
Common splits include horizontal split and vertical split , However, horizontal splitting is used at most , I have not been exposed to vertical splitting at present , Let's talk about horizontal splitting , Like an order form , A lot of data is inserted every day , Suppose that the data in a table has reached 1000 ten thousand ( Theoretically mysql Single table greater than 500 Ten thousand data , We need to consider the horizontal sub table , Because the larger the amount of data in a single table, the slower the query , The query efficiency drops exponentially ), Let's split this table horizontally , Then there will be a problem that is how to know which database you want to check data in .
We use hash The idea of dividing tables ( The precondition is to ensure that the primary key is a number ), Suppose the two tables are divided into 100 individual hash Slot , The table above shows 0~49, The table below for 50~99, Suppose the incoming id by 50 when , use 50/100 Take the remainder as 50, Then look it up in the table below .
We can also use third-party plug-ins , such as mycat, It just helps us integrate hash The idea of dividing tables .
边栏推荐
- 生产者消费者问题
- UML series articles (21) high level behavior - events and signals
- Web performance testing strategy
- 纯英式 VoxEdit 大赛来啦
- UML series article (22) advanced behavior -- state machine
- 性能测试流程,指标,实现方法以及总结
- 257. all paths of binary tree
- LVS+keepalived高可用
- C language file -- read and write by string
- Boot Black apple with OpenCORE
猜你喜欢

纯英式 VoxEdit 大赛来啦

2022年全國最新消防設施操作員(中級消防設施操作員)考試模擬題庫及答案

Common classes - overview of string classes

Pycharm and MySQL as a student information management system

Naive Bayes classifier

Flutter learning Hello World

Don't waste your spare time. Playing with mobile phones can start "sideline life"

Error (119013): Current license file does not support the EP4CE10F17C8 device解决方法

UML series (24) advanced behavior - time and space

WPF data binding (II)
随机推荐
Introduction to mongodb framework zero Foundation (unfinished)
新职业:数字化管理师太抢手,只要来面试,企业就会发offer
pycharm 和mysql做学生信息管理系统问题求解
High precision personnel positioning system, power plant indoor positioning application solution
C语言fopen函数的编程实现(可直接粘贴走验证)
2022年7月2日下午,济南IT技术聚会,感兴趣的朋友扫码报名并入群交流
Use postman to simulate a request to carry a token
性能测试流程,指标,实现方法以及总结
[quick record for CV] teachyourselfsql_ MySQL
【工作向】conda常用命令汇总
Flutter学习之Hello World
分布式消息中间件--消息队列介绍
Read dates in various formats from excel and convert them to target formats
QT console project display label small window
Producer consumer issues
C语言文件——字符读出与写入
Basic knowledge summary of database
How idea views the path to save code
The sandbox and ikonia have reached a cooperation to restore the murals of the football legend Pirlo in the metauniverse
多线程-程序进程线程的概念