当前位置:网站首页>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 .
边栏推荐
- 浏览积分设置的目的
- 一锅乱炖,npm、yarn cnpm常用命令合集
- Compiler optimization (4): inductive variables
- Kirin Xin'an cloud platform is newly upgraded!
- R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
- 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
- LC:字符串转换整数 (atoi) + 外观数列 + 最长公共前缀
- Introduction to bit operation
- Semantic SLAM源码解析
- Make this crmeb single merchant wechat mall system popular, so easy to use!
猜你喜欢
Ways to improve the utilization of openeuler resources 01: Introduction
Leetcode force buckle (Sword finger offer 36-39) 36 Binary search tree and bidirectional linked list 37 Serialize binary tree 38 Arrangement of strings 39 Numbers that appear more than half of the tim
J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
编译器优化那些事儿(4):归纳变量
【STL】vector
转置卷积理论解释(输入输出大小分析)
Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
# 欢迎使用Markdown编辑器
Simulate the implementation of string class
Welcome to the markdown editor
随机推荐
Version selection of boot and cloud
【RT-Thread env 工具安装】
Kubernetes——kubectl命令行工具用法详解
剑指 Offer II 013. 二维子矩阵的和
IP 工具类
Compiler optimization (4): inductive variables
Browse the purpose of point setting
R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry
What does "true" mean
华南X99平台打鸡血教程
mysql 的一些重要知识
银行理财产品怎么买?需要办银行卡吗?
ant desgin 多选
位运算介绍
Jürgen Schmidhuber回顾LSTM论文等发表25周年:Long Short-Term Memory. All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversarial RL. Soccer learn
R language dplyr package mutate_ At function and min_ The rank function calculates the sorting sequence number value and ranking value of the specified data column in the dataframe, and assigns the ra
R language uses ggplot2 function to visualize the histogram distribution of counting target variables that need to build Poisson regression model, and analyzes the feasibility of building Poisson regr
vulnhub之school 1
关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】