Re: Query preparation

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: John Lister <john(dot)lister-ps(at)kickstone(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Oliver Jowett <oliver(at)opencloud(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Query preparation
Date: 2009-04-15 12:42:55
Message-ID: 49E5D64F.8010603@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

John Lister wrote:
> I appreciate that the send operations (and responses) may be grouped
> into a single packet, but i was thinking of the scenario (which i would
> have thought is fairly common) where you prepare the statement and
> execute it multiple times with different parameters...
>
> This will result in the parse and describe(portal) commands being sent
> twice as is (unless i set the prepare threshold to be 1). Admittedly,
> this will probably not result in any extra packets as the total length
> of all commands is likely to be less than the packet length (the query
> size is likely to be the limiting factor here), but this causes extra
> load on both the server and client - although maybe not enough to worry
> about.
>
> I was thinking that you could parse/describe the query just once.

Incidentally, a customer of ours bumped into the overhead of the
describe portal step just yesterday. It doesn't cause any extra network
roundtrips, and is usually pretty cheap, but in this case they were
selecting a single row from a table with 145 columns thousands of times
in a loop. Furthermore, I believe most of the columns were NULL. They're
using a PreparedStatement, but we still send the Describe portal message
on every execution. A quick & dirty patch to cache the RowDescription
information cut over 10% off the total runtime of the application.

Does anyone see a problem with caching the result set descriptor
(RowDescription)? AFAICS it should never change after a statement is
prepared. If not, I'll polish up and submit the patch.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2009-04-15 13:11:30 Re: Query preparation
Previous Message Oliver Jowett 2009-04-14 23:49:20 Re: Query preparation