pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Altaf Malik <mmalik_altaf@yahoo.com>
To: Kris Jurka <books@ejurka.com>
Cc: Dave Cramer <pg@fastcrypt.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC causing the connection to close after executing a COPY command
Date: Fri, 14 Dec 2007 13:50:52 -0800 (PST)
Message-ID: <70448.97215.qm@web39108.mail.mud.yahoo.com> (raw)
In-Reply-To: <Pine.BSO.4.64.0712131616360.2084@leary.csoft.net>

I am attaching the new patch.

For CopyInResponse, client will send a CopyFail message and server won't wait for the client input. For CopyOutResponse, exception is generated for only CopyOutResponse and not for every CopyData message. Also slightly changed the 'ignoring' mechanism from reading the message to ignore it to skipping the message. I hope this
 will also improve the performance.

Altaf Malik
EnterpriseDB
http://www.enterprisedb.com/

Kris Jurka <books@ejurka.com> wrote:

 In the case of copying data from the server, if you do have a 
large table, you'll generate a SQLException for every row of the copy 
result which isn't great, but I guess it's better than failing completely. 

Trying to copy out a single column table of 100k integers took about seven 
minutes and 150 MB of memory here.

Also, it doesn't work for copying data to the server.  In that case the 
server is sitting waiting for data and the driver is waiting for the 
server and nothing happens.  That was the case before, so this is no 
worse.

Do you have plans to work on this further or shall I apply just this minor 
improvement?

Kris Jurka



          Best Regards
  Muhammad Altaf Malik 
Sr. Software Engineer, 
EnterpriseDB (SMC) (pvt) Ltd.
  3rd floor, Software Technology Park, 
Islamabad. Ph: +92 (051) 2873815
  Cell: 0321-5177961






       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.

Attachments:

pg_copy.diff (text/x-patch, 3.8K) download *** org/postgresql/core/v3/QueryExecutorImpl.java 2007-10-15 13:06:24.000000000 +0500 --- org/postgresql/core/v3/QueryExecutorImpl.java 2007-12-15 02:40:49.000000000 +0500 *************** *** 1425,1447 **** break; case 'G': // CopyInResponse case 'H': // CopyOutResponse case 'c': // CopyDone ! case 'd': // CopyData ! { ! // COPY FROM STDIN / COPY TO STDOUT, neither of which are currently ! // supported. ! ! // CopyInResponse can only occur in response to an Execute we sent. ! // Every Execute we send is followed by either a Bind or a ClosePortal, ! // so we don't need to send a CopyFail; the server will fail the copy ! // automatically when it sees the next message. ! ! int l_len = pgStream.ReceiveInteger4(); ! /* discard */ ! pgStream.Receive(l_len); ! handler.handleError(new PSQLException(GT.tr("The driver currently does not support COPY operations."), PSQLState.NOT_IMPLEMENTED)); } break; --- 1425,1469 ---- break; case 'G': // CopyInResponse + if (logger.logDebug()) { + logger.debug(" <=BE CopyInResponse"); + logger.debug(" FE=> CopyFail"); + } + + //COPY sub-protocol is not implemented yet + // We'll send a CopyFail message for COPY FROM STDIN so that server does not wait for the data + // For COPY TO STDOUT we cannot abort the data transfer ... we'll just ignore the messages + + byte[] buf = GT.tr("The driver currently does not support COPY operations.").getBytes(); + pgStream.SendChar('f'); + pgStream.SendInteger4(buf.length + 4 + 1); + pgStream.Send(buf); + pgStream.SendChar(0); + pgStream.flush(); + sendSync(); // send sync message + skipCopyResponse(); // skip the response message + break; + case 'H': // CopyOutResponse + if (logger.logDebug()) + logger.debug(" <=BE CopyOutResponse"); + + skipCopyResponse(); + //In case of CopyOutResponse we cannot abort data transfer - we will just throw error and ignore CopyData messages + handler.handleError(new PSQLException(GT.tr("The driver currently does not support COPY operations."), PSQLState.NOT_IMPLEMENTED)); + break; + case 'c': // CopyDone ! skipCopyResponse(); // skip the response message ! if (logger.logDebug()) { ! logger.debug("<=BE CopyDone"); ! } ! break; ! case 'd': // CopyData ! skipCopyResponse(); // skip the response message ! if (logger.logDebug()) { ! logger.debug("<=BE CopyData"); } break; *************** *** 1452,1457 **** --- 1474,1487 ---- } } + // skipCopyResponse + // ignore the response message by just skipping the next n bytes where n is the message length in bytes + private void skipCopyResponse() throws IOException { + int l_len = pgStream.ReceiveInteger4(); + // skip l_len-4 (length includes the 4 bytes for message length itself + pgStream.Skip(l_len - 4); + } + public synchronized void fetch(ResultCursor cursor, ResultHandler handler, int fetchSize) throws SQLException { final Portal portal = (Portal)cursor;

view thread (9+ messages)

Message-ID: <70448.97215.qm@web39108.mail.mud.yahoo.com>
Permalink:  ../70448.97215.qm@web39108.mail.mud.yahoo.com/
Also on:    postgresql.org/message-id/70448.97215.qm@web39108.mail.mud.yahoo.com

 ·  · 

reply

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: mmalik_altaf@yahoo.com, books@ejurka.com, pg@fastcrypt.com
  Subject: Re: JDBC causing the connection to close after executing a COPY command
  In-Reply-To: <70448.97215.qm@web39108.mail.mud.yahoo.com>
  References: <Pine.BSO.4.64.0712131616360.2084@leary.csoft.net> <70448.97215.qm@web39108.mail.mud.yahoo.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