Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id A418963388F for ; Sun, 3 May 2009 05:22:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 92919-10 for ; Sun, 3 May 2009 05:22:44 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f174.google.com (mail-fx0-f174.google.com [209.85.220.174]) by mail.postgresql.org (Postfix) with ESMTP id 7FB946330BE for ; Sun, 3 May 2009 05:22:44 -0300 (ADT) Received: by fxm22 with SMTP id 22so3257294fxm.19 for ; Sun, 03 May 2009 01:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=G918hRENwoGHw8FzcILh9rQ4RlQvIQAu13dWgdnrbxM=; b=EvMZ3q9trckKeQuIB4IdIUpH9agEekbmxF7D37Kk72RrXqPoBf2LNewELXNG/g2TPt Zg1N2wFTi28Y/GaZ1gCelgfLZL696s8Biq9Q8UEgi8K8ArLJUuwe7NEykpayu06oYhqO 9z9a0Z67tQdBwdBE8azIJetdHt75EjmdeoBHA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=AFebJRK5S070dMCDJAHfWyqrQhQpUxtzx7YS0emq4W8CrMUsqxeCDSRFjUTpzZGOBc Jmy3Ny5y/9zvT/gswk2v9hlOsbc7yZaf0BCLUppv+ONTsMFYMZ0KoX5OKKRy6ds2loyD Q69XyshGPBQOj/ulKWCO+EKdxqUtoVdsmG+ek= MIME-Version: 1.0 Received: by 10.239.163.5 with SMTP id n5mr256046hbd.18.1241338962573; Sun, 03 May 2009 01:22:42 -0700 (PDT) In-Reply-To: <02437794-A78D-449C-843F-B823195F9623@noopsis.fr> References: <5C2E1645-73B6-4509-96CD-FA77869516AB@noopsis.fr> <49F71EDD.2070200@opencloud.com> <02437794-A78D-449C-843F-B823195F9623@noopsis.fr> Date: Sun, 3 May 2009 10:22:42 +0200 X-Google-Sender-Auth: 1cd8ed7204c20576 Message-ID: Subject: Re: Very strange performance decrease when reusing a PreparedStatement From: =?UTF-8?B?UMOpdGVyIEtvdsOhY3M=?= To: =?UTF-8?B?RnLDqWTDqXJpayBCaWxoYXV0?= Cc: Oliver Jowett , pgsql-jdbc@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200905/11 X-Sequence-Number: 19561 2009/4/29 Fr=C3=A9d=C3=A9rik Bilhaut : > Le 28 avr. 09 =C3=A0 17:21, Oliver Jowett a =C3=A9crit : >> >> Try with prepareThreshold=3D0. Probably, your particular query benefits >> from re-planning each time with the particular concrete parameter values >> for each execution. >> >> (you can either specify this as a URL parameter, or tweak it on a >> per-connection or per-statement basis via methods on >> PGConnection/PGStatement) > > > Thank you Oliver for this answer. > > Your hypothesis seems plausible to me, because we rely strongly on indexe= s > to improve performance, and it appears that the query duration of a reuse= d > satement is the that the same query without index. On the other hand, > "explain analyze" tells that the index is correctly used each time, but i= t > also reports a very short total time in any case, so who knows what > happens... > > Anyway, I will try the option you suggest asap (although re-creating > statements each time does not seem to be so harmful...). > > But there is maybe something somewhere in the driver (or pg iteself ?) th= at > may have to be fixed or at least documented ? Every JDBC optimisation > tutorial will mention the fact that preparing and reusing statements can > improve the performances of recurrent query, but my example proves that i= n > some situations, the performances can be dramatically worsen (around 20 > times slower in my case) ! > It appears that the Postgres "server-prepared statement" cannot handle parameters to the statement. This is really unfortunate, because 99% of real-life applications will want to re-use the same statement (template) with different parameters. The term "server-prepared statement" itself already indicates that there may be something skewed about the "local" semantics of java.sql.PreparedStatements in the Postgres JDBC driver. There is no notion of "client-prepared statement" in the JDBC API, which conceives PreparedStatement instances as mere handles to server side objects. And indeed, Postgres JDBC users have historically been using java.sql.PreparedStatements for its side-effect of preventing SQL injection rather than for the purpose the JDBC API designers had in mind with this class. Peter > > Best regards, > -- > Fr=C3=A9d=C3=A9rik Bilhaut > NOOPSIS > > > > > > > > > > > > -- > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-jdbc >