mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Replace pq_getbytes(&ch, 1) calls with pq_getbyte(), which is easier
to use and significantly faster. This tweak saves 25% (!) of the runtime of COPY IN in a test with 8000-character lines. I wouldn't normally commit a performance improvement this late in the cycle, but 25% got my attention...
This commit is contained in:
parent
dae887abfe
commit
f4bd04bb67
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.142 2001/10/25 05:49:24 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.143 2001/12/04 19:40:16 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -157,13 +157,10 @@ CopyGetChar(FILE *fp)
|
|||||||
{
|
{
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
unsigned char ch;
|
int ch = pq_getbyte();
|
||||||
|
|
||||||
if (pq_getbytes((char *) &ch, 1))
|
if (ch == EOF)
|
||||||
{
|
|
||||||
fe_eof = true;
|
fe_eof = true;
|
||||||
return EOF;
|
|
||||||
}
|
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -209,12 +206,9 @@ CopyDonePeek(FILE *fp, int c, int pickup)
|
|||||||
if (pickup)
|
if (pickup)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We want to pick it up - just receive again into dummy
|
* We want to pick it up
|
||||||
* buffer
|
|
||||||
*/
|
*/
|
||||||
char c;
|
(void) pq_getbyte();
|
||||||
|
|
||||||
pq_getbytes(&c, 1);
|
|
||||||
}
|
}
|
||||||
/* If we didn't want to pick it up, just leave it where it sits */
|
/* If we didn't want to pick it up, just leave it where it sits */
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: pqcomm.c,v 1.124 2001/11/12 04:54:08 tgl Exp $
|
* $Id: pqcomm.c,v 1.125 2001/12/04 19:40:17 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -47,6 +47,7 @@
|
|||||||
* low-level I/O:
|
* low-level I/O:
|
||||||
* pq_getbytes - get a known number of bytes from connection
|
* pq_getbytes - get a known number of bytes from connection
|
||||||
* pq_getstring - get a null terminated string from connection
|
* pq_getstring - get a null terminated string from connection
|
||||||
|
* pq_getbyte - get next byte from connection
|
||||||
* pq_peekbyte - peek at next byte from connection
|
* pq_peekbyte - peek at next byte from connection
|
||||||
* pq_putbytes - send bytes to connection (not flushed until pq_flush)
|
* pq_putbytes - send bytes to connection (not flushed until pq_flush)
|
||||||
* pq_flush - flush pending output
|
* pq_flush - flush pending output
|
||||||
@ -527,7 +528,7 @@ pq_recvbuf(void)
|
|||||||
* pq_getbyte - get a single byte from connection, or return EOF
|
* pq_getbyte - get a single byte from connection, or return EOF
|
||||||
* --------------------------------
|
* --------------------------------
|
||||||
*/
|
*/
|
||||||
static int
|
int
|
||||||
pq_getbyte(void)
|
pq_getbyte(void)
|
||||||
{
|
{
|
||||||
while (PqRecvPointer >= PqRecvLength)
|
while (PqRecvPointer >= PqRecvLength)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.242 2001/11/10 23:51:14 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.243 2001/12/04 19:40:17 tgl Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* this is the "main" module of the postgres backend and
|
* this is the "main" module of the postgres backend and
|
||||||
@ -242,25 +242,25 @@ InteractiveBackend(StringInfo inBuf)
|
|||||||
static int
|
static int
|
||||||
SocketBackend(StringInfo inBuf)
|
SocketBackend(StringInfo inBuf)
|
||||||
{
|
{
|
||||||
char qtype;
|
int qtype;
|
||||||
char result = '\0';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get input from the frontend
|
* get input from the frontend
|
||||||
*/
|
*/
|
||||||
qtype = '?';
|
qtype = pq_getbyte();
|
||||||
if (pq_getbytes(&qtype, 1) == EOF)
|
|
||||||
return EOF;
|
|
||||||
|
|
||||||
switch (qtype)
|
switch (qtype)
|
||||||
{
|
{
|
||||||
|
case EOF:
|
||||||
|
/* frontend disconnected */
|
||||||
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 'Q': user entered a query
|
* 'Q': user entered a query
|
||||||
*/
|
*/
|
||||||
case 'Q':
|
case 'Q':
|
||||||
if (pq_getstr(inBuf))
|
if (pq_getstr(inBuf))
|
||||||
return EOF;
|
return EOF;
|
||||||
result = 'Q';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -269,14 +269,12 @@ SocketBackend(StringInfo inBuf)
|
|||||||
case 'F':
|
case 'F':
|
||||||
if (pq_getstr(inBuf))
|
if (pq_getstr(inBuf))
|
||||||
return EOF; /* ignore "string" at start of F message */
|
return EOF; /* ignore "string" at start of F message */
|
||||||
result = 'F';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 'X': frontend is exiting
|
* 'X': frontend is exiting
|
||||||
*/
|
*/
|
||||||
case 'X':
|
case 'X':
|
||||||
result = 'X';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -289,7 +287,8 @@ SocketBackend(StringInfo inBuf)
|
|||||||
elog(FATAL, "Socket command type %c unknown", qtype);
|
elog(FATAL, "Socket command type %c unknown", qtype);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
return qtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
@ -1627,7 +1626,7 @@ PostgresMain(int argc, char *argv[], const char *username)
|
|||||||
if (!IsUnderPostmaster)
|
if (!IsUnderPostmaster)
|
||||||
{
|
{
|
||||||
puts("\nPOSTGRES backend interactive interface ");
|
puts("\nPOSTGRES backend interactive interface ");
|
||||||
puts("$Revision: 1.242 $ $Date: 2001/11/10 23:51:14 $\n");
|
puts("$Revision: 1.243 $ $Date: 2001/12/04 19:40:17 $\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: libpq.h,v 1.48 2001/11/05 17:46:33 momjian Exp $
|
* $Id: libpq.h,v 1.49 2001/12/04 19:40:17 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -62,6 +62,7 @@ extern void StreamClose(int sock);
|
|||||||
extern void pq_init(void);
|
extern void pq_init(void);
|
||||||
extern int pq_getbytes(char *s, size_t len);
|
extern int pq_getbytes(char *s, size_t len);
|
||||||
extern int pq_getstring(StringInfo s);
|
extern int pq_getstring(StringInfo s);
|
||||||
|
extern int pq_getbyte(void);
|
||||||
extern int pq_peekbyte(void);
|
extern int pq_peekbyte(void);
|
||||||
extern int pq_putbytes(const char *s, size_t len);
|
extern int pq_putbytes(const char *s, size_t len);
|
||||||
extern int pq_flush(void);
|
extern int pq_flush(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user