- Alternatively IN with EXISTS, NOT EXISTS with alternative NOT IN
- Avoid the use of columns in the index calculation, because this will cause the index fail
- Avoid the use of IS NULL and IS NOT NULL index columns
- Query optimization, should try to avoid full table scan, first consider the establishment by the column involved in where and order index
- Try to avoid fields where the null value judgment clause, or your engine will give up using the index, so a full table scan
- Try to avoid the operation of the fields in the where clause expression, or your engine will give up using the index, so a full table scan
- Try to avoid using the where clause! = Or <> operator, or they will give up the engine using the index, thereby performing a full table scan
- Try to avoid the use or to connect to the conditions in the where clause, or your engine will give up using the index, so a full table scan
- If the value is continuous, you can not use in between
- Do not use anywhere select * from table, use the specific field instead of "*", remove only the required fields
- Fuzzy searching try to avoid using pre-percent sign, or your engine will give up using the index, so a full table scan
- An index number table is best not more than 6, because too much will affect the index update speedometer
- If the field contains only numerical information, try not designed for the type of character, otherwise it will reduce the performance of queries and connections, while also increasing the storage overhead
- Avoid frequent create and delete temporary tables, system tables to reduce the consumption of resources
- Try to use varchar / nvarchar instead of char / nchar, because of the small field of variable-length memory space, it saves storage space, while for the query, the search within a relatively small field, more efficient naturally
- Try to use table variables instead of temporary tables
Interviewer: What are some ways to talk about optimizing SQL statements
Guess you like
Origin blog.csdn.net/weixin_38106322/article/details/105239716
Ranking