First, the basic norms
(1) must use the InnoDB storage engine
Interpretation: support transactions, row-level locking, better concurrent performance, CPU and memory cache page optimization allows greater resource utilization
(2) a new library using utf8mb4 character set
Interpretation: Unicode, without transcoding, no garbled risk, save space
(3) data tables, data fields must join Chinese comments
Interpretation: N tm years later who knows this r1, r2, r3 field is doing
(4) prohibiting the use of stored procedures, views, triggers, the Event
Interpretation: Internet business large high concurrent data, architecture design idea is to "liberate database CPU, will be transferred to the computing service layer", a large amount of concurrent case, these functions are likely to slow death database, business logic services layer have put better scalability, can be easily achieved "by the machine will increase performance." It specializes in database storage and indexing, CPU computing or move it
(5) prohibits storing large files or large photo
Interpretation: Why is it not good to let the database do things? Large files and photos stored in the file system, database, how good save URI
Second, the naming convention
(6) provided with a domain name only, not connected to a database ip
(7) online environment, development environment, test environment within the database domain name follows the naming convention
Business Name: xxx
online environment: dj.xxx.db
development environment: dj.xxx.rdb
test environment: dj.xxx.tdb
from the library after the name add -s logo, prepared by the library after the name plus -ss identity
online from the library: dj.xxx-s.db
online library Preparation: dj.xxx-sss.db
(8) library name, table names, field names: lowercase, underline style, no more than 32 characters, you must see to know the name is intended to prohibit the English alphabet mix
(9) the table name t_xxx, non-unique index name idx_xxx, unique index name uniq_xxx
Third, the design rules of Table
(10) must be smaller than the number of single instance 500
(11) the number of single-column table 30 must be less than
(12) The table must have a primary key, e.g. increment primary key
Interpretation:
A) primary key increment data line is written can improve insert performance, avoid page splitting, reducing table fragmentation enhance space and memory usage
b) primary keys to select a shorter data type, Innodb engine general index value will be saved primary key , shorter data types can effectively reduce the disk space index, the index cache to improve efficiency
c) delete the table without a primary key, the main row pattern from architecture, will lead to the standby database live ram
(13) prohibit the use of foreign keys, foreign key integrity constraints if required application control
Interpretation: foreign keys can lead to coupling between the table and the table, update and delete operations will involve the associated table, very sql performance impact, and even cause a deadlock. High concurrency likely to cause database performance, high concurrency big data business scenarios using performance-priority database
Fourth, field design specifications
(14) must be defined as NOT NULL field and provide default values
Interpretation:
A) a null index column enable / statistical index / value comparison is more complicated, more difficult to optimize for MySQL
b) null MySQL this type require special handling inside, increasing the complexity of the database process of the records; under the same conditions the table has more empty field when the processing performance of the database will reduce a lot of
c) null values require more storage space, whether it is null or the index of the list in each row are required to identify additional space
d ) of the null processing time, only use is null or is not null, and not with =, in, <, <>the operation symbols. Such as: where name = 'shenjian', if there is a null value is recorded as the name, the query result will not include a null value is recorded for the name!
(15) prohibit the use of TEXT, BLOB Types
Interpretation: will waste more disk space and memory, a large number of non-essential data will heat a large field of inquiry eliminated, resulting in drastically reduced memory hit rate, affect database performance
(16) prohibit the use of decimal currency storage
Interpretation: using an integer it, decimals easily lead to no money
(17) must use varchar (20) to store the phone number
Interpretation:
A) related to the area code or country code, may appear + - ()
b) phone number will do the math it?
c) varchar can support fuzzy queries, such as: like "138%"
(18) prohibits the use ENUM, may be used instead of TINYINT
Interpretation:
A) add new ENUM values do DDL operations
inside the actual storage b) ENUM is an integer, you think you are the definition of string?
Fifth, the index design specifications
(19) the single table index proposed control within 5
(20) Number of single index field does not allow more than five
Interpretation: fields when more than 5, the actual effective filtration has no effect of the data
(21) prohibit the establishment of the index on the updated very frequently, discrimination is not high property
Interpretation:
A) update will change the B + tree, frequently updated field indexing can greatly reduce database performance
b) is not "sex" discrimination of this property, indexing is meaningless, can not effectively filter the data, and performance similar full table scan
(22) establish a composite index, identifies the field must be high on the front
Interpretation: can more effectively filter the data
Six, SQL preparation of specifications
(23) prohibits the use SELECT *, obtain only the necessary fields, you need to display the Description column properties
Interpretation:
A) reading unneeded columns increases CPU, IO, NET consumption
b) can not be effectively utilized cover index
c) using the SELECT * BUG prone procedures in the field to add or delete
(24) prohibits the use INSERT INTO t_xxx VALUES (xxx), you must display the specified attribute columns inserted
: Interpreting program after BUG easy to add or remove fields
(25) prohibit the use of implicit conversion property
Interpretation: the SELECT uid the FROM t_user the WHERE phone = 13812345678 lead to a full table scan, index and can not hit the phone, guess what? (This line problem appears more than once)
(26) prohibit the use of the function or expression properties WHERE condition
Interpretation: the SELECT UID T_USER the WHERE FROM_UNIXTIME the FROM (Day)> = '2017-02-15' cause full table scan correct wording is: SELECT uid FROM t_user WHERE day>00 ')
(27) prohibits negative fuzzy query to the query, as well as the beginning of%
Interpretation:
A) Negative query:!! NOT, =, <the like, will lead to a full table scan
b)% at the beginning of the fuzzy queries, cause a full table scan
(28) prohibits the use of a large table JOIN query, prohibit large tables using subqueries
Interpretation: will produce a temporary table, consumes more memory and CPU, greatly affect database performance
(29) prohibit the use of OR conditions must be changed to IN query
Interpretation: the old version of OR Mysql query can not hit the index, even if we can hit the index, why let consume more CPU database query optimization to help implement it?