Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: SQL functions and indexes
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C05935.C81E46A0
Content-Type: text/plain;
charset="iso-8859-1"
The use of a function on an indexed column cripples the use of that index (Pre 8.1)
Consider the EMP table with an index on ENAME
ENAME
0 SELECT STATEMENT Optimizer=RULE 1 0 INDEX (RANGE SCAN) OF 'EMP_N1' (NON-UNIQUE)
2. SQL> select ename from emp where substr(ename,1,1) = 'M';
ENAME
0 SELECT STATEMENT Optimizer=RULE 1 0 TABLE ACCESS (FULL) OF 'EMP'
3. SQL> select ename from emp where ename = 'MILLER';
ENAME
0 SELECT STATEMENT Optimizer=RULE 1 0 INDEX (RANGE SCAN) OF 'EMP_N1' (NON-UNIQUE)
4. SQL> select ename from emp where ename || '' = 'MILLER';
ENAME
0 SELECT STATEMENT Optimizer=RULE 1 0 TABLE ACCESS (FULL) OF 'EMP'
Statements 2 & 4 are functionally identical to statements 1 & 3, but the index is not used because a function is being applied to the column.
As of release 8.1 you can have function based indexes, which complicates matters a little.
Hope This Helps
Garry
Last night doing some study for OCP exam I came across a note I had written in course material for PL/SQL, "SQL functions ignore table indexes and therefore can impact on performance.". So now I'm wondering if this is correct or did I take a confused message. Anyone know?
Sean :)
++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2651.75">
<TITLE>RE: SQL functions and indexes</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>The use of a function on an indexed column cripples =
the use of that index (Pre 8.1)</FONT>
</P>
<P><FONT SIZE=3D2>Consider the EMP table with an index on ENAME</FONT>
</P>
<P><FONT SIZE=3D2>1. SQL> select ename from emp where ename =
like 'M%'; </FONT>
</P>
<P><FONT SIZE=3D2> ENAME </FONT>
<BR><FONT SIZE=3D2> ---------- </FONT>
<BR><FONT SIZE=3D2> MARTIN </FONT>
<BR><FONT SIZE=3D2> MILLER</FONT>
</P>
<P><FONT SIZE=3D2> Execution Plan </FONT>
<BR><FONT SIZE=3D2> =
---------------------------------------------------------- </FONT>
<P><FONT SIZE=3D2>2. SQL> select ename from emp where =
substr(ename,1,1) =3D 'M'; </FONT>
</P>
<P><FONT SIZE=3D2> ENAME </FONT>
<BR><FONT SIZE=3D2> ---------- </FONT>
<BR><FONT SIZE=3D2> MARTIN </FONT>
<BR><FONT SIZE=3D2> MILLER </FONT>
</P>
<P><FONT SIZE=3D2> Execution Plan </FONT>
<BR><FONT SIZE=3D2> =
---------------------------------------------------------- </FONT>
<P><FONT SIZE=3D2>3. SQL> select ename from emp where ename =
=3D 'MILLER'; </FONT>
</P>
<P><FONT SIZE=3D2> ENAME </FONT>
<BR><FONT SIZE=3D2> ---------- </FONT>
<BR><FONT SIZE=3D2> MILLER </FONT>
</P>
<P><FONT SIZE=3D2> Execution Plan </FONT>
<BR><FONT SIZE=3D2> =
---------------------------------------------------------- </FONT>
<P><FONT SIZE=3D2>4. SQL> select ename from emp where ename || =
'' =3D 'MILLER'; </FONT>
</P>
<P><FONT SIZE=3D2> ENAME </FONT>
<BR><FONT SIZE=3D2> ---------- </FONT>
<BR><FONT SIZE=3D2> MILLER </FONT>
</P>
<P><FONT SIZE=3D2> Execution Plan </FONT>
<BR><FONT SIZE=3D2> =
---------------------------------------------------------- </FONT>
<P><FONT SIZE=3D2>Statements 2 & 4 are functionally identical to =
statements 1 & 3, but</FONT>
<BR><FONT SIZE=3D2>the index is not used because a function is being =
applied to the</FONT>
<BR><FONT SIZE=3D2>column.</FONT>
</P>
<P><FONT SIZE=3D2>As of release 8.1 you can have function based =
indexes, which complicates</FONT>
<BR><FONT SIZE=3D2>matters a little.</FONT>
</P>
<P><FONT SIZE=3D2>Hope This Helps</FONT>
</P>
<P><FONT SIZE=3D2>Garry</FONT>
</P>
<P><FONT SIZE=3D2>Last night doing some study for OCP exam I came =
across a note I had written</FONT>
<BR><FONT SIZE=3D2>in course material for PL/SQL, "SQL functions =
ignore table indexes and</FONT>
<BR><FONT SIZE=3D2>therefore can impact on performance.". So =
now I'm wondering if this is</FONT>
<BR><FONT SIZE=3D2>correct or did I take a confused message. =
Anyone know?</FONT>
</P>
<P><FONT SIZE=3D2>Sean :)</FONT>
</P>
<FONT SIZE=3D3 COLOR=3DBLUE><PRE>++++++++++++++++++++++++++++++++++++
Received on Tue Nov 28 2000 - 06:21:49 CST