X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7CD923A66B7; Sat, 11 Dec 2004 03:24:02 +0000 (GMT) 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 93703-01; Sat, 11 Dec 2004 03:23:26 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id B472E3A9BEF; Sat, 11 Dec 2004 02:28:38 +0000 (GMT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id C49D135834; Fri, 10 Dec 2004 18:28:38 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id C2FC83582F; Fri, 10 Dec 2004 18:28:38 -0800 (PST) Date: Fri, 10 Dec 2004 18:28:38 -0800 (PST) From: Stephan Szabo To: Tomas =?iso-8859-1?q?Sk=E4re?= Cc: pgsql-general@postgresql.org, pgsql-performance@postgresql.org Subject: Re: Query is not using index when it should In-Reply-To: <80oeh2tm7x.fsf@junk.nocrew.org> Message-ID: <20041210182453.G92467@megazone.bigpanda.com> References: <80oeh2tm7x.fsf@junk.nocrew.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: QUOTED-PRINTABLE X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.011 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200412/510 X-Sequence-Number: 70122 On Fri, 10 Dec 2004, Tomas [iso-8859-1] Sk=E4re wrote: > I have a table that looks like this: > > Table "public.cjm_object" > Column | Type | Modifiers > -----------+-------------------+----------- > timestamp | bigint | not null > jobid | bigint | not null > objectid | bigint | not null > class | integer | not null > field | character varying | not null In 7.4.x and earlier, you need to cast the value you're comparing to into a bigint in order to make sure the indexes are used (in your timestamp case it appears to work because the value doesn't fit in a plain integer). 8.0 should handle this better. > But when doing a search with objectid, class and field, it doesn't use > the idx_cjm_object1 index. > db=3D# explain analyze select * from cjm_object where objectid=3D4534 and= class=3D12 and field=3D'paroid'; Using one of objectid=3D4534::bigint objectid=3D'4534' objectid=3DCAST(4534 as bigint) rather than objectid=3D4534 should make this indexable in 7.4.x.