X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 5AE78D1B4B0 for ; Wed, 3 Mar 2004 23:53:53 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 33280-10 for ; Wed, 3 Mar 2004 19:53:58 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 0FF59D1CAFD for ; Wed, 3 Mar 2004 19:53:50 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i23Nru4H019342; Wed, 3 Mar 2004 18:53:56 -0500 (EST) To: John Siracusa Cc: Postgres Performance Subject: Re: Feature request: smarter use of conditional indexes In-reply-to: References: Comments: In-reply-to John Siracusa message dated "Wed, 03 Mar 2004 14:56:06 -0500" Date: Wed, 03 Mar 2004 18:53:56 -0500 Message-ID: <19341.1078358036@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/54 X-Sequence-Number: 5910 John Siracusa writes: > Given an index like this: > CREATE UNIQUE INDEX i1 ON t1 (c1) WHERE c1 IS NOT NULL; > and a query like this: > SELECT * FROM t1 WHERE c1 = 123; > I'd like the planner to be smart enough to use an index scan using i1. Send a patch ;-) The routine you want to teach about this is pred_test_simple_clause() in src/backend/optimizer/path/indxpath.c. ISTM that it's legitimate to conclude that "foo IS NOT NULL" is implied by "foo op anything" or "anything op foo" if the operator is marked strict. Note: please patch against CVS head, as that code got rewritten since 7.4. regards, tom lane