---
title: "oracle索引与like条件的关系"
author: "fourfire"
date: "2008-07-25T13:36:59Z"
tags: []
categories: ["非技术"]
slug: "oracle-like"
draft: false
lastmod: "2008-07-25T13:36:59Z"
id: 219489
url: "https://fourfire.iteye.com/blog/219489"
---

表：gzl_action_define
字段:id:主键，有索引
     name:一般字段，无索引
以下是各种写法的结果
1
select t.name
  from gzl_action_define t
 where  t.id ='12'
使用索引(UNIQUE SCAN)
2
select t.name
  from gzl_action_define t
 where  t.id like '12%'
使用索引(RANGE SCAN)
3
select t.name
  from gzl_action_define t
 where  t.id like '%12'
不使用索引(TABLE ACCESS (FULL))
4
select t.id
  from gzl_action_define t
 where  t.id like '%12'
使用索引(FAST FULL SCAN)
5 
select t.name
  from gzl_action_define t
 where  t.id like '%12%'
不使用索引(TABLE ACCESS (FULL))
6
select t.id
  from gzl_action_define t
 where  t.id like '%12%'
使用索引(FAST FULL SCAN)
3、5的原因不是很清楚，估计是%在前带来的问题