当前位置:网站首页>MySQL development specification pdf
MySQL development specification pdf
2022-06-29 15:26:00 【Code farmer Programming Advanced notes】
Prohibited items :
1、 No use select * Etc
When querying all fields (select *) Can cause the following problems 1. Increase network bandwidth consumption 2. Select * It will inevitably lead to back table query / Return the data , Invalidate the overlay index
3. If the table structure is modified, such as adding multiple columns , It is dangerous to return redundant data
2、 Database name is prohibited 、 Table name 、 The field name uses MySQL Reserved words
When the name of the library 、 Table name 、 When properties such as field name contain reserved words ,SQL Statement must refer to the property name with backquotes , This will make SQL Statement writing 、SHELL Escape of variables in scripts 、 It becomes very complicated to modify the table structure online .
3、 The use of partitioned tables is prohibited Mysql Partition table technology is still not very mature , And there are strict requirements for partitioning keys , After the partition table becomes larger, it is very difficult for table backup and recovery , It is recommended to use... On the business side sharding technology .
4、 It is forbidden to store plaintext password in database If you need to store MySQL The password can be used MySQL Built in functions password() Clear text password MD5 To encrypt .
5、SQL It is forbidden to appear in now()、rand()、sysdate()、current_user() Waiting for uncertain results function .
It is suggested that the uncertain time should be taken out at the program layer , Statement level replication scenario , Cause inconsistency between master and slave data ; Functions of uncertain values , produce Of SQL The statement cannot be used .
6、 No use VARBINARY、BLOB Store image 、 Documents, etc. , Use VARCHAR(N),N all The quantity may be small
7、 Prohibit operations on columns An operation on a column will result in Mysql Full table scan due to index failure .
Specification item :1、 Create table character set using UTF8 perhaps UTF8mb4
UTF8 Unified and universal , There will be no risk of transcoding . If there is a need for emoticons , have access to utf8mb4
2、 The table must have a primary key , Recommended UNSIGNED Autoincrement column as primary key
Table has no primary key ,INNODB Hidden primary key columns will be set by default ; Tables without primary keys are very inefficient in locating data rows and reduce the efficiency of row based replication . When creating a table, you must define a self incrementing column as the primary key ( Nothing to do with business logic , If the application data has a unique candidate column, it can be made into a unique key ), Reiterated INNODB Each table in the storage engine must have a business independent auto increment column as the primary key .
Another suggestion :
1、 It is recommended to use prefix matching fuzzy queries cautiously
Prefix matching can lead to direct full table scan or full index scan , The worst performance , No extensions , Basically unacceptable .
2、 It is recommended that all fields be defined as NOT NULL, Set up default value .
Defined as Not Null Here's why :
- MySQL Each in the database is NULL All of the columns need extra 1 Bytes for storage , Waste space resources .
- B Tree indexes are not stored NULL value , If the index field can be NULL, Indexing efficiency will decrease .
- Suggest using 0、 Special value or empty string instead of NULL value .
3、 It is recommended to avoid implicit conversion in queries MySQL If the query field is different from the table definition field, an implicit conversion will occur , Thus, the index cannot be used, resulting in low query efficiency .
4、 It is recommended not to MySQL Store business logic in the database .
Databases are stateful services , Changes are complex and slow , If you put the business logic into the database , It will limit the rapid development of the business . It is suggested to advance the business logic , Put it in the front-end or middle logical layer , And take the database as the storage layer , Realize the separation of logic and storage .
5、 Subqueries are not recommended For subqueries ,mysql The sub query results will be returned to the external table , And scan the external table
6、 It is recommended that the fields be large 、 Fields with low access frequency are split into separate tables to store , Separate hot and cold data
When our table is similar to TEXT Or big VARCHAR Type of large field when , If we don't need this field most of the time we access this table , We should split it into separate tables , To reduce the storage space occupied by common data . One obvious benefit of this is that the number of data pieces that can be stored in each data block can be greatly increased , Both reduce Physics IO frequency , It can also greatly improve the cache hit rate in memory .
7、 Suggest using in() /union Replace or, And pay attention in The number of ( The number depends on the specific situation )
8、 It is recommended not to use mysql stored procedure 、 trigger 、 Functions, etc ( As the case may be )
It's easy to combine business logic with DB Couple together , And for the current data volume stored procedure 、 trigger 、 Functions and so on have no advantage ( stored procedure 、 Functions have great advantages in processing large amounts of data and complex business logic ), and mysql Stored procedures also have certain BUG.
边栏推荐
- Informatics Olympiad all in one 1194: mobile route
- MCS: discrete random variable Poisson distribution
- .NET程序配置文件操作(ini,cfg,config)
- 「游戏引擎 浅入浅出」98. SubstancePainter插件开发
- Take another picture of cloud redis' improvement path
- Lumiprobe 活性染料丨环炔染料:AF488 DBCO,5 异构体
- I am 35 years old. Can I change my career to be a programmer?
- ROS notes (10) - Launch file startup
- 使用自定义注解实现Redis分布式锁
- Leetcode notes: biweekly contest 81
猜你喜欢

MCS: discrete random variable - Hyper geometric distribution

Knowledge points: what are the know-how of PCB wiring?

MySQL的json 数组操作 json_array_append、json_array_insert

Create an API rapid development platform, awesome!

Hi,你有一份Code Review攻略待查收

Imgutil image processing tool class, text extraction, image watermarking

Lumiprobe 脱氧核糖核酸丨炔烃dT亚磷酰胺

Lumiprobe 活性染料丨环炔染料:AF488 DBCO,5 异构体

第九章 APP项目测试(4) 测试工具

Render follows, encapsulating a form and adding data to the table
随机推荐
SOFARegistry 源码|数据同步模块解析
服务器的数据库连不上了【服务已起、防火墙已关、端口已开、netlent 端口不通】
MCS: multivariate random variable polynomial distribution
For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?
Lumiprobe reactive dye cycloalkyne dye: af488 dbco, 5 isomer
Secondary pointer
雷达天线简介
Chapter IX app project test (4) test tools
Building SQL statements in Excel
知识点:PCB线路板布线都有哪些诀窍?
第九章 APP项目测试(此章完结)
MySQL开发规范.pdf
在shop工程中,实现一个菜单(增删改查)
Unity C # basic review 26 - first acquaintance Commission (p447)
Const usage
File常用工具类, 流相关运用 (记录)
数据挖掘复习
中序和后序遍历构建二叉树[递归划分区间与回溯拼接子树+中后序和中前序的相似与不同]
Lumiprobe 活性染料丨杂染料:BDP FL 神经酰胺
BioVendor游离轻链(κ和λ)Elisa 试剂盒的化学性质