X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 252A7DB5B3 for ; Mon, 31 Oct 2005 17:03:55 -0400 (AST) 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 28160-02 for ; Mon, 31 Oct 2005 21:03:52 +0000 (GMT) Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by svr1.postgresql.org (Postfix) with ESMTP id 515D8DB5B1 for ; Mon, 31 Oct 2005 17:03:53 -0400 (AST) Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP with MS-WebStorage 6.5.6944 Received: from state.g2switchworks.com by mail.g2switchworks.com; 31 Oct 2005 15:03:53 -0600 Subject: Re: 8.x index insert performance From: Scott Marlowe To: Merlin Moncure Cc: Kelly Burkhart , pgsql-performance@postgresql.org In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD72D@Herge.rcsinc.local> References: <6EE64EF3AB31D5448D0007DD34EEB3417DD72D@Herge.rcsinc.local> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1130792605.15018.21.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Mon, 31 Oct 2005 15:03:53 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.008 required=5 tests=[AWL=0.007, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.008 X-Spam-Level: X-Archive-Number: 200510/482 X-Sequence-Number: 15250 On Mon, 2005-10-31 at 13:13, Merlin Moncure wrote: > > > if that index is causing the problem, you may want to consider > setting > > > up partial index to exclude null values. > > > > This is a single column index. I assumed that null column values were > > not indexed. Is my assumption incorrect? > > > > -K > It turns out it is, or it certainly seems to be. I didn't know that :). > So partial index will probably not help for null exclusion... > > would be interesting to see if you are getting swaps (check pg_tmp) when > performance breaks down. That is an easy fix, bump work_mem. OK, here's the issue in a nutshell. NULLS, like everything else, are indexed. HOWEVER, there's no way for them to be used by a normal query, since =NULL is not a legal construct. So, you can't do something like: select * from sometable where somefield = NULL because you won't get any answers, since nothing can equal NULL and select * from sometable where somefield IS NULL won't work because IS is not a nomally indexible operator. Which is why you can create two indexes on a table to get around this like so: create index iname1 on table (field) where field IS NULL and create index iname2 on table (field) where field IS NOT NULL And then the nulls are indexable by IS / IS NOT NULL.