Home > Database > Mysql Tutorial > body text

MySQL 'military regulations'

亚连
Release: 2018-05-17 11:33:42
Original
1368 people have browsed it

Let me talk about the most practical "military regulations" on MYSQL. I hope everyone can remember to abide by

1. Core military regulations

- Do not perform calculations in the database: CPU calculations must be moved to the business layer

- Control the amount of data in a single table: the records in a single table are controlled at 1000w

- Control the number of columns: fields The number is controlled within 20

- Balance paradigm and redundancy: Sacrifice paradigm design and redundant data to improve efficiency

- Reject 3B: Reject large SQL, large things, large batches

2. Field Class Military Rules

                                                                                                                                                                                                                              ’ s ’ s ’ s           ‐ ‐ ‑Use well numeric types
int (4byte)
Bigint (8byte)
Bad Case: int (1)/int (11)
## -Character convert to numbers
Use int instead of char (15) storage IP

- Avoid using NULL fields

                                                                                                             . Invalid

- Use text/blob

less - The performance of varchar will be much higher than text
If blob is unavoidable, please split the table - Do not store
pictures in the database
3. Index Military Rules

- Use indexes carefully and rationally
Improve queries and slow down
updates

The more indexes, the better Good (if you can’t add it, don’t add it. If you want to add it, you must add it) There are too many covered records that are not suitable for building an index, such as "Gender"

- Character fields must be built with prefix index

-to ​​do not do columns for index

Bad Case:
SELECT Id WHERE AGE 1 = 10; ## -InNodb Primary Recommended Main Books Main Key Create Cluster Index

                                                                                              #                                                                                                               ’         ’       ’ s ’ s ’ s ’ s           ‐   ‐   ‐ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​## Please be guaranteed by the program. Operation

                                                                                                                                using   using   using   using                     ‐                        .                . #Upload picture transaction

-avoid using Trig/Func

# trigger

, function does not need

client program to replace

The above is the MySQL "military rules" I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Mysql basic syntax

##Create index for Myql

Some advanced usage of mysql

The above is the detailed content of MySQL 'military regulations'. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template