Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id C0BA92E00FD for ; Mon, 28 Jan 2008 16:51:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 11997-06 for ; Mon, 28 Jan 2008 16:51:51 -0400 (AST) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 51F8E2E0182 for ; Mon, 28 Jan 2008 16:51:54 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m0SKprfP006916; Mon, 28 Jan 2008 15:51:53 -0500 (EST) To: Claire McLister cc: pgsql-performance@postgresql.org Subject: Re: JDBC/Stored procedure performance issue In-reply-to: <018573B2-DC52-4B98-9AB6-1ACB953B0035@zeesource.net> References: <018573B2-DC52-4B98-9AB6-1ACB953B0035@zeesource.net> Comments: In-reply-to Claire McLister message dated "Mon, 28 Jan 2008 09:59:07 -0800" Date: Mon, 28 Jan 2008 15:51:53 -0500 Message-ID: <6915.1201553513@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/277 X-Sequence-Number: 28516 Claire McLister writes: > When I do an EXPLAIN ANALYZE on one query that returns 3261 rows, it > executes in a reasonable 159ms: > ... > If I issue the same query over JDBC or use a PSQL stored procedure, it > takes over 3000 ms, which, of course is unacceptable! I suspect that the problem is with "groupid = $1" instead of "groupid = 57925". The planner is probably avoiding an indexscan in the parameterized case because it's guessing the actual value will match so many rows as to make a seqscan faster. Is the distribution of groupid highly skewed? You might get better results if you increase the statistics target for that column. Switching to something newer than 7.4.x might help too. 8.1 and up support "bitmap" indexscans which work much better for large numbers of hits, and correspondingly the planner will use one in cases where it wouldn't use a plain indexscan. regards, tom lane