当前位置:网站首页>MySQL development specification

MySQL development specification

2022-06-24 15:41:00 Xianling Pavilion

All database object names must be lowercase and separated by underscores (MySQL Case sensitive , The name should see the meaning of the name , Better not exceed 32 character )
It is forbidden to store pictures in data , File binary data ( Use a file server )

Do not do database stress tests online

Forbidden from development environment , The test environment is directly connected to the production environment database

Limit the number of indexes on each table , It is recommended that the index of a single table should not exceed 5 individual ( Indexing increases query efficiency , But it will reduce the speed of insertion and update )
Avoid using ENUM data type ( modify ENUM Values need to be used ALTER sentence ,ENUM Type of ORDER BY Low operating efficiency , Require additional operations , It is forbidden to use book value as ENUM The enumerated values

Try to define all fields as NOT NULL( Indexes NULL Need extra space to save , So you need to use more memory temporarily , The comparison and calculation should be correct NULL It's worth special treatment )

Use timestamp or datetime Type to store time

Financial related amount data , use decimal type ( No loss of accuracy , No use float and double)
All database object names are prohibited MySQL Reserved keyword

The temporary library table must be in the form of tmp Is prefixed and suffixed with a date (tmp_)

Backup libraries and libraries must be bak Is prefixed and suffixed with a date (bak_)

All column names and column types that store the same data must be consistent .

The character set of database and table should be used uniformly as much as possible utf8( The character set must be uniform , Avoid garbled code caused by character set conversion , Chinese characters utf8 Take up 3 Bytes )

All tables and fields should be annotated COMMENT, Maintain the data dictionary from the beginning

It is recommended to manage big data by physical tables

Try to separate hot and cold data , Reduce the width of the table (mysql Limit maximum storage 4096 Column , There is no limit to the number of lines , However, the total number of bytes per line cannot exceed 65535. Column restriction benefits : Reduce disk io, Ensures a memory cache hit ratio for hot data , Avoid reading useless cold data )

It is forbidden to create a reserved field in a table ( Unable to confirm stored data type , Modify the reserved field type , Will lock the table )
Avoid using double % Number and like, It is strictly forbidden to search for left blur or full blur ( If necessary, please use search engine to solve . Index file has B-Tree The leftmost prefix matching property of , If the value on the left is not determined , Then this cable cannot be used )

Precompiled statements are recommended for database operations

Cross database query is prohibited ( Leave room for data migration and database and table segmentation , Reduce coupling , Reduce risk )

prohibit select * Inquire about ( Consume more cpu and io And network bandwidth resources , Cannot use overlay index )

in Avoid if operation can be avoided , If it can't be avoided , Need to be evaluated carefully in Number of set elements behind , Control in 1000 Within

No use order by rand() Sort at random

Avoid creating redundant and duplicate indexes ( redundancy :index(a,b,c) index(a,b) index(a))

It is forbidden to create a separate index for each column in a table

The most distinguished column is placed on the leftmost side of the union index

Try to put columns with small field lengths on the far left of the union index

Try to avoid using foreign keys ( Prohibit the use of physical foreign keys , Logical foreign keys are recommended )

Use as much as possible union all Instead of union

Split complex large SQL For the multiple small SQL( MySQL One SQL You can only use one CPU Calculate )

For the program to connect to the database account , Follow the principle of minimum authority

More than three tables prohibited join.( need join Field of , Data types must be absolutely consistent ; When multi table associated query , Ensure that the associated field needs to have an index . Even if the double meter join Also pay attention to table indexes 、SQL performance .)

stay varchar When indexing on a field , Index length must be specified , There's no need to index all fields , Determine the index length according to the actual text differentiation .

SQL Objectives of performance optimization : At the very least range Level , The requirement is ref Level , If it could be consts best

Use ISNULL() To determine whether it is NULL value .

Try not to use physical deletion ( Delete directly , If you want to delete it, make a backup in advance ), It's using logical deletion , Use fields delete_flag Do logical deletion , The type is tinyint,0 Indicates not deleted ,1 Indicates that

If there is order by Scene , Note the use of index order .order by The last field is the combination , Part of index , And put it at the end of the index combination order , Avoid file_sort The situation of , Affect query performance .

The source code attachment has been packaged and uploaded to Baidu cloud , You can download it yourself ~

link : https://pan.baidu.com/s/14G-bpVthImHD4eosZUNSFA?pwd=yu27
Extraction code : yu27
Baidu cloud link is unstable , It may fail at any time , Let's keep it tight .

If Baidu cloud link fails , Please leave me a message , When I see it, I will update it in time ~

Open source address

Code cloud address :
http://github.crmeb.net/u/defu

Github Address :
http://github.crmeb.net/u/defu

https://z.itpub.net/article/detail/6D5CA2E8905731A1A784F87B4F4FEA32

原网站

版权声明
本文为[Xianling Pavilion]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241319024278.html