/ * Under normal circumstances, the percent sign index may be used later * /
SELECT Nickname from T WHERE Nickname like ' the DBA% '
/ * percent sign in front of the index can not be used, solutions rewritten sql, adding reverse index * /
Create index idx_t1_name ON T1 ( Reverse (name))
SELECT name from T1 wHERE Reverse (name) like Reverse ( ' % ADC ' );
/ * both before and after a percent, this is generally not use an index. * /
/ * 1. the search condition character string is always in a fixed position start string, in the cable to optimize the function can be created, to create subStr index function, and then use like 'abc%' example:* /
Create index idx_substr_t1_name ON T1 (substr (name, . 5 , 10 ));
SELECT ID, name, name_type from T1 WHERE substr (name, . 5 , 10 ) like ' ABC% ' ;
/ * 2. search condition character always a fixed location at the end of the string occurs, a combination index can be created to optimize the function, create reverse + substr combination index function, and then using Reverse like 'ABC%' * /
Create index idx_t1_reverse_name ON T1 ( Reverse (substr (name, . 1 , length (name) - . 4 )));
SELECTID, name, name_type from T1 WHERE Reverse (substr (name, . 1 , length (name) - . 4 )) like Reverse ( ' % ABC ' )
/ * 3. a fixed position search string do not appear, optimization, first establish a common index column rewritten SQL * /
Create index idx_t1_name ON T1 (name)
SELECT ID, name, name_type from T1 WHERE name in ( SELECT name from T1 WHERE name like ' %% ABC ' )