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 769C6329C7B for ; Sun, 19 Sep 2004 21:22:45 +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 96615-09 for ; Sun, 19 Sep 2004 20:22:40 +0000 (GMT) Received: from msgdirector3.onetel.net.uk (msgdirector3.onetel.net.uk [212.67.96.159]) by svr1.postgresql.org (Postfix) with ESMTP id 81368329E80 for ; Sun, 19 Sep 2004 21:22:40 +0100 (BST) Received: from bolek.coachhouse (213-78-127-222.friaco.onetel.net.uk [213.78.127.222] (may be forged)) by msgdirector3.onetel.net.uk (MOS 3.4.6-GR) with ESMTP id CSL02274; Sun, 19 Sep 2004 21:22:30 +0100 (BST) Received: (Exim 3.36) #1 (Debian)) protocol: esmtp id 1C98CV-00059t-00 ; Sun, 19 Sep 2004 21:22:23 +0100 Message-ID: <414DEA7F.6050100@numerixtechnology.de> Date: Sun, 19 Sep 2004 21:22:23 +0100 From: T E Schmitz Reply-To: mailreg@numerixtechnology.de User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Greg Stark Cc: Tom Lane , 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> In-Reply-To: <87zn3mjeaw.fsf@stark.xeocode.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit 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/139 X-Sequence-Number: 18985 Hello Greg, Greg Stark wrote: > T E Schmitz writes: > >>Quote: "PostgreSQL will not index NULL values. Because an index will never >>include NULL values, it cannot be used to satisfy the ORDER BY clause of a >>query that returns all rows in a table." > > > You should just cross out that whole section. It's just flatly wrong. > I had always assumed it was just people bringing assumptions over from Oracle > where it is true. Perhaps this book is to blame for some of the confusion. > Which book is it? PostgreSQL by Korry Douglas + Susan Douglas, ISBN 0-7357-1257-3; Feb 2003 > Postgres indexes NULLs. It can use them for ORDER BY clauses. > > Where it cannot use them is to satisfy "WHERE foo IS NULL" or "WHERE foo IS > NOT NULL" constraints though. That's an implementation detail, but it can be > worked around with partial indexes. 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." -- Regards/Gruß, Tarlika Elisabeth Schmitz