Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g1FGl7E02852 for ; Fri, 15 Feb 2002 11:47:07 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g1FGkkf14412; Fri, 15 Feb 2002 11:46:46 -0500 (EST) To: wweng@kencast.com cc: pgsql-sql@postgresql.org Subject: Re: create index on function - why? In-reply-to: <3C6D3684.9040101@kencast.com> References: <3C6D3684.9040101@kencast.com> Comments: In-reply-to Wei Weng message dated "Fri, 15 Feb 2002 11:25:40 -0500" Date: Fri, 15 Feb 2002 11:46:46 -0500 Message-ID: <14409.1013791606@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200202/179 X-Sequence-Number: 6605 Wei Weng writes: > But what is the rationale behind creating index on a function? To speed up searching. For example, given create table foo (f1 text); create index fooi on foo (upper(f1)); the index can be used for queries like select * from foo where upper(f1) = 'HELLO'; Without the index, there'd be no way to avoid a sequential scan --- not to mention evaluation of the function at every row. With the index, the above query actually performs zero evaluations of upper() --- the work got pushed into row insertion, instead. A functional index is sort of like a hidden, precomputed column added to your table. regards, tom lane