Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: SQL functions and indexes

RE: SQL functions and indexes

From: Gillies, Garry <garry_at_weir.co.uk>
Date: Tue, 28 Nov 2000 12:21:49 -0000
Message-Id: <10694.123043@fatcity.com>


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

  1. SQL> select ename from emp where ename like 'M%';

    ENAME



    MARTIN
    MILLER     Execution Plan
       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



    MARTIN
    MILLER     Execution Plan
       0      SELECT STATEMENT Optimizer=RULE 
       1    0   TABLE ACCESS (FULL) OF 'EMP'

3. SQL> select ename from emp where ename = 'MILLER';

    ENAME



    MILLER     Execution Plan
       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



    MILLER     Execution Plan
       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 :)

++++++++++++++++++++++++++++++++++++

All internet traffic to this site is
automatically scanned for viruses
and vandals.
++++++++++++++++++++++++++++++++++++

------_=_NextPart_001_01C05935.C81E46A0
Content-Type: text/html;

        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.&nbsp; SQL&gt; select ename from emp where ename =
like 'M%'; </FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; ENAME </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; ---------- </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; MARTIN </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; MILLER</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; Execution Plan </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; =

---------------------------------------------------------- </FONT>

<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT STATEMENT Optimizer=3DRULE =
</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
1&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; INDEX (RANGE SCAN) OF 'EMP_N1' = (NON-UNIQUE) </FONT>
</P>
<BR>
<BR>

<P><FONT SIZE=3D2>2.&nbsp; SQL&gt; select ename from emp where =
substr(ename,1,1) =3D 'M'; </FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; ENAME </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; ---------- </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; MARTIN </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; MILLER </FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; Execution Plan </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; =

---------------------------------------------------------- </FONT>

<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT STATEMENT Optimizer=3DRULE =
</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
1&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; TABLE ACCESS (FULL) OF 'EMP'</FONT>
</P>

<P><FONT SIZE=3D2>3.&nbsp; SQL&gt; select ename from emp where ename =
=3D 'MILLER'; </FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; ENAME </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; ---------- </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; MILLER </FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; Execution Plan </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; =

---------------------------------------------------------- </FONT>

<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT STATEMENT Optimizer=3DRULE =
</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
1&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; INDEX (RANGE SCAN) OF 'EMP_N1' = (NON-UNIQUE) </FONT>
</P>
<BR>
<BR>

<P><FONT SIZE=3D2>4.&nbsp; SQL&gt; select ename from emp where ename || =
'' =3D 'MILLER'; </FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; ENAME </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; ---------- </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; MILLER </FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; Execution Plan </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; =

---------------------------------------------------------- </FONT>

<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT STATEMENT Optimizer=3DRULE =
</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
1&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; TABLE ACCESS (FULL) OF 'EMP' </FONT>
</P>

<P><FONT SIZE=3D2>Statements 2 &amp; 4 are functionally identical to =
statements 1 &amp; 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, &quot;SQL functions =
ignore table indexes and</FONT>
<BR><FONT SIZE=3D2>therefore can impact on performance.&quot;.&nbsp; So =
now I'm wondering if this is</FONT>
<BR><FONT SIZE=3D2>correct or did I take a confused message.&nbsp; =
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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US