当前位置:网站首页>MySQL 30 military regulations
MySQL 30 military regulations
2022-06-26 10:48:00 【BOGO】
One 、 The specification (1) You have to use InnoDB Storage engine
Reading : Support transactions 、 Row-level locks 、 Better concurrency 、CPU And memory cache page optimization for higher resource utilization .
(2) You have to use UTF8 Character set
Reading : unicode , Without transcoding , No risk of garbled code , Save a space .
(3) Data sheet 、 Data fields must be annotated in Chinese
Reading :N Who will be in the future tm Know this r1,r2,r3 What are the fields for .
(4) Stored procedures are not allowed 、 View 、 trigger 、Event
Reading : High concurrency big data Internet business , The architectural design idea is “ Free database CPU, Move the computation to the service layer ”, High concurrency , These features are likely to kill the database , Business logic is more extensible in the services layer , Can be easily implemented “ Add performance to the machine ”. Databases are good at storing and indexing ,CPU Let's move it up .
(5) Do not store large files or photos
Reading : Why let a database do something it's not good at ? Large files and photos are stored in the file system , Database storage URI How good .
Two 、 Naming specification
(6) Only Intranet domain names are allowed , instead of ip Connect to database
(7) The online environment 、 development environment 、 Test environment database Intranet domain names follow naming conventions
Business name :xxx
The online environment :dj.xxx.db
development environment :dj.xxx.rdb
Test environment :dj.xxx.tdb
The slave library is added after the name -s identification , Backup libraries are appended to the name -ss identification
Online from the library :dj.xxx-s.db
Online storage :dj.xxx-sss.db
(8) Library name 、 Table name 、 Field name : A lowercase letter , Underline style , No more than 32 Characters , You must know what you mean , Pinyin is not allowed to be used in English .
(9) Table name t_xxx, Non-unique index name idx_xxx, Unique index name uniq_xxx
3、 ... and 、 Table design specification
(10) The number of singleton tables must be smaller 500
(11) The number of single table columns must be less than 30
(12) The table must have a primary key , For example, self-augment primary keys
Reading :
a) Increasing the primary key , Row writing can improve insert performance , You can avoid page split , Reduce table fragmentation and memory usage
b) The primary key selects a shorter data type , Innodb The engine's normal index stores the value of the primary key , Shorter data types can effectively reduce index disk space , Improve index caching efficiency
c) Table deletion without primary key , stay row The master-slave architecture of the pattern , Will lead to storage ramming
(13) Foreign keys are not allowed , If there is a foreign key integrity constraint , Application control is required
Reading : Foreign keys cause coupling between tables ,update And delete All operations involve the associated tables , Very affected sql Performance of , It can even cause a deadlock . High concurrency can easily lead to database performance , The big data high concurrency business scenario database is used to prioritize performance .
Four 、 Field design specification
(14) The field must be defined as NOT NULL And provide default values
Reading :
a)null The column of / The index statistics / Value comparisons are more complex , Yes MySQL Harder to optimize .
b)null This type of MySQL Special handling is required internally , Increases the complexity of database processing records ; Under the same conditions , When there are more empty fields in the table , The processing performance of the database can be significantly reduced .
c)null Values require more storage space , Either in the table or in each row of the index null Each of the following columns requires additional space for identification .
d) Yes null Processing time , Only use is null or is not null, Can't use =、in、<、<>、!=、not in These operation symbols . Such as :where name!=’shenjian’, If there is name by null The record of value , The query result is not included name by null The record of value .
(15) No use TEXT、BLOB type
Reading : It wastes more disk and memory space , A large number of large field queries that are not necessary eliminate hot data , This results in a dramatically reduced memory hit ratio , Impact on database performance .
(16) Do not use decimals to store currency
Reading : Let's use integers , Decimals can easily lead to misalignment of money .
(17) You have to use varchar(20) Store phone number
Reading :
a) Refers to the area code or country code , May appear +-()
b) Can phone Numbers do math ?
c)varchar Fuzzy queries can be supported , for example :like“138%”
(18) No use ENUM, You can use TINYINT Instead of
Reading :
a) Add new ENUM Value to do DDL operation
b)ENUM The actual internal storage of , You think you're defining a string ?
5、 ... and 、 Index design specification
(19) Single table index is recommended to be controlled in 5 Within a
(20) The number of single index fields is not allowed to exceed 5 individual
Reading : The field more than 5 Time , Effectively filtering data is no longer possible .
(21) The ban on updates is very frequent 、 Index poorly differentiated attributes
Reading :
a) Updates change B+ Trees , Indexing frequently updated fields can significantly reduce database performance .
b)“ Gender ” It's a very indistinguishable property , What's the point of indexing , Unable to filter data effectively , The performance is similar to that of a full table scan .
(22) Set up composite index , The highly differentiated fields must be placed first
Reading : To filter data more efficiently .
6、 ... and 、SQL Use standard
(23) No use SELECT *, Get only the necessary fields , The description column properties need to be displayed
Reading :
a) Additional columns are read that are not needed CPU、IO、NET Consume .
b) Coverage indexes cannot be effectively utilized .
c) Use SELECT * Easy to appear after adding or deleting fields BUG.
(24) No use INSERT INTO t_xxx VALUES(xxx), The column properties specified for insertion must be displayed
Reading : Easy to appear after adding or deleting fields BUG.
(25) Property implicit conversion is not allowed
Reading :SELECT uid FROM t_user WHERE phone=13812345678 Causes a full table scan , And not hit phone Indexes , Guess why ?( This online problem has come up more than once ).
(26) Do not use WHERE A function or expression is used on a property of a condition
Reading :SELECT uid FROM t_user WHERE from_unixtime(day)>='2017-02-15' Causes a full table scan .
The correct way to write it is :SELECT uid FROM t_user WHERE day>= unix_timestamp('2017-02-15 00:00:00').
(27) Negative queries are not allowed , as well as % The fuzzy query at the beginning
Reading :
a) Negative query condition :NOT、!=、<>、!<、!>、NOT IN、NOT LIKE etc. , Causes a full table scan .
b)% The fuzzy query at the beginning , Causes a full table scan .
(28) Do not use large tables JOIN Inquire about , Large tables are not allowed to use subqueries
Reading : Temporary tables are generated , More memory is consumed CPU, Significantly affects database performance .
(29) No use OR Conditions , Must be changed to IN Inquire about
Reading : The old version Mysql Of OR The query cannot hit the index , Even if it hits the index , Why make the database more expensive CPU Help with query optimization ?
(30) The application must capture SQL abnormal , And have corresponding processing .
边栏推荐
- MySQL第七次作业-更新数据
- 互联网对抗神器之漏洞扫描与反渗透
- Global and Chinese markets in hair conditioner 2022-2028: Research Report on technology, participants, trends, market size and share
- The fourteenth MySQL operation - e-mall project
- The difference between NPM and yarn
- MySQL第十三次作业-事务管理
- 磁带库简单记录1
- Pytest configuration file
- MySQL第八次作业
- Alibaba cloud OSS - object storage service (tool)
猜你喜欢

Alibaba cloud OSS - object storage service (tool)

Redis knowledge mind map

Hcia-dhcp experiment

Linux下安裝Mysql【詳細】

Flutter与原生通信(上)

MySQL 9th job - connection Query & sub query

Quantitative investment learning - Introduction to classic books

Based on Zeng Shen's explanation, the line segment tree is studied again one

Write data to local file

ISO 26262之——2功能安全概念
随机推荐
Redis中执行Lua脚本
Is it safe to open an account in the school of Finance and business?
MySQL Chapter 5 Summary
目前为止最全的Kubernetes最新版核心命令
Global and Chinese market of aluminum sunshade systems 2022-2028: Research Report on technology, participants, trends, market size and share
近期工作汇报
Easyexcel - Excel read / write tool
[echart] II. User manual and configuration item reading notes
Quantitative investment learning - Introduction to classic books
用同花顺手机炒股是安全的吗?如何用同花顺炒股
MySQL project 8 summary
工程数学概率论统计简明教程第二版复习大纲
Idea remote debugger
Nuxt. JS - learning notes
CentOS安装Redis多主多从集群
Searchview click failure
【在线仿真】Arduino UNO PWM 控制直流电机转速
Concise course of probability theory and statistics in engineering mathematics second edition review outline
Tape library simple record 1
Notes - simple but adequate series_ KVM quick start