X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0DC4F475EE2 for ; Sun, 20 Apr 2003 01:40:33 -0400 (EDT) Received: from minos.iwerx.gr (unknown [194.158.4.35]) by postgresql.org (Postfix) with ESMTP id 0047B4758C9 for ; Sun, 20 Apr 2003 01:40:31 -0400 (EDT) Received: from pobox.gr (minos.iwerx.gr [194.158.4.35]) by minos.iwerx.gr (8.12.8/8.12.8) with ESMTP id h3K6bb35031663 for ; Sun, 20 Apr 2003 08:37:37 +0200 Message-ID: <3EA231D2.2040305@pobox.gr> Date: Sun, 20 Apr 2003 07:36:18 +0200 From: kp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Sequence scans on indexed row Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-12.9 required=5.0 tests=BAYES_01,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/280 X-Sequence-Number: 8435 Hello all. I am doing a straight forward update on a table with over 1.6 million records based on a where clause that only uses one of its indexed columns (btree on a varchar). However postgres instists on not using the index and instead does a sequence scan that takes ages to complete. The weird thing is that the same table has another column indexed in exactly the same way (btree on a varchar) which postgres correctly uses the index on. One difference between the two columns is that on one I have fixed the maximum size of the varchar to 80 while the other is free to grow as much as it wants. The other difference between these two columns (or rather the kind of data they contain) is that the column for which postgres *uses* the index on contains around 32000 distinct values while the other only contains 14 distinct values. I have a suspicion that postgres (i'm using 7.1.3) incorrectly assumes that a sequence scan is cheaper for the column with the 14 distinct values in it and ends up scanning 1.6 million rows. Bug? If so, has it been fixed on later versions? TIA for any replies, kp