==========================================
MSSQL like Efficiency
Today, I have studied the efficiency of like for one day. The effect is as follows: the first case is:
Run: Select * from question where title like '? %'
The result is as follows:
(Eight rows are affected)
Table 'Question '. 1 scan count, 259 logical reads, 0 physical reads, 0 pre-reads, 18 lob logical reads, 0 physical reads, and 0 lob pre-reads.
The second case is: Select * from question where title like '%? %'
The result is as follows:
(Row 3 is affected)
Table 'Question '. 1 scan count, 259 logical reads, 0 physical reads, 0 pre-reads, 5885 lob logical reads, 0 physical reads, and 0 lob pre-reads.
The third case is: Select * from question where charindex (title ,'? % ')> 0
The execution result is as follows:
(3 rows affected)
Table 'Question '. 1 scan count, 259 logical reads, 0 physical reads, 0 pre-reads, 7 lob logical reads, 0 physical reads, and 0 lob pre-reads.
It can be seen that % has performed a full table scan, while % is not bad, but it can be greatly improved if you use charindex to replace, but the remarks type cannot be operated.
========================================================== =
MSSQL Optimization
1. It is critical to create an index. There are two types of indexes: focused index and non-focused index. However, the cost of index maintenance is also high, so it is best to be unique and cannot be modified; if there are duplicate items, the indexing effect is poor.
2. try to reduce the number of views, but the number of views can be reduced.CodeNumber of duplicates
3. Reduce the Selection Range
========================================================== ===