Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 70066eb

Browse files
committed
Insert into getCopyDataMessage() the same logic that already existed in the
main code path for enlarging libpq's input buffer in one swoop when needing to read a long data message. Without this, the code will double the buffer size, read more data, notice it still hasn't got the whole message, and repeat till it finally has a large enough buffer. Which wastes a lot of data-moving effort and also memory (since malloc probably can't do anything very useful with the freed-up smaller buffers). Not sure why this wasn't there already; certainly the COPY data path is a place where we're quite likely to see long data messages. I'm not backpatching though, since this is just a marginal performance issue rather than a real bug.
1 parent a44174c commit 70066eb

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/interfaces/libpq/fe-protocol3.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.33 2008/01/15 22:18:20 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.34 2008/01/17 21:21:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1305,7 +1305,24 @@ getCopyDataMessage(PGconn *conn)
13051305
}
13061306
avail = conn->inEnd - conn->inCursor;
13071307
if (avail < msgLength - 4)
1308+
{
1309+
/*
1310+
* Before returning, enlarge the input buffer if needed to hold
1311+
* the whole message. See notes in parseInput.
1312+
*/
1313+
if (pqCheckInBufferSpace(conn->inCursor + msgLength - 4, conn))
1314+
{
1315+
/*
1316+
* XXX add some better recovery code... plan is to skip over
1317+
* the message using its length, then report an error. For the
1318+
* moment, just treat this like loss of sync (which indeed it
1319+
* might be!)
1320+
*/
1321+
handleSyncLoss(conn, id, msgLength);
1322+
return -2;
1323+
}
13081324
return 0;
1325+
}
13091326

13101327
/*
13111328
* If it's a legitimate async message type, process it. (NOTIFY

0 commit comments

Comments
 (0)