From: Adrian Klaver <adrian.klaver@gmail.com>
To: Clemens Eisserer <linuxhippy@gmail.com>
To: pgsql-general@postgresql.org
To: pgsql-jdbc@postgresql.org
Subject: Re: Creating an index alters the results returned
Date: Fri, 03 Jan 2014 16:55:03 -0800
Message-ID: <52C75BE7.3060601@gmail.com> (raw)
In-Reply-To: <CAFvQSYSLkN5D4Up=0wyQDRfJr2vvQZeWa=BaZeSJaUf1heiUgg@mail.gmail.com>
References: <CAFvQSYSLkN5D4Up=0wyQDRfJr2vvQZeWa=BaZeSJaUf1heiUgg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>
On 01/03/2014 11:59 AM, Clemens Eisserer wrote:
> Hi,
>
> Running postgres 9.1.11 + postgresql-9.3-1100.jdbc41.jar, I experience
> a strange phenomenon using indexes.
>
> I have the following schema:
> CREATE TABLE wplog (id serial NOT NULL,ts timestamp without time zone,
> sensor1 real, sensor2 real, noiselevel smallint, CONSTRAINT wplog_pkey
> PRIMARY KEY (id))
>
> and execute the following query on it:
>
> SELECT sensor1, sensor2, EXTRACT(EPOCH from ts) AS epoche FROM wplog
> WHERE EXTRACT(EPOCH from ts) BETWEEN 1388712180::double precision AND
> 1388780572::double precision ORDER BY id
>
> However, the results differ, depending on whether I've created an
> index on ts or not:
>
> With index:
> ResultSet Size: 6651
> minTS: 1388730187145 maxTs: 1388796688388 txdiff: 66501243
>
> Without index:
> ResultSet Size: 6830
> minTS: 1388712182800 maxTs: 1388780567963 txdiff: 68385163
>
> The index looks like: CREATE INDEX ON wplog (CAST(EXTRACT(EPOCH from
> ts) AS double precision))
>
> Even more puzzling to me is the fact, that I can only observe this
> difference when using the JDBC driver,
> using pgadmin to execute the query I get consistent results.
>
> Is this behaviour expected?
Only thing I can think of is the JDBC driver and Postgres have a
difference of opinion on the precision of double precision. What happens
if you eliminate the double precision cast?
Another thought, what is the storage type for timestamps in this
cluster? The default should be 8 byte integer, but floating point is
also a possibility. To find out do:
pg_controldata PGDATA
and look for:
Date/time type storage: 64-bit integers
>
> Thank you in advance, Clemens
>
>
--
Adrian Klaver
adrian.klaver@gmail.com
--
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-jdbc@postgresql.org
Cc: adrian.klaver@gmail.com, linuxhippy@gmail.com, pgsql-general@postgresql.org
Subject: Re: Creating an index alters the results returned
In-Reply-To: <52C75BE7.3060601@gmail.com>
References: <CAFvQSYSLkN5D4Up=0wyQDRfJr2vvQZeWa=BaZeSJaUf1heiUgg@mail.gmail.com> <52C75BE7.3060601@gmail.com>
* 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