当前位置:网站首页>MySQL indexing and performance optimization
MySQL indexing and performance optimization
2022-06-09 04:34:00 【User 9076598】
Principles of using indexes 1. If there is no uniqueness requirement , You can select a normal index 2. If there is a uniqueness requirement on the column , You can select a unique index 3. If you need fuzzy search , It is recommended to select full-text index 4. If there are multiple conditions to query together , You can choose to combine indexes The following points should be paid attention to when using indexes : 1. Use indexes as needed 2. The larger the cardinality of the column where the index is located, the better , The effect of indexing such fields for men and women is not significant , The base number is very small 3. Pay attention to the leftmost principle in the composite index
We want to know our sql Is the sentence well written , How to judge ? Let's start with sql How statements are executed , for instance select u.name i.expression from user u left join userinfo i on u.id=i.uid where u.id in (1,3,4,55,67,76) order by u.id limit 10; This article sql sentence , Which block will be executed first ? What is the principle of execution ?
select u.name i.expression from user u left join userinfo i on u.id=i.uid where u.id in (1,3,4,55,67,76) order by u.id limit 10; sql The logic of statement execution is as follows First step : take user Table and userinfo surface Do Cartesian product 1.FROM Clause on the left table after it user And right table execution userinfo Line Cartesian product , Generate virtual tables VT1 2.ON Clause pair VT1 The data in is based on ON Conditions for filtration , Generate virtual tables VT2 problem : How to filter ? 3.JOIN Clause Add the data in the unqualified retention table to all VT2 in , formation VT3 4.WHERE Clause Yes VT3 The data in WHERE filter , formation VT4 5.GROUP BY Clause pair VT4 Group the data in , And then form VT5 6.CUBE | ROLLUP Clause to form VT6
7.HAVING Yes VT6 The data in HAVING filter , And then form VT7 8.SELECT from VT7 Select the field to get in the , And then form VT8 9.DISTINCT De duplication data , formation VT9 10.ORDER BY Yes VT9 After sorting the results of , formation VT10 11.LIMIT from VT10 To retrieve the specified data , formation VT11, Return to the user
We want to know our sql Is the sentence well written , How to judge ? Method 1 : Directly in database Up test , Look at the execution time Method 2 : explain select xxxx see
There are several parameters that need attention : type It's worth more than
const: The table has at most one matching row ,const For comparison primary key perhaps unique Indexes . eq_ref: It is used for joining all parts of an index and the index is UNIQUE or PRIMARY KEY".
eq_ref It can be used for = Compare indexed columns . ref For each row combination from the previous table , All rows with matching index values are read from this table . range Search in a given range , Use an index to check the rows . ref Column shows which column or constant to use with key Select rows from the table together . rows Show MYSQL Number of rows to execute the query , Simple and important , The larger the number, the worse , It means that the index is not used well
边栏推荐
- Golang-- concurrent runtime package
- [006] [ESP32开发笔记] 使用Flash下载工具烧录固件步骤
- 查看本机公网IP
- number-precision--使用/实例
- 2022 test question bank and simulation test of special operation certificate for installation, maintenance and demolition at heights
- 如何计算NFT的稀有度?
- MySQL queries which table in the database has the most fields
- Number precision-- use / instance
- Openstack Learning Series 12: installing CEPH and docking openstack
- (8) Style binding
猜你喜欢

golang---并发runtime包

Hengyuan cloud (gpushare)_ Beyond the model of pre training NLP

(7)属性绑定

proteus仿真Arduino

Mysql 查询数据库中哪个表的字段个数最多

openGL_ 01 create window

openGL_ 03 use different VAO and VBO, and different shaders

150 basic acoustic knowledge that acoustic engineers should know (full text)

Golang--- redis operation

OpenInfra基金会发起“定向基金”计划,推行成功开源治理经验
随机推荐
Software testing (II)
keepalived配置虚拟IP
YOLO、COCO和VOC数据集之间格式互换
2022 safety officer-b certificate work certificate title and online simulation examination
(7) Attribute binding
2022安全员-C证考试练习题模拟考试平台操作
如何计算NFT的稀有度?
Test website construction + penetration + audit Part 1 start the website with idea
“迪文杯”湖南文理学院电子设计大赛圆满结束
lua 运算符
2022 test question bank and simulation test of special operation certificate for installation, maintenance and demolition at heights
2022年R2移动式压力容器充装考试模拟100题及模拟考试
Harbor container installation and related feature deployment and use (SSL certificate +ad domain)
Format interchange among Yolo, coco and VOC datasets
微信小程序:(异常)Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ 解决方案和分析流程(这里一定有你要的答案)
VS Code `launch. Json` and `task Predefined variables available in json`
openGL_ 02 point line surface triangle
Golang --- comparison operation of various types of variables
number-precision--使用/实例
(5) Bidirectional data binding