Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf4bd04b

Browse files
committed
Replace pq_getbytes(&ch, 1) calls with pq_getbyte(), which is easier
to use and significantly faster. This tweak saves 25% (!) of the runtimeof COPY IN in a test with 8000-character lines. I wouldn't normallycommit a performance improvement this late in the cycle, but 25% gotmy attention...
1 parentdae887a commitf4bd04b

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

‎src/backend/commands/copy.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.142 2001/10/25 05:49:24 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.143 2001/12/04 19:40:16 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -157,13 +157,10 @@ CopyGetChar(FILE *fp)
157157
{
158158
if (!fp)
159159
{
160-
unsignedcharch;
160+
intch=pq_getbyte();
161161

162-
if (pq_getbytes((char*)&ch,1))
163-
{
162+
if (ch==EOF)
164163
fe_eof= true;
165-
returnEOF;
166-
}
167164
returnch;
168165
}
169166
else
@@ -209,12 +206,9 @@ CopyDonePeek(FILE *fp, int c, int pickup)
209206
if (pickup)
210207
{
211208
/*
212-
* We want to pick it up - just receive again into dummy
213-
* buffer
209+
* We want to pick it up
214210
*/
215-
charc;
216-
217-
pq_getbytes(&c,1);
211+
(void)pq_getbyte();
218212
}
219213
/* If we didn't want to pick it up, just leave it where it sits */
220214
}

‎src/backend/libpq/pqcomm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
3030
* Portions Copyright (c) 1994, Regents of the University of California
3131
*
32-
*$Id: pqcomm.c,v 1.124 2001/11/12 04:54:08 tgl Exp $
32+
*$Id: pqcomm.c,v 1.125 2001/12/04 19:40:17 tgl Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -47,6 +47,7 @@
4747
* low-level I/O:
4848
*pq_getbytes- get a known number of bytes from connection
4949
*pq_getstring- get a null terminated string from connection
50+
*pq_getbyte- get next byte from connection
5051
*pq_peekbyte- peek at next byte from connection
5152
*pq_putbytes- send bytes to connection (not flushed until pq_flush)
5253
*pq_flush- flush pending output
@@ -527,7 +528,7 @@ pq_recvbuf(void)
527528
*pq_getbyte- get a single byte from connection, or return EOF
528529
* --------------------------------
529530
*/
530-
staticint
531+
int
531532
pq_getbyte(void)
532533
{
533534
while (PqRecvPointer >=PqRecvLength)

‎src/backend/tcop/postgres.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.242 2001/11/10 23:51:14 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.243 2001/12/04 19:40:17 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -242,25 +242,25 @@ InteractiveBackend(StringInfo inBuf)
242242
staticint
243243
SocketBackend(StringInfoinBuf)
244244
{
245-
charqtype;
246-
charresult='\0';
245+
intqtype;
247246

248247
/*
249248
* get input from the frontend
250249
*/
251-
qtype='?';
252-
if (pq_getbytes(&qtype,1)==EOF)
253-
returnEOF;
250+
qtype=pq_getbyte();
254251

255252
switch (qtype)
256253
{
254+
caseEOF:
255+
/* frontend disconnected */
256+
break;
257+
257258
/*
258259
* 'Q': user entered a query
259260
*/
260261
case'Q':
261262
if (pq_getstr(inBuf))
262263
returnEOF;
263-
result='Q';
264264
break;
265265

266266
/*
@@ -269,14 +269,12 @@ SocketBackend(StringInfo inBuf)
269269
case'F':
270270
if (pq_getstr(inBuf))
271271
returnEOF;/* ignore "string" at start of F message */
272-
result='F';
273272
break;
274273

275274
/*
276275
* 'X': frontend is exiting
277276
*/
278277
case'X':
279-
result='X';
280278
break;
281279

282280
/*
@@ -289,7 +287,8 @@ SocketBackend(StringInfo inBuf)
289287
elog(FATAL,"Socket command type %c unknown",qtype);
290288
break;
291289
}
292-
returnresult;
290+
291+
returnqtype;
293292
}
294293

295294
/* ----------------
@@ -1627,7 +1626,7 @@ PostgresMain(int argc, char *argv[], const char *username)
16271626
if (!IsUnderPostmaster)
16281627
{
16291628
puts("\nPOSTGRES backend interactive interface ");
1630-
puts("$Revision: 1.242 $ $Date: 2001/11/10 23:51:14 $\n");
1629+
puts("$Revision: 1.243 $ $Date: 2001/12/04 19:40:17 $\n");
16311630
}
16321631

16331632
/*

‎src/include/libpq/libpq.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: libpq.h,v 1.48 2001/11/05 17:46:33 momjian Exp $
10+
* $Id: libpq.h,v 1.49 2001/12/04 19:40:17 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -62,6 +62,7 @@ extern void StreamClose(int sock);
6262
externvoidpq_init(void);
6363
externintpq_getbytes(char*s,size_tlen);
6464
externintpq_getstring(StringInfos);
65+
externintpq_getbyte(void);
6566
externintpq_peekbyte(void);
6667
externintpq_putbytes(constchar*s,size_tlen);
6768
externintpq_flush(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp