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 291F1D1B4E6 for ; Fri, 24 Oct 2003 12:53:46 +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 86648-01 for ; Fri, 24 Oct 2003 09:53:18 -0300 (ADT) Received: from proteus.affordablehost.com (proteus.affordablehost.com [216.46.203.177]) by svr1.postgresql.org (Postfix) with ESMTP id 39C76D1B515 for ; Fri, 24 Oct 2003 09:53:09 -0300 (ADT) Received: from [66.31.57.228] (helo=Laptop) by proteus.affordablehost.com with smtp (Exim 4.20) id 1AD1R4-0007Dq-R8; Fri, 24 Oct 2003 08:52:58 -0400 From: Andrew Biagioni To: pgsql-admin@postgresql.org Date: Fri, 24 Oct 2003 08:52:57 -0400 X-Priority: 3 (Normal) Organization: E-Greek, llc Message-Id: Subject: Matching indexes on int8 columns MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" X-Mailer: Opera 6.05 build 1140 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/293 X-Sequence-Number: 10854 I'm running 7.3, and I recently found out something rather disconcerting: 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 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 id performed taking ~24 msec. I found this workaround in a 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 is that index-to-WHERE matching relies on some strict kind of type matching, without any attempt at type conversion between int4 and int8. 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