当前位置:网站首页>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 .
边栏推荐
- Global and Chinese market for change and configuration management software 2022-2028: Research Report on technology, participants, trends, market size and share
- Searchview click failure
- 工作汇报(2)
- SwiftUI 开发经验之为离线优先的应用程序设计数据层
- SSH, SCP command appears permission denied, please try again solution
- Query online users and forced withdrawal users based on oauth2
- Yarn package management tool
- Blog article index Summary - wechat games
- Opencv image processing - grayscale processing
- [echart] i. how to learn echart and its characteristic document reading notes
猜你喜欢

Concise course of probability theory and statistics in engineering mathematics second edition review outline

About multi table query of MySQL

Flutter and native communication (Part 1)

MySQL第七次作业-更新数据

Basic MySQL

量化投资学习——经典书籍介绍

Query online users and forced withdrawal users based on oauth2

JS take the date of the previous month 【 pit filling 】
![[echart] II. User manual and configuration item reading notes](/img/03/fa87e5b8f8d23381ea6923d507f250.jpg)
[echart] II. User manual and configuration item reading notes

栖霞市住建局和消防救援大队开展消防安全培训
随机推荐
MySQL第四章总结
SQL Server foundation introduction collation
Search engine advanced search method records
Bit operation n & (n-1), leetcode231, interview question 05.06
How QT uses quazip to compress and decompress files
【在线仿真】Arduino UNO PWM 控制直流电机转速
MySQL 11th job - view application
Fabric.js 上划线、中划线(删除线)、下划线
OpenCV图像处理-灰度处理
看我在Map<String, String>集合中,存入Integer类型数据
MySQL 12th job - Application of stored procedure
Query online users and forced withdrawal users based on oauth2
AIX基本操作记录
Execute Lua script in redis
ceph运维常用指令
Renesas electronics launched a complete intelligent sensor solution for Internet of things applications
Global and Chinese market for change and configuration management software 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL第十四次作业--电子商城项目
MySQL第十二次作业-存储过程的应用
appliedzkp zkevm(8)中的Plookup Table