From: Xavier Poinsard <xpoinsard@free.fr>
To: pgsql-jdbc@postgresql.org
Subject: Re: Need a performance tip - Statement pooling for server
Date: Tue, 30 Nov 2004 17:56:35 +0100
Message-ID: <coi8o0$ejo$1@floppy.pyrenet.fr> (raw)
In-Reply-To: <FB0608BA1956244694E2B71BF8B8138003240984@etudes_nt>
References: <FB0608BA1956244694E2B71BF8B8138003240984@etudes_nt>
VIDAL Cedric wrote:
>
>>-----Message d'origine-----
>>De : pgsql-jdbc-owner@postgresql.org
>>[mailto:pgsql-jdbc-owner@postgresql.org]De la part de Kris Jurka
>>Envoye : mardi 30 novembre 2004 12:37
>>A : VIDAL Cedric
>>Cc : 'pgsql-jdbc@postgresql.org'
>>Objet : Re: [JDBC] Need a performance tip - Statement pooling
>>for server
>>
>>
>>
>>
>>On Tue, 30 Nov 2004, VIDAL Cedric wrote:
>>
>>
>>>Hi,
>>>
>>>On the postgresql jdbc site's todo
>>
>>http://jdbc.postgresql.org/todo.html, it
>>
>>>is stated that
>>>"statement pooling to take advantage of server prepared
>>
>>statements" should
>>
>>>be added.
>>>
>>>Is that information up to date ? Is that feature really not
>>
>>supported. If
>>
>>>yes, does that mean, that using JDBC PreparedStatement(s)
>>
>>with PostgreSQL
>>
>>>doesn't take avantage of server side statement pooling, and
>>
>>thus has no
>>
>>>advantage over simple statements.
>>>
>>
>>There is a difference between not using server side
>>statements and not
>>pooling them. Consider a function that did an insert into
>>the database.
>>
>>public void f(Connection conn, int i) throws SQLException {
>> PreparedStatement ps = conn.prepareStatement("INSERT INTO t
>>VALUES(?)");
>> ps.setInt(1,i);
>> ps.executeUpdate();
>> ps.close();
>>}
>>
>>In this case a prepared statement is created every time the
>>function is
>>called so no real advantage comes from doing a server side
>>preparation.
>>Now if the function was written as:
>>
>>public void f(PreparedStatement ps, int i) throws SQLException {
>> ps.setInt(1, i);
>> ps.executeUpdate();
>>}
>>
>>Then the prepared statement gets reused and potentially
>>significant gains
>>can be had from doing server side preparation. The idea
>>behind statement
>>pooling is to allow a function written in the first form to get the
>>performance advantages of a function written in the second
>>form. It can
>>be difficult to create and manage a pool of
>>PreparedStatements to reuse in
>>your application code, so it would be great if the driver
>>could do that
>>for you.
>>
>>Kris Jurka
>
>
> Hi Kris,
>
> So if I get it right, i understand that
> - 1 - postgresql knows how to prepare statements
> - 2 - the pooling is the responsibility of the jdbc driver
> - 3 - the postgresql jdbc driver doesn't implement prepared statements
> pooling thus does not take advantage of
> postgresql's preparing statements (your first form doesn't get the
> performance advantage)
You take advantage of it when you reuse the same prepared statement.
For example :
PreparedStatement ps = conn.prepareStatement("INSERT INTO t VALUES(?)");
for (int i=1;i<=5;i++){
ps.setInt(1,i);
ps.executeUpdate();
}
ps.close();
Or better using batch :
PreparedStatement ps = conn.prepareStatement("INSERT INTO t VALUES(?)");
for (int i=1;i<=5;i++){
ps.setInt(1,i);
ps.addBatch();
}
ps.executeBatch();
ps.close();
> - 4 - if our application were to deal with prepared statements' pooling
> itself (your second form), it would get the performance advantage of
> postgresql's preparing statements
>
> Is it so ?
>
> thanx for the reply,
>
> Cedric Vidal
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: xpoinsard@free.fr
Subject: Re: Need a performance tip - Statement pooling for server
In-Reply-To: <coi8o0$ejo$1@floppy.pyrenet.fr>
References: <FB0608BA1956244694E2B71BF8B8138003240984@etudes_nt> <coi8o0$ejo$1@floppy.pyrenet.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox