X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 1E71FD1B56F for ; Wed, 29 Oct 2003 19:08:52 +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 77965-09 for ; Wed, 29 Oct 2003 15:08:22 -0400 (AST) Received: from proteus.affordablehost.com (proteus.affordablehost.com [216.46.203.177]) by svr1.postgresql.org (Postfix) with ESMTP id DB2FAD1B53F for ; Wed, 29 Oct 2003 15:08:20 -0400 (AST) Received: from [66.92.67.95] (helo=e-greek.net) by proteus.affordablehost.com with esmtp (Exim 4.20) id 1AEvfo-0000Jc-Ga for pgsql-admin@postgresql.org; Wed, 29 Oct 2003 14:08:04 -0500 Message-ID: <3FA01013.1090105@e-greek.net> Date: Wed, 29 Oct 2003 14:08:03 -0500 From: Andrew Biagioni User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Matching indexes on int8 columns? 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: 200310/359 X-Sequence-Number: 10920 I'm running 7.3, and I recently observed something rather disconcerting, using EXPLAIN ANALYZE. If I have an index on an int8 column, and I run a query such as SELECT * FROM [tablename] WHERE [colname] = 12345 the index is NOT used, and a sequential scan of the 200K rows is done, taking ~ 17500 msec.; if I change the query to be: SELECT * FROM [tablename] WHERE [colname] = '12345' or SELECT * FROM [tablename] WHERE [colname] = 12345::int8 then the index is used and a btree index scan is performed taking ~24 msec. I found these workarounds in a Sept. 2001 thread, leading me to believe that it's nothing new; however, there is nothing in the docs. that I could find (including the Momjian book), that has any reference to this problem. My conclusion (assumption?) is that index-to-WHERE matching relies on some strict kind of type matching, without any attempt at type conversion between int4 and int8; but if a type conversion is forced (e.g., by quoting the number), then the conversion is done before the matching and all goes well. So finally, my question. Why is this behavior present? Is it actually a feature that I don't know enough to appreciate? Inquiring minds want to know... Thanks, Andrew Biagioni