MSSQL like Efficiency

Source: Internet
Author: User

==========================================
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
========================================================== ===

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.