当前位置:网站首页>MySQL development considerations (Alibaba development manual)
MySQL development considerations (Alibaba development manual)
2022-06-12 15:23:00 【Stars_ min】
1. Make a schedule
1.1 Field constraints that indicate whether the concept is
You have to use is_xxx How to name , The data type is unsigned tinyint( 1 Said is ,0 Indicate no )
Be careful : If any field is non negative , Must be unsigned
1.2 Table name 、 Field name constraints
For table names 、 Field names must be lowercase letters or numbers , Do not start with numbers , Prohibit only numbers between two underscores , And the table name cannot use plural names
1.3 Disable reserved words , such as :desc、range、match wait
1.4 Index name constraint
| Index name | Name constraint |
|---|---|
| primary key | pk_ Field name |
| unique index | uk_ Field name |
| General index | idx_ Field name |
Full-text index :InnoDB I won't support it ,Myisam Good support performance , Generally in char、varchar、text Column to create
1.5 Decimal type constraint
Decimal type is decimal, No use float and double
reason : At the time of storage ,float and double There is a problem of precision loss
Suggest : The range of stored data exceeds decimal The scope of the , It is recommended to split the data into integers and decimals for storage
1.6 If the stored string length is almost equal , Use char Fixed length string type
2. Index specifications
2.1 Fields with unique characteristics on the business , Even a combination of multiple fields , You have to build a unique index
explain : Building a unique index affects insert The number of degrees can be ignored , But building a unique index will increase the search speed
2.2 More than three tables prohibited join, need join Field of , Data types must be consistent ; When multi table associated query , Ensure that the associated field needs to have an index
2.3 stay varchar Index on field , Index length must be specified , There's no need to index all fields
2.4 Page search must not be left blurred or full blurred , If you need to go to search engine to solve .
3. SQL sentence
3.1 Do not use count( Name ) perhaps count( Constant ) To replace count(*)
count(*) The statistical value is NULL The line of , and count( Column ) Will not count as null Row of values
3.2 count(distinct col) Calculate the column Division NULL Duplicate lines outside
Be careful :count(distinct col1,col2) If one of the columns is all null, So even if the other column has different values , And will return to 0
3.3 When the values of a column are all NULL,count(col) The return result is 0 however sum(col) The return result of is NULL
3.4 Use isnull() To determine whether it is null value
explain :null The comparison with any value is null
1.null<>null The return value is null, instead of false
2.null=null The return value is null, instead of true
3.null<>1 The return result is null, instead of true
3.5 When the code writes the paging query logic , if count by 0 Should return directly , Avoid executing subsequent paging statements
3.6 Do not use foreign keys and cascades , All foreign keys must be resolved at the application layer
3.7 Stored procedures are not allowed , Stored procedures are difficult to debug and extend , There is no portability
3.8 Data revision ( When deleting or modifying ) First select, Avoid deleting by mistake , It is confirmed that the correction is correct
4. ORM mapping
4.1 When querying tables , Never use * As a list of query fields , What fields are required must be clearly stated
4.2 POJO The Boolean attribute of a class cannot be added is, Database fields must be added is-, Ask for in resultMap Mapping between fields and attributes in
4.3 Do not use resultClass When a parameter is returned , Even if all class attribute names and database fields correspond to each other , You also need to define
4.4 sql.xml Use of configuration parameters #{}
4.5 It is not allowed to take it directly HashMap And HashTable As the output of the query result set
边栏推荐
猜你喜欢

ROS 中 boost::bind( ) 的使用

Ngork implements intranet penetration -- free

Pta: self test -2 prime pair conjecture (20 points)
![CUDA out of memory or brokenpipeerror: [errno 32] broken pipe or oserror: [winerror 1455] solution to the problem that the page file is too small](/img/2c/63f1c865105a74ed651bb0ef97ab60.png)
CUDA out of memory or brokenpipeerror: [errno 32] broken pipe or oserror: [winerror 1455] solution to the problem that the page file is too small

ngork实现内网穿透--免费
![CUDA out of memory 或 BrokenPipeError: [Errno 32] Broken pipe 或 OSError: [WinError 1455] 页面文件太小的解决办法](/img/2c/63f1c865105a74ed651bb0ef97ab60.png)
CUDA out of memory 或 BrokenPipeError: [Errno 32] Broken pipe 或 OSError: [WinError 1455] 页面文件太小的解决办法
![[jvm learning] types of GC and allocation process of objects on JVM heap](/img/f3/8141be7bcbf79d9c874f9cc09683c8.jpg)
[jvm learning] types of GC and allocation process of objects on JVM heap

Swap numbers, XOR, operator correlation

Function recursion example

粒子滤波学习记录
随机推荐
org. xml. sax. SAXParseException; lineNumber: 63; columnNumber: 10; The definition of "mapper" in the related type must be matched with "(CAC
Introduction to microservices
Distributed concurrent repeated submission
Change according to the situation, the road to promotion in the second half of 2022
學習是一件逆人性的事情(成為高手的內功心法)
sql server 2008 的导入导出步骤
Error 1105: message:\“raft entry is too large
CUDA out of memory 或 BrokenPipeError: [Errno 32] Broken pipe 或 OSError: [WinError 1455] 页面文件太小的解决办法
Classification of annotations
Codeforces Round 797 (Div. 3,CF1690)全题解
[jvm learning] class loading subsystem
[jvm learning] types of GC and allocation process of objects on JVM heap
Rust tip - running the tensorrt model through FFI programming
About layoffs in Internet companies
频繁项集产生强关联规则的过程
MySQL开发注意事项(阿里巴巴开发手册)
Qiming cloud sharing | demonstrate the switch through an example of the matter protocol to control the light on and off through the matter protocol
Seaborn Brief
Microservice fault tolerance
How to write year-end summary