X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 70FA45281A for ; Tue, 31 May 2005 01:21:43 -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 43602-02 for ; Tue, 31 May 2005 04:21:39 +0000 (GMT) Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by svr1.postgresql.org (Postfix) with ESMTP id 2569E5280A for ; Tue, 31 May 2005 01:21:38 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1DcyFp-0000u1-00; Tue, 31 May 2005 00:21:25 -0400 To: Tobias Brox Cc: Bruno Wolff III , pgsql-performance@postgresql.org Subject: Re: Index on a NULL-value References: <20050531030207.GD26100@tobias.exoweb.net> <20050531032119.GH26100@tobias.exoweb.net> <20050531033633.GA20015@wolff.to> <20050531034529.GJ26100@tobias.exoweb.net> In-Reply-To: <20050531034529.GJ26100@tobias.exoweb.net> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 31 May 2005 00:21:25 -0400 Message-ID: <87mzqcvxdm.fsf@stark.xeocode.com> Lines: 33 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/462 X-Sequence-Number: 12626 Tobias Brox writes: > [Bruno Wolff III - Mon at 10:36:33PM -0500] > > You want something like this: > > CREATE INDEX b_is_null ON mock(b) WHERE b IS NULL; > > Oh, cool. I wasn't aware that this is possible. This would probably help > us a lot of places. :-) Yeah it's a cool feature. I'm not 100% sure but I think it still won't consider this index unless the column being indexed is used in some indexable operation. So for example if you had CREATE INDEX b_null on mock(other) WHERE b IS NULL; and something like SELECT * FROM b WHERE b IS NULL ORDER BY other or SELECT * FROM b where other > 0 AND b IS NULL then it would be a candidate because the ORDER BY or the other > 0 make the index look relevant. But I don't think (again I'm not 100% sure) that the partial index WHERE clause is considered in picking which indexes to consider. It *is* considered in evaluating which index is the best one to use and whether it's better than a sequential scan. Just not in the initial choice of which indexes to look at at all. -- greg