当前位置:网站首页>MySQL composite index with or without ID
MySQL composite index with or without ID
2022-07-02 07:17:00 【Software development heart】
One 、 Preface
A few days ago, there was a slow sql problem , The scene is import and Export ,, This watch has about 2 More than 100 million data , Need to add index optimization , Tables and fields are desensitized ., primary sql Something like that :
select * from object_range force index(idx_obj_no_id) where type = 1 and biz_type = 1 and obj_no = 123 order by id limit 1000,500
You can see that there are three query fields type,biz_typ,objec_no, The original query force index go obj_no and id Joint index of , But because of a single object_no The number of lines will still go to hundreds of thousands , So it's still slow to query .
Two 、 First processing .
According to my previous understanding , The composite index is automatically added id Of , Therefore, changes were made directly in production, and these three query fields were linked together to build a joint index idx_type_biz_type_obj_no. And then modify sql Removed force_index I went for a run explain
-- The modified sql no need force_index Time 0.015s
select * from object_range where type = 1 and biz_type = 1 and obj_no = 123 order by id limit 1000,500
-- Go to the new index idx_type_biz_type_obj_no
explain select * from object_range where type = 1 and biz_type = 1 and obj_no = 123 order by id limit 1000,500
Very satisfied with , Then publish directly .
Unfortunately, production is still the same slow sql, hold sql Pull it down and find it under specific parameters explain, This article sql Can go to the primary key index , Why did you leave primary Index? .
3、 ... and 、 solve
First , One sql stay mysql After the analyzer , Optimizer , actuator , Goodbye to the storage engine etc.
After consulting colleagues, I found , Composite indexes do add id, I really remember this correctly , But it turns out that this is in the storage layer . about mysql The optimizer does not know that this index is added id.
So in the sql When analyzing and optimizing , Especially when it comes to sorting , Probably mysql The optimizer thinks there will be filesort So use the primary key id The index will be better , Because the optimizer does not know that there is id, Therefore, the analysis will not consider ...
Then on sql Once again, the forced index publishing , slow sql period .
explain select * from object_range index(idx_type_biz_type_obj_no) where type = 1 and biz_type = 1 and obj_no = 123 order by id limit 1000,500
Back to the beginning , I understand why I started this sql To add idx_obj_no_id Indexes . So the next time you add a joint index, you'd better be honest and finally id add , There is no loss , There will be unexpected gains .
边栏推荐
- Oracle EBS database monitoring -zabbix+zabbix-agent2+orabbix
- Pyspark build temporary report error
- Three principles of architecture design
- php中计算两个日期之前相差多少天、月、年
- Oracle general ledger balance table GL for foreign currency bookkeeping_ Balance change (Part 1)
- 2021-07-17C#/CAD二次开发创建圆(5)
- Sqli-labs customs clearance (less2-less5)
- Module not found: Error: Can't resolve './$$_ gendir/app/app. module. ngfactory'
- Oracle rman自动恢复脚本(生产数据向测试迁移)
- php中的二维数组去重
猜你喜欢

UEditor . Net version arbitrary file upload vulnerability recurrence

Oracle EBS ADI development steps

CSRF攻击

如何高效开发一款微信小程序

Sqli labs customs clearance summary-page2

@Transational踩坑

架构设计三原则

MapReduce concepts and cases (Shang Silicon Valley Learning Notes)

Error in running test pyspark in idea2020

Explain in detail the process of realizing Chinese text classification by CNN
随机推荐
Oracle apex Ajax process + dy verification
【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding
Sqli Labs clearance summary - page 2
ERNIE1.0 与 ERNIE2.0 论文解读
Ingress Controller 0.47.0的Yaml文件
Oracle EBs and apex integrated login and principle analysis
使用Matlab实现:Jacobi、Gauss-Seidel迭代
Spark的原理解析
Oracle 11g uses ords+pljson to implement JSON_ Table effect
Illustration of etcd access in kubernetes
Message queue fnd in Oracle EBS_ msg_ pub、fnd_ Application of message in pl/sql
Oracle EBS DataGuard setup
Only the background of famous universities and factories can programmers have a way out? Netizen: two, big factory background is OK
Oracle apex 21.2 installation and one click deployment
Sqli-labs customs clearance (less15-less17)
2021-07-05C#/CAD二次开发创建圆弧(4)
DNS攻击详解
RMAN incremental recovery example (1) - without unbacked archive logs
Pyspark build temporary report error
The boss said: whoever wants to use double to define the amount of goods, just pack up and go