X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 874E7528C7 for ; Thu, 9 Jun 2005 02:27:10 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57732-09 for ; Thu, 9 Jun 2005 05:27:05 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9C0DC528BB for ; Thu, 9 Jun 2005 02:27:04 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j595R4OI007274; Thu, 9 Jun 2005 01:27:04 -0400 (EDT) To: "Dmitri Bichko" Cc: "Sql-Postgre" Subject: Re: Indices and user defined operators In-reply-to: <6338.1118289716@sss.pgh.pa.us> References: <6338.1118289716@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 09 Jun 2005 00:01:56 -0400" Date: Thu, 09 Jun 2005 01:27:04 -0400 Message-ID: <7273.1118294824@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/126 X-Sequence-Number: 21727 I wrote: > "Dmitri Bichko" writes: >> So, is there any way to make these operators use an index defined as >> above? > If you've set things up so that the operators are defined by inline-able > SQL functions, I'd sort of expect it to fall out for free ... Here's a quick proof-of-concept: regression=# create function iequal(text,text) returns bool as regression-# 'select upper($1) = upper($2)' language sql strict immutable; CREATE FUNCTION regression=# create operator *= (procedure = iequal, leftarg = text, regression(# rightarg = text , commutator = *= ); CREATE OPERATOR regression=# explain select * from text_tbl where f1 *= 'foo'; QUERY PLAN --------------------------------------------------------- Seq Scan on text_tbl (cost=0.00..1.03 rows=1 width=32) Filter: (upper(f1) = 'FOO'::text) (2 rows) regression=# create index fooi on text_tbl(upper(f1)); CREATE INDEX regression=# set enable_seqscan TO 0; -- because my test table is tiny SET regression=# explain select * from text_tbl where f1 *= 'foo'; QUERY PLAN ---------------------------------------------------------------------- Index Scan using fooi on text_tbl (cost=0.00..4.68 rows=1 width=32) Index Cond: (upper(f1) = 'FOO'::text) (2 rows) This is with CVS tip, but I'm pretty sure it works as far back as 7.4. regards, tom lane