当前位置:网站首页>SQL common optimization
SQL common optimization
2022-07-07 20:00:00 【Whiteye too white】
sql Optimize
1. Small tables drive large tables
First, query the table with less data , Then execute the query of the table with more data .
2. Index building , A table does not exceed 5 An index
Avoid large memory consumption .
3. Go to the index , Try to meet the leftmost match , Avoid index invalidation
Index failure :
(1)select *
(2)>、<、!=、between
(3) In front of % Of like Inquire about .
(4)where The field value type is inconsistent with the database , There is an automatic conversion .
(5)or Connect different fields .
(6)or Connect the same field , But there is >、<、!= Non indexed query .( Only when both left and right queries are indexes .)
(7) Function or operation causes index invalidation .
(8)IS NULL Don't walk index ,IS NOT NULL Go to the index ( Table design : When not necessary , The field should not be NULL, Set the default empty string or 0)
(9) When querying the range of composite cables , The following index is invalid .
(10)IN Can walk the index , But when IN When the value range of is large, the index will be invalid .
- ep_range_index_dive_limit This parameter affects in Use index or not ,MySQL 5.6 Default 10, MySQL.5.7 Default 200. But our code tends to be controlled in 50 Inside . A Table data is greater than B Table data , choice in Than exists High execution efficiency . contrary ,A Table data is less than B Table data , choice exists More efficient . in Execute subquery first ,exists First perform the appearance .
(11)not in Will invalidate the index , In either case not exists All ratio not in Efficient .
- Use left join or not exists To optimize not in operation .
4. Try to separate hot and cold data
Reduce the number of query table columns , Avoid cold data filtering .
5. Adjust the order of index columns
The uniqueness is better 、 Field is short 、 The frequently used column is placed on the far left of the union index
6. Override indexes are a priority for frequent queries
Query the data together when searching .
7. Avoid implicit conversions of data types
Avoid index invalidation .
8. No use SELECT * You have to use SELECT < Field list > Inquire about
There will be redundant fields , Consume more CPU And network bandwidth Will not be able to use overlay index .
9. Avoid subqueries , The subquery can be optimized to join operation
Subqueries will generate a large number of temporary tables without indexes .
10. Avoid using JOIN Too many tables associated
The more associated tables, the larger the associated cache .
11. Used when there is obviously no duplicate value UNION ALL instead of UNION
UNION ALL No de duplication operation , Speed up query .
12. Big SQL Split , More than one species SQL Batch processing
One SQL You can only use one cpu Calculate , After splitting, multiple cpu Parallel computing .
13. WHERE Functional transformations and calculations for columns are forbidden in clauses
Avoid index invalidation .
14. Use count(*) instead of count( Name )?
Comprehensive performance :count( Non primary key columns ) < count( Primary key ) < count(1) ≈ count()
count() yes SQL92 The syntax for defining the number of standard statistics lines , It's not about the database ,count(*) The statistical value is NULL The line of , and
count( Name ) This column is not counted NULL Row of values .
边栏推荐
- UCloud是基础云计算服务提供商
- Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
- mock.js从对象数组中任选数据返回一个数组
- R language ggplot2 visualization: use the ggecdf function of ggpubr package to visualize the grouping experience cumulative density distribution function curve, and the linetype parameter to specify t
- Ucloud is a basic cloud computing service provider
- Browse the purpose of point setting
- The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list
- Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry
- 【STL】vector
- ASP.NET幼儿园连锁管理系统源码
猜你喜欢
vulnhub之school 1
Compiler optimization (4): inductive variables
剑指 Offer II 013. 二维子矩阵的和
【STL】vector
Detailed explanation of Flink parallelism and slot
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
模拟实现string类
爬虫实战(七):爬王者英雄图片
项目经理『面试八问』,看了等于会了
随机推荐
How to buy bank financial products? Do you need a bank card?
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
【STL】vector
Kirin Xin'an cloud platform is newly upgraded!
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip plot, set the position parameter, and configure the separation degree of different grouped
【RT-Thread env 工具安装】
使用高斯Redis实现二级索引
The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
LeetCode_7_5
UCloud是基础云计算服务提供商
The DBSCAN function of FPC package of R language performs density clustering analysis on data, checks the clustering labels of all samples, and the table function calculates the two-dimensional contin
Time tools
R语言dplyr包mutate_at函数和min_rank函数计算dataframe中指定数据列的排序序号值、名次值、将最大值的rank值赋值为1
ASP. Net kindergarten chain management system source code
开源重器!九章云极DataCanvas公司YLearn因果学习开源项目即将发布!
力扣 643. 子数组最大平均数 I
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
R language ggplot2 visualization: use the ggdensity function of ggpubr package to visualize the packet density graph, and use stat_ overlay_ normal_ The density function superimposes the positive dist
Simulate the implementation of string class