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 E4055329E67 for ; Mon, 20 Sep 2004 01:51:46 +0100 (BST) 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 32298-09 for ; Mon, 20 Sep 2004 00:51:39 +0000 (GMT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by svr1.postgresql.org (Postfix) with ESMTP id 95EED329CD2 for ; Mon, 20 Sep 2004 01:51:41 +0100 (BST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1C9CP1-00088S-00; Sun, 19 Sep 2004 20:51:35 -0400 To: Tom Lane Cc: mailreg@numerixtechnology.de, Greg Stark , pgsql-sql@postgresql.org Subject: Re: ORDER BY and NULLs References: <011d01c49e5b$c88fdb20$2766f30a@development.greatgulfhomes.com> <414DB1AB.5080207@sympatico.ca> <414DB594.5000300@numerixtechnology.de> <19733.1095613137@sss.pgh.pa.us> <414DBF6D.8040500@numerixtechnology.de> <87zn3mjeaw.fsf@stark.xeocode.com> <414DEA7F.6050100@numerixtechnology.de> <21812.1095625829@sss.pgh.pa.us> In-Reply-To: <21812.1095625829@sss.pgh.pa.us> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 19 Sep 2004 20:51:35 -0400 Message-ID: <874qltkbjc.fsf@stark.xeocode.com> Lines: 30 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.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/146 X-Sequence-Number: 18992 Tom Lane writes: > > The paragraph continues: > > "If the SELECT command included the clause WHERE phone NOT NULL, > > PostgreSQL could use the index to satisfy the ORDER BY clause. > > An index that covers optional (NOT NULL) columns will not be used to > > speed table joins either." > > My goodness, it seems to be a veritable fount of misinformation :-( > > I wonder how much of this is stuff that is true for Oracle and they just > assumed it carried over? The first part is true for Oracle. You have to add the WHERE phone NOT NULL to convince Oracle it can use an index. Or just make the column NOT NULL to begin with I think. However as far as I recall the second part is not true. Oracle is smart enough to realize that an equijoin clause implies NOT NULL and therefore allows it to use the index. (This may have all changed in Oracle 9+. The last I saw of Oracle was 8i) I wonder if they just tried explain on a bunch of queries and noticed that postgres wasn't using an index for SELECT * FROM foo ORDER BY bar and came up with explanations for the patterns they saw? -- greg