当前位置:网站首页>A case of MySQL implicit conversion
A case of MySQL implicit conversion
2022-04-22 10:13:00 【bisal(Chen Liu)】
Implicit conversion , It can be said to be a relational database SQL A very hidden problem in optimization , I have encountered many cases related to him before ,
《 Alternatives to implicit conversion are not omnipotent 》
《Oracle、SQL Server and MySQL Similarities and differences of implicit transformation of 》
《 Let's see SQL Server Different implicit conversion processing 》
《 How to find the of implicit conversion SQL?》
《 Convert cases implicitly , To tap the skills of developers 》
《 On explicit conversion and implicit conversion 》
《 Implicitly converted case scenarios 》
《 An interesting misselection of execution plan problem location 》
This article on data and cloud 《SQL Optimize —— Implicit character encoding conversion 》 It introduces MySQL The problem of implicit conversion caused by different character sets in .
MySQL We know that ,
If you do a function operation on the index field , May break the order of index values , So the optimizer decided to give up the tree search function .
Implicit type conversion can also lead to abandoning tree search .
Because type conversion is equivalent to using a function on a condition field , for example ,
hypothesis tradeid The field has an index , And for varchar type ,
mysql> select * from tradelog where tradeid=110717;
Equivalent to ,
mysql> select * from tradelog where CAST(tradid AS signed int) = 110717;
Let's take a look at a slow problem caused by implicit character encoding conversion SQL, There is a business SQL Execution requires 1.31 second ,

Look at the execution plan ,

From the analysis of the implementation plan, we can see that the problem lies in r Watch is h_merge_result_new_indicator Table full table scan , Check that the table of this table has a joint index . However, the union index range will be invalid , So I plan to create a new joint index ,

View the fields of the pre created union index ,

Combined with selectivity ,
create index idx_hmrni on h_merge_result_new_indicator(keyName,module,BATCH_NO);
After creation , Again, the implementation plan is still invalid ,

View table structure ,

in addition 3 A table structure with 2 individual utf8mb4,1 individual utf8,



Character set utf8mb4 yes utf8 Superset , So when these two types of strings are compared ,MySQL The internal operation is , First the utf8 String to utf8mb4 Character set , To compare . therefore ,

This part will be converted and then connected with h_merge_result_new_indicator relation . Optimization only needs to convert the character set encoding to utf8 And again h_merge_result_new_indicator The association can use the index ,

If you look at the query again, you only need 0.02 The second ,

But there's a problem , The above implementation plan key_len yes 606=(100*3+3)+(100*3+3). That is to say , It doesn't work BATCH_NO Index on field , We know that the index is missing one field , Occupancy will be reduced , Not too bloated . therefore , The federated index only needs to contain (keyName,module),
drop index idx_hmrni on h_merge_result_new_indicator;
create index idx_hmrni on h_merge_result_new_indicator(keyName,module);
Function operation on index field , Whether it's explicit , Or implicit , Will destroy the order of index values , And then affect the judgment of the optimizer , This is right Oracle and MySQL It's all interlinked .
therefore , In the development stage , And the audit stage , Avoiding and excavating these problems , It's worth noticing , Input output ratio , Still considerable .
Recently updated articles :
《Linux Comparison of several data transmission tools 》
《 Xiaobai studies MySQL - There are some differences between users created by different versions 》
《 Recent problems 》
《Linux Retrieval of process information 》
《OCR Analyze the picture of health treasure 》
Article classification and indexing :
版权声明
本文为[bisal(Chen Liu)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221012235460.html
边栏推荐
- Challenges of enterprise web development
- SWOOLE高性能内存数据库的使用和配置教程
- 三极管、场效应管和MOS管三者的工作原理
- Tensorflow Experiment 4 -- Boston house price forecast
- Google Earth Engine(GEE)——聚合网格化人口数据
- 柯里化的两种写法(弄懂`fn.length`与`fn.toString()`)
- Cross platform compilation
- The debug breakpoint of idea thread pool cannot jump in
- 基于SSM的电影在线购票系统
- source_ Insight is a method to create a new project and search for a variable or function in the whole document
猜你喜欢

Deep learning remote sensing scene classification data set sorting

Qtabelwidget instance

【QT小记】使用QPainter绘制各种基本图形

5.嵌入式控制器(Embedded Controller,EC)学习 PS/2协议

Interpretation of openeuler kernel technology | introduction to kernel interrupt subsystem

三极管、场效应管和MOS管三者的工作原理

頭條面試居然跟我扯了半小時的Semaphore

关于tpshop开源商城6.0版本图片库不显示图片问题

Multi target tracking extended Kalman filter (EKF)

通过LayerDrawable实现进度条的功能
随机推荐
SQL 关系型数据库管理系统
2022-04-21 MySQL InnoDB storage engine core processing
Cloud native enthusiast weekly: looking for open source alternatives to netlify
5. Embedded controller (EC) learns PS / 2 protocol
Deep learning remote sensing scene classification data set sorting
Secondary encapsulation of requests for uni app projects
TextView设置指定字符显示颜色
Drop down refresh and pull-up load of product list of uni app project
Zhezheng nail scanning code login
Depth first search (I): middle order traversal of binary tree (force buckle)
linux安装oracle19c完整版(图形+静默安装)
Cobbler cobbler cobbler
基于SSM的电影在线购票系统
The working principle of triode, FET and MOS transistor
DA14580BLE点亮LED
SQL operator
dataguard (ADG)备库移动(迁移)数据文件
01背包问题——以及变形问题
多目标追踪——拓展卡尔曼滤波(EKF)
matplotlib教程04---绘制常用的图形