Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 47D2A2E4522 for ; Thu, 13 Dec 2007 19:27:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 56492-06 for ; Thu, 13 Dec 2007 19:27:02 -0400 (AST) Received: from mail.capital-internet.net (mail.capital-internet.net [216.136.66.10]) by postgresql.org (Postfix) with ESMTP id 2AE0F2E44A0 for ; Thu, 13 Dec 2007 19:27:08 -0400 (AST) Received: from [192.168.1.37] (unknown [66.195.146.163]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.capital-internet.net (Postfix) with ESMTP id 28D1419F5B2F for ; Thu, 13 Dec 2007 17:26:59 -0600 (CST) Message-Id: <62EFD840-6C75-4220-9CC3-77D35C76403F@techbydesign.com> From: Tom Duffey To: pgsql-jdbc@postgresql.org In-Reply-To: <4761BACA.4020008@opencloud.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v915) Subject: Re: Slow query after upgrades Date: Thu, 13 Dec 2007 17:27:06 -0600 References: <3EB52707-C945-43D6-9B3F-15F3B228D6F6@techbydesign.com> <4761A221.80604@opencloud.com> <1d4e0c10712131358m4bbc3f57t7e33c6c8ad2b3710@mail.gmail.com> <435EC9B4-F3DD-4136-9070-93E0DBB94B3F@techbydesign.com> <1d4e0c10712131452l65841793r449eb3c7cffbf3a5@mail.gmail.com> <0116C2A9-8DB5-4EBE-A66B-BE7F2A11651C@techbydesign.com> <4761BACA.4020008@opencloud.com> X-Mailer: Apple Mail (2.915) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/102 X-Sequence-Number: 17957 On Dec 13, 2007, at 5:05 PM, Oliver Jowett wrote: > Tom Duffey wrote: > >> This makes a huge difference, thanks. However, is there anything I >> can do to help improve the performance of that query when using a >> newer protocol? > > We need to work out what is going wrong under the newer protocol > first, which unfortunately can be a bit tricky because psql doesn't > use the query protocol in the same way as the JDBC driver. > > Can you write a little JDBC app that runs the query with EXPLAIN > ANALYZE, setting parameters in the same way that your real app does, > and dump out the resultset it gets back? (which should be the > EXPLAIN results rather than the real data, IIRC) QUERY PLAN=Sort (cost=289075.73..289147.11 rows=28554 width=20) (actual time=141222.112..141222.294 rows=192 loops=1) QUERY PLAN= Sort Key: "timestamp" QUERY PLAN= -> Bitmap Heap Scan on point_history (cost=1847.73..286962.53 rows=28554 width=20) (actual time=140998.758..141221.691 rows=192 loops=1) QUERY PLAN= Recheck Cond: (point_id = 21001) QUERY PLAN= Filter: (("timestamp")::text >= '2007-12-11 23:20:57'::text) QUERY PLAN= -> Bitmap Index Scan on point_history_pkey (cost=0.00..1840.59 rows=85663 width=0) (actual time=122.393..122.393 rows=65262 loops=1) QUERY PLAN= Index Cond: (point_id = 21001) QUERY PLAN=Total runtime: 141222.791 ms Cool, this makes it look like the problem is that the "timestamp" parameter as a string instead of a timestamp. What do you think? Tom