Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VzFWJ-0003WS-G7 for pgsql-general@arkaria.postgresql.org; Sat, 04 Jan 2014 00:55:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VzFWI-0001za-Vc for pgsql-general@arkaria.postgresql.org; Sat, 04 Jan 2014 00:55:19 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VzFWG-0001yx-Ck; Sat, 04 Jan 2014 00:55:16 +0000 Received: from mail-pa0-x22f.google.com ([2607:f8b0:400e:c03::22f]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VzFW8-0002zb-Ji; Sat, 04 Jan 2014 00:55:15 +0000 Received: by mail-pa0-f47.google.com with SMTP id kq14so16246420pab.6 for ; Fri, 03 Jan 2014 16:55:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=0X0K8PHQHEa1V2uVHNamCxWDEp0BrVIMU4fWYfbSnjQ=; b=kJsnTebifgmPC/1lib0DKsXrIaMO+4IUdKToxYGoSQ8eZ2g9FqFCPnm9v86PNiLWR8 UgjtUG8e/uU0RMrEooRYjnsyO6GCXk1N3ja3IIiEQhcmwSQtmYMyGY8DpGfxYSUvSkzj ELjQEghgmCP6lurjVWxwcHSGYS9sx2nj6Iu//OVpudmH1/5e/c49XFIC88PsxGR/kpIc 8rVcHCmCT0zlU89qd4N96jX5UQ6v6sORYH75Dp6vo5J9X+s8/wXNi1yxpnbAzlR1XUFB H2hohAudqHKmPp6VVuXD6QNHXosaKmU6a0R5GSTbxGu0UHCRHCIGXnp+xzCIQ1gINien UBrw== X-Received: by 10.68.92.98 with SMTP id cl2mr98707382pbb.81.1388796905910; Fri, 03 Jan 2014 16:55:05 -0800 (PST) Received: from panda.site (174-21-132-251.tukw.qwest.net. [174.21.132.251]) by mx.google.com with ESMTPSA id nl7sm111611119pbc.6.2014.01.03.16.55.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 03 Jan 2014 16:55:05 -0800 (PST) Message-ID: <52C75BE7.3060601@gmail.com> Date: Fri, 03 Jan 2014 16:55:03 -0800 From: Adrian Klaver User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Clemens Eisserer , pgsql-general@postgresql.org, pgsql-jdbc@postgresql.org Subject: Re: Creating an index alters the results returned References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org 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