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 9649452861 for ; Wed, 8 Jun 2005 23:22:30 -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 19532-04 for ; Thu, 9 Jun 2005 02:22:21 +0000 (GMT) Received: from mail.aveo.aveopharma.com (67.109.105.227.ptr.us.xo.net [67.109.105.227]) by svr1.postgresql.org (Postfix) with SMTP id D027E52825 for ; Wed, 8 Jun 2005 23:22:20 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Indices and user defined operators Date: Wed, 8 Jun 2005 22:23:42 -0400 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Indices and user defined operators Thread-Index: AcVsmkGWttVXSPG7RxGBmV9BtSEqKA== From: "Dmitri Bichko" To: "Sql-Postgre" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.091 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200506/124 X-Sequence-Number: 21725 Being lazy, I've created a set of case incensitive text comparison operators: =3D*, <*, >*, and !=3D*; the function for each just does an UPPER() on both arguments and then uses the corresponding builtin operator. What would make these REALLY useful, is if when running something like: SELECT * FROM foo WHERE bar =3D* 'baz';=20 postgres would know to use an index defined as: CREATE INDEX idx_foo_bar ON foo (UPPER(bar)); Currently, the explain I get for the above situation is: Seq Scan on foo (cost=3D0.00..8696.81 rows=3D1324 width=3D34) Filter: (upper(upper((bar)::text)) =3D 'BAZ'::text) I am vaguely aware of the concept of operator classes, but from what I understand, the op class has to be specified at index creation time; seeing how this is just to save a little typing, I'd rather not have to rely on these ops and opclasses being defined for the rest of the database to work. Also I need to still be able to do SELECT * FROM foo WHERE UPPER(bar) =3D UPPER('baz') and have it use the same index. So, is there any way to make these operators use an index defined as above? Thanks, Dmitri