From: Oliver Jowett <oliver@opencloud.com>
To: Sebastiaan van Erk <sebster@sebster.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: ps.setCharacterStream() and memory usage
Date: Sat, 30 Oct 2004 10:30:07 +1300
Message-ID: <4182B65F.6000905@opencloud.com> (raw)
In-Reply-To: <20041029115651.GE4199@sebster.com>
References: <20041029115651.GE4199@sebster.com>
Sebastiaan van Erk wrote:
> ps.setCharacterStream(1, reader, (int) messageFile.length());
> ps.executeUpdate();
> I already noticed that the postgres driver does not stream the data to
> the backend (I don't know if postgres actually supports this).
Character streams are going to be hard to support as we need to know the
length, in bytes, of the parameter before we start sending it to the
backend. With a character stream the number of bytes is unpredictable
because it's being encoded into UTF8, which has a variable number of
bytes per character.
Binary streams we can stream, and the development driver already does so
without intermediate copies.
> First of all, in setCharacterStream() it loads the file into a char array.
> Then this is cloned into a String and passed to setString. (Here one can
> already cause the char[] to go out of scope, at least allowing it to be
> cleaned up). Secondly, setString causes another clone in escapeString(). [...]
I suggest you look at the current development driver before looking at
solutions in this area. The parameter storage mechanisms have changed
substantially compared to the stable driver. It should be much easier
to, for example, encode the stream directly into a bytearray, then write
from that array to the server on demand.
-O
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: oliver@opencloud.com, sebster@sebster.com
Subject: Re: ps.setCharacterStream() and memory usage
In-Reply-To: <4182B65F.6000905@opencloud.com>
References: <20041029115651.GE4199@sebster.com> <4182B65F.6000905@opencloud.com>
* 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