X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5BD7E3A44F7 for ; Thu, 25 Nov 2004 23:40:27 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81135-08 for ; Thu, 25 Nov 2004 23:40:15 +0000 (GMT) Received: from cougar.DIT.UMontreal.CA (chene.DIT.UMontreal.CA [132.204.246.20]) by svr1.postgresql.org (Postfix) with ESMTP id 977DC3A480D for ; Thu, 25 Nov 2004 23:40:12 +0000 (GMT) Received: from chene.dit.umontreal.ca(132.204.246.20) by cougar.DIT.UMontreal.CA via csmap id 5a6a03b0_3f3b_11d9_81bc_0002b39fa8dc_21308; Thu, 25 Nov 2004 18:40:18 -0500 (EST) Received: from cougar.DIT.UMontreal.CA (gw-mail.LEXUM.UMontreal.CA [132.204.136.52]) by chene.DIT.UMontreal.CA (8.13.1/8.13.1) with ESMTP id iAPNeAVj006201 for ; Thu, 25 Nov 2004 18:40:10 -0500 Received: from gw-mail.lexum.umontreal.ca(132.204.136.52) by cougar.DIT.UMontreal.CA via csmap id 588c7d0c_3f3b_11d9_808b_0002b39fa8dc_21199; Thu, 25 Nov 2004 18:40:10 -0500 (EST) Received: from [192.168.1.101] ([::ffff:70.80.14.117]) (AUTH: PLAIN paree, SSL: TLSv1/SSLv3,256bits,AES256-SHA) by mail.lexum.umontreal.ca with esmtp; Thu, 25 Nov 2004 18:38:21 -0500 id 00000089.41A66CED.00007CE6 Subject: using index with bigint pkey From: "=?ISO-8859-1?Q?=C9ric_Par=E9?=" Reply-To: paree@LEXUM.UMontreal.CA To: pgsql-jdbc@postgresql.org Organization: LexUM Message-Id: <1101425976.3726.56.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 25 Nov 2004 18:39:36 -0500 X-Mime-Autoconverted: from 8bit to quoted-printable by courier 0.47 X-NAI-Spam-Score: 0.0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/208 X-Sequence-Number: 11630 Problem (I think) : planner usage of an index that is based on a bigint field through jdbc ? 1) Planner perspective, in psql for example I found that running a simple query on a bigint index does not behave as expected in the planner. This query does not use the index on 'a pkey id column' if it is of bigint type : create table test ( id bigint primary key, field text not null ); This will never use the index, whatever size of table, and is independant of calling analyze. explain select * from test where id =3D 123; Solution: cast explain select * from test where id =3D 123::bigint; explain select * from test where id =3D '123'; This is the way the planner behaves, as far as shown by 'explain'. I don't really like this example since I wouldn't expect the planner to use an index on an empty table. It just serves the purpose. 2) Jdbc perspective The setLong javadoc for PreparedStatement states that it prepares the query sending the equivalent of the postgresql bigint parameter. When I look at query activities in pg_stat_activity to feel the behavior of database usage of my Java program, it shows that a query is ran without casting ::bigint or 'string'. Since the table is growing big, I see that the queries aren't using the index on my bigint key (slow queries). I'd guess this is a postgresql bug, not a jdbc bug, right ? Or is this a feature ? Patch solution with postgersql-jdbc : I replaced setLong with setString(myLong.toString()) which casts to a quoted string representation and uses the index. Works for me. Note on setup : - postgresql 7.4.1 server - postgresql-7.4.1-jdbc3.jar -- =C9ric Par=E9 for/pour LexUM Universit=E9 de Montr=E9al Centre de recherche en droit public C.P. 6128, succ. Centre-ville Montr=E9al (Qc) Canada H3C 3J7 +1 514-343-6111 #0873 paree@lexum.umontreal.ca