今天开发的传一条sql语句,查询很慢,半天都不返回数据,其中一张表的where 条件只有一个完全(CUSTOMER_TRUE_NAME llike %xxxxxxx%) ,导致不走此列上的索引,但又不得不使用完全like,此表又很大,还好查询只需要三个列,所以使用查询需要的三个列创建索引后,再查询就走索引了
SQL> select c.CUSTOMER_xxxx_NAME ,c.MOBILE_CODE MOBILE_CODE,c.xxxx_NO from xxxxxxxc where c.CUSTOMER_xxxxx_NAME like '%xxxxxx%';
Execution Plan
----------------------------------------------------------
Plan hash value: 3727569346
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 33515 | 1210K| 1311 (3)| 00:00:16 |
|* 1 | INDEX FAST FULL SCAN| CUSTOMER_xxxxx_NAME_INDEX | 33515 | 1210K| 1311 (3)| 00:00:16 |
-------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("C"."CUSTOMER_TRUE_NAME" LIKE '%xxxxx%')
注:这样操作会增加此表的维护成本,影响dml语句的性能,且如果索引很大,此方法性能也不会很高。如果like 中使用的字符串不变的话,也可使用函数索引来解决此问题。