Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 255C1B5DBE7 for ; Tue, 5 Jul 2011 20:43:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 88243-06 for ; Tue, 5 Jul 2011 23:43:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 87C25B5DBDC for ; Tue, 5 Jul 2011 20:43:50 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p65Nhoo9055168 for ; Tue, 5 Jul 2011 23:43:50 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p65NhoKD055167; Tue, 5 Jul 2011 23:43:50 GMT (envelope-from www) Date: Tue, 5 Jul 2011 23:43:50 GMT Message-Id: <201107052343.p65NhoKD055167@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6092: specific casting required for gist indexing of bigint From: "Jeff Frost" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201107/42 X-Sequence-Number: 30654 The following bug has been logged online: Bug reference: 6092 Logged by: Jeff Frost Email address: jeff@pgexperts.com PostgreSQL version: 9.0.4 Operating system: CentOS 5.5 Description: specific casting required for gist indexing of bigint Details: Ran into a situation with a customer who is using the btree_gist contrib module to allow combined index of some tsearch data and two other columns. One of these other columns is a bigint field. I noticed that the combined index won't be used by the planner unless you specifically cast the bare number to a bigint. Here's a quick test case: createdb jefftest psql -f /usr/pgsql-9.0/share/contrib/btree_gist.sql jefftest jefftest=# create table test (id bigint); CREATE TABLE Time: 28.541 ms jefftest=# insert into test select generate_series(1,100000); INSERT 0 100000 Time: 179.768 ms jefftest=# CREATE INDEX test__id ON test using gist(id) ; CREATE INDEX Time: 1603.811 ms jefftest=# ANALYZE test; ANALYZE Time: 21.854 ms jefftest=# explain analyze select id from test WHERE id = 587; QUERY PLAN ---------------------------------------------------------------------------- ------------------------ Seq Scan on test (cost=0.00..1693.00 rows=500 width=8) (actual time=0.097..14.698 rows=1 loops=1) Filter: (id = 587) Total runtime: 14.739 ms (3 rows) Time: 32.965 ms jefftest=# explain analyze select id from test WHERE id = 587::bigint; QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------- Bitmap Heap Scan on test (cost=20.16..490.49 rows=500 width=8) (actual time=0.037..0.038 rows=1 loops=1) Recheck Cond: (id = 587::bigint) -> Bitmap Index Scan on test__id (cost=0.00..20.03 rows=500 width=0) (actual time=0.027..0.027 rows=1 loops=1) Index Cond: (id = 587::bigint) Total runtime: 0.080 ms (5 rows) Time: 0.592 ms