X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CACF2D1B220 for ; Sun, 20 Jun 2004 15:45:24 -0300 (ADT) 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 13592-03 for ; Sun, 20 Jun 2004 18:45:21 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 6CE2BD1B1D0 for ; Sun, 20 Jun 2004 15:45:19 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i5KIj65Z004120; Sun, 20 Jun 2004 14:45:06 -0400 (EDT) To: Stan Bielski Cc: pgsql-performance@postgresql.org Subject: Re: Indexing question In-reply-to: References: Comments: In-reply-to Stan Bielski message dated "Tue, 15 Jun 2004 17:29:59 -0400" Date: Sun, 20 Jun 2004 14:45:06 -0400 Message-ID: <4119.1087757106@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/210 X-Sequence-Number: 7268 Stan Bielski writes: > Table "public.allflow_tv_mydoom" > Column | Type | Modifiers > ------------+---------+----------- > tv_s | bigint | ^^^^^^ > Indexes: allflow_tv_mydoom_x btree (tv_s) > standb=# explain select * from allflow_tv_mydoom where tv_s < 1074200099 > and tv_s > 107506499; > [ gives seqscan ] This is a FAQ :-(. Unadorned integer constants are taken to be int4 not int8 (unless they are too large for int4), and cross-data-type comparisons are not indexable in existing releases. So you have to explicitly cast the comparison values to int8: explain select * from allflow_tv_mydoom where tv_s < 1074200099::bigint and tv_s > 107506499::bigint; (or use the standard CAST syntax if you prefer). 7.5 will have a fix for this ancient annoyance. BTW, is there a reason to be using tv_s+tv_us and not just a single timestamptz column? regards, tom lane