X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id D4E78D1B4BD for ; Sun, 4 Jan 2004 04:33:33 +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 31429-09 for ; Sun, 4 Jan 2004 00:32:45 -0400 (AST) Received: from relay01.kbs.net.au (relay01.kbs.net.au [203.220.32.149]) by svr1.postgresql.org (Postfix) with ESMTP id 2F4EED1B4AE for ; Sun, 4 Jan 2004 00:32:44 -0400 (AST) Received: from [203.221.247.184] (helo=familyhealth.com.au) by relay01.kbs.net.au with esmtp (Exim 3.36 #2) id 1AczwP-0008AO-00; Sun, 04 Jan 2004 15:32:41 +1100 Message-ID: <3FF79764.6060805@familyhealth.com.au> Date: Sun, 04 Jan 2004 12:32:36 +0800 From: Christopher Kings-Lynne User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "D. Dante Lorenso" Cc: pgsql-performance@postgresql.org Subject: Re: Indexing a Boolean or Null column? References: <3FF769EA.7090508@lorenso.com> In-Reply-To: <3FF769EA.7090508@lorenso.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/18 X-Sequence-Number: 5193 > Will an index on the 'data_is_active' column be used or work > as I expect? I'm assuming that I may have a million entries > sharing the same 'data_lookup_key' and I'll be using that to > search for the active version of the row. An index just on a boolean column won't be 'selective enough'. eg. The index will only be able to choose 50% of the table - since it's faster to do a full table scan in that case, the index won't get used. A multi keyed index, however will work a bit better, eg an index over (data_lookup_key, data_is_active). That way, the index will first be able to find the correct key (which is nicely selective) and then will be able to halve the resulting search space to get the active ones. BTW, you shouldn't use 'banana', 'pear', etc as the data_lookup_key, you should make another table like this: id name 1 banana 2 apple 3 pear And then replace the data_lookup_key col with a column of integers that is a foreign key to the names table - waaaaay faster to process. Chris