Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gTs1Q-0002qg-Pt for pgsql-general@arkaria.postgresql.org; Mon, 03 Dec 2018 17:28:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gTs1P-0004Z5-7f for pgsql-general@arkaria.postgresql.org; Mon, 03 Dec 2018 17:28:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gTs1O-0004Yg-Se for pgsql-general@lists.postgresql.org; Mon, 03 Dec 2018 17:28:39 +0000 Received: from mail.flexidesk.de ([148.251.127.103]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gTs1L-0005jg-8P for pgsql-general@lists.postgresql.org; Mon, 03 Dec 2018 17:28:37 +0000 Received: from [2003:c2:6f0f:b400:256e:3ed9:711a:4e1d] (helo=titanium) by mail.flexidesk.de with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2 #2 (Debian)) id 1gTs1I-00069t-6B; Mon, 03 Dec 2018 18:28:32 +0100 Date: Mon, 3 Dec 2018 18:28:31 +0100 From: Jan Behrens To: Tom Lane Cc: pgsql-general@lists.postgresql.org Subject: Re: GiST index on INT8, possible bug in query planner? Message-Id: <20181203182831.186d562e6b2b35e085e9ef21@public-software-group.org> In-Reply-To: <31226.1543855637@sss.pgh.pa.us> References: <20181203170904.3bebd803bd71f4a24a3e1061@public-software-group.org> <31226.1543855637@sss.pgh.pa.us> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; amd64-portbld-freebsd11.1) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 03 Dec 2018 11:47:17 -0500 Tom Lane wrote: > Jan Behrens writes: > > > However, the GiST index seems not to work as expected by me when > > 64-bit integers are involved. I tried to create a minimal > > proof-of-concept to demonstrate this. Consider the following setup: > > > > CREATE TABLE test8_gist (id SERIAL4, ctx INT8); > > CREATE INDEX ON test8_gist USING gist (ctx, id); > > EXPLAIN SELECT * FROM test8_gist WHERE ctx = 1 AND id = 2; > > -- uses Index Cond: (id = 2) > > > > The query planning for the select on table "test8_gist" does not > > include "ctx" in the "Index Cond". > > Probably it would if you'd written "WHERE ctx = 1::int8". Without > the cast, what you'll have is "int8 = int4", and I suspect that > btree_gist doesn't include cross-type operators in its opclasses. > > regards, tom lane You are right! I just tested it and ::int8 does the job. It might be good to add a short notice or warning in the documentation at: https://www.postgresql.org/docs/current/btree-gist.html It might help other people who run into the same problem. Thanks for helping me, Jan Behrens -- Public Software Group e. V. Johannisstr. 12, 10117 Berlin, Germany www.public-software-group.org vorstand@public-software-group.org eingetragen in das Vereinregister des Amtsgerichtes Charlottenburg Registernummer: VR 28873 B Vorstände (einzelvertretungsberechtigt): Jan Behrens Axel Kistner Andreas Nitsche Björn Swierczek