1. Test environment:
1. Database: Sql Server 2008
2. Test table: 15000 records, char type primary key, no other indexes
3. Test field: ntext type, the maximum data length is 12000
2. Test statement:
1。select * from ProductTemp where ProductDesc like ‘%192.168.70.236%’
2。select * from ProductTemp where charindex(‘192.168.70.236’,ProductDesc)>0
3。select * from ProductTemp where patindex(’%192.168.70.236%’,ProductDesc)>0
3. Test results:
1. Efficiency test result: charindex> like> patindex, the efficiency is about 20%
2. Applicability test results:
1) Charindex has requirements for the maximum displacement of the search result. After testing, the displacement of the ntext field in Sql2008 cannot exceed 3987, otherwise it returns 0;
2) There is no displacement limit for patindex and like;
3) patindex supports matching expressions and can be applied to regular expressions;
4) Like can use'%oldstring%' for fuzzy matching;
5) Charindex can only match fixed strings