Received: from hercules.dns-solutions.net (hercules.dns-solutions.net [209.66.124.56]) by postgresql.org (8.11.3/8.11.4) with SMTP id g1FHlLE32159 for ; Fri, 15 Feb 2002 12:47:22 -0500 (EST) (envelope-from dhuselid@pepperdash.com) Received: (qmail 8679 invoked from network); 15 Feb 2002 17:47:25 -0000 Received: from 146-115-44-119.c3-0.sbo-ubr1.sbo-ubr.ma.cable.rcn.com (HELO TELLURIUM) (@146.115.44.119) by pepperdash.com - 146.115.44.119 with SMTP; 15 Feb 2002 17:47:25 -0000 From: "David Huselid" To: "'Tom Lane'" , Cc: Subject: Re: create index on function - why? Date: Fri, 15 Feb 2002 13:01:15 -0500 Message-ID: <004901c1b64a$c32e4870$9801a8c0@TELLURIUM> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2616 In-reply-to: <14409.1013791606@sss.pgh.pa.us> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal X-Archive-Number: 200202/183 X-Sequence-Number: 6609 Hi All, Following the advice given below, I am trying to create an index on the function upper() when used on a lastname varchar(60) column. PostgreSQL 7.0.2 Create table members (lastname varchar(60)); Then I am creating the index as: Create index upper_lastname_idx on members (upper(lastname)); But I am getting the following error: ERROR: DefineIndex: function 'upper(varchar)' does not exist I use the upper() function frequently and it works just fine, I just want the search to use the index instead of a seq scan. Thanks in advance. Dave -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Tom Lane Sent: Friday, February 15, 2002 11:47 AM To: wweng@kencast.com Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] create index on function - why? 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 ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)