From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dingyuan Wang <gumblex@aosc.io>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Index not used when using expression
Date: Thu, 09 Nov 2017 11:33:54 -0500
Message-ID: <24936.1510245234@sss.pgh.pa.us> (raw)
In-Reply-To: <42dbce76-9986-f9a0-e29d-12013e1b8b8e@aosc.io>
References: <42dbce76-9986-f9a0-e29d-12013e1b8b8e@aosc.io>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>
Dingyuan Wang <gumblex@aosc.io> writes:
> I have a table named "gps", with an indexed column "packettime", which
> has unix timestamps.
> The following query:
> select * from gps where packettime < extract(epoch from '2017-05-01
> 08:00+08'::timestamp with time zone)
> explains to:
> Seq Scan on gps (cost=0.00..43411860.64 rows=384325803 width=120)
> Filter: ((packettime)::double precision < date_part('epoch'::text,
> '2017-05-01 08:00:00+08'::timestamp with time zone))
The reason that's not working for you is that the query is not testing
packettime, it's testing packettime::float8, because date_part() returns
float8. You could cast the result of date_part() to bigint, or whatever
type the packettime column actually is, so that the comparison is to
the unadorned variable.
regards, tom lane
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, gumblex@aosc.io
Subject: Re: Index not used when using expression
In-Reply-To: <24936.1510245234@sss.pgh.pa.us>
References: <42dbce76-9986-f9a0-e29d-12013e1b8b8e@aosc.io> <24936.1510245234@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox