当前位置:网站首页>Experience in database optimization

Experience in database optimization

2022-06-09 22:37:00 Versatile senior

Database optimization experience

1、 use PreparedStatement Generally speaking, it's better than Statement High performance , And it can prevent SQL Injection attack

2、 There are foreign key constraints that affect insert and delete performance , If the program can guarantee the integrity of the data , Remove the foreign key when designing the database . Try to use single meter in large e-commerce

3、 Appropriate redundancy is allowed in the table , Use space for time , Improve query efficiency

4、 The user name and password are separated from the user table . In the login service, you only need to query the user name and password .

5、 Use index . select As far as possible need not *, Even if you query all the fields, try to write them out You can use join queries and never subqueries , Because the bottom layer of the subquery is the join query
Use indexes rationally to improve efficiency ( The essence of indexing is a mechanism to improve efficiency , It's essentially a tree ) For often appearing in where Index columns in clause For often appearing in order
by,distinct Index the fields in
Don't always be in DML( Retrieve or modify ) Index on the table of ( It is easy to cause inaccurate index , The solution is rebuild Rebuild , whatever
DML All operations are updates index, This is the price )
Don't index your resume on a small list ( Indexing resumes and maintaining them also consume resources , Create a small table The index will cause the maintenance time of the index to be longer than the data query time )
Limit the number of indexes on the table , The more indexes, the better ( Indexes take up table space , More External maintenance ) Delete rarely used , Unreasonable index

4、 Too much data in the database , What to do when the database is close to crashing ?

1、 Index optimization and SQL Statement optimization is a must , Avoid fuzzy and non indexed queries , The delete operation is performed according to the clustered index , If the deletion and modification operations are too frequent, you still need to consider splitting tables
2、 See the demand , If the demand is not limited , Then divide the tables
3、 Generally, historical data is regularly transferred to other tables ( Add the year and month to the same table name, for example TABLE201205) file . In this way, the pressure of this year's query of this table is also reduced (90% The query volume is concentrated in this year ), Even querying historical data does not affect performance , Strongly recommend !
4 Optimize the table structure according to your business . Sometimes you can consider using space for time .

原网站

版权声明
本文为[Versatile senior]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206092157112425.html