summaryrefslogtreecommitdiff
path: root/src/backend/tcop/fastpath.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2021-03-04 10:45:55 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2021-03-04 10:45:55 +0200
commit3174d69fb96a66173224e60ec7053b988d5ed4d9 (patch)
tree2dbeb5e94ccfde05b8d40a15b88e1107220fb9b1 /src/backend/tcop/fastpath.c
parent0a687c8f103d217ff1ca8c34a644b380d89bb0ad (diff)
Remove server and libpq support for old FE/BE protocol version 2.
Protocol version 3 was introduced in PostgreSQL 7.4. There shouldn't be many clients or servers left out there without version 3 support. But as a courtesy, I kept just enough of the old protocol support that we can still send the "unsupported protocol version" error in v2 format, so that old clients can display the message properly. Likewise, libpq still understands v2 ErrorResponse messages when establishing a connection. The impetus to do this now is that I'm working on a patch to COPY FROM, to always prefetch some data. We cannot do that safely with the old protocol, because it requires parsing the input one byte at a time to detect the end-of-copy marker. Reviewed-by: Tom Lane, Alvaro Herrera, John Naylor Discussion: https://www.postgresql.org/message-id/9ec25819-0a8a-d51a-17dc-4150bb3cca3b%40iki.fi
Diffstat (limited to 'src/backend/tcop/fastpath.c')
-rw-r--r--src/backend/tcop/fastpath.c165
1 files changed, 2 insertions, 163 deletions
diff --git a/src/backend/tcop/fastpath.c b/src/backend/tcop/fastpath.c
index 1b76653caa4..77d17ebca94 100644
--- a/src/backend/tcop/fastpath.c
+++ b/src/backend/tcop/fastpath.c
@@ -58,98 +58,24 @@ struct fp_info
static int16 parse_fcall_arguments(StringInfo msgBuf, struct fp_info *fip,
FunctionCallInfo fcinfo);
-static int16 parse_fcall_arguments_20(StringInfo msgBuf, struct fp_info *fip,
- FunctionCallInfo fcinfo);
-
-
-/* ----------------
- * GetOldFunctionMessage
- *
- * In pre-3.0 protocol, there is no length word on the message, so we have
- * to have code that understands the message layout to absorb the message
- * into a buffer. We want to do this before we start execution, so that
- * we do not lose sync with the frontend if there's an error.
- *
- * The caller should already have initialized buf to empty.
- * ----------------
- */
-int
-GetOldFunctionMessage(StringInfo buf)
-{
- int32 ibuf;
- int nargs;
-
- /* Dummy string argument */
- if (pq_getstring(buf))
- return EOF;
- /* Function OID */
- if (pq_getbytes((char *) &ibuf, 4))
- return EOF;
- appendBinaryStringInfo(buf, (char *) &ibuf, 4);
- /* Number of arguments */
- if (pq_getbytes((char *) &ibuf, 4))
- return EOF;
- appendBinaryStringInfo(buf, (char *) &ibuf, 4);
- nargs = pg_ntoh32(ibuf);
- /* For each argument ... */
- while (nargs-- > 0)
- {
- int argsize;
-
- /* argsize */
- if (pq_getbytes((char *) &ibuf, 4))
- return EOF;
- appendBinaryStringInfo(buf, (char *) &ibuf, 4);
- argsize = pg_ntoh32(ibuf);
- if (argsize < -1)
- {
- /* FATAL here since no hope of regaining message sync */
- ereport(FATAL,
- (errcode(ERRCODE_PROTOCOL_VIOLATION),
- errmsg("invalid argument size %d in function call message",
- argsize)));
- }
- /* and arg contents */
- if (argsize > 0)
- {
- /* Allocate space for arg */
- enlargeStringInfo(buf, argsize);
- /* And grab it */
- if (pq_getbytes(buf->data + buf->len, argsize))
- return EOF;
- buf->len += argsize;
- /* Place a trailing null per StringInfo convention */
- buf->data[buf->len] = '\0';
- }
- }
- return 0;
-}
/* ----------------
* SendFunctionResult
- *
- * Note: although this routine doesn't check, the format had better be 1
- * (binary) when talking to a pre-3.0 client.
* ----------------
*/
static void
SendFunctionResult(Datum retval, bool isnull, Oid rettype, int16 format)
{
- bool newstyle = (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3);
StringInfoData buf;
pq_beginmessage(&buf, 'V');
if (isnull)
{
- if (newstyle)
- pq_sendint32(&buf, -1);
+ pq_sendint32(&buf, -1);
}
else
{
- if (!newstyle)
- pq_sendbyte(&buf, 'G');
-
if (format == 0)
{
Oid typoutput;
@@ -180,9 +106,6 @@ SendFunctionResult(Datum retval, bool isnull, Oid rettype, int16 format)
errmsg("unsupported format code: %d", format)));
}
- if (!newstyle)
- pq_sendbyte(&buf, '0');
-
pq_endmessage(&buf);
}
@@ -288,9 +211,6 @@ HandleFunctionRequest(StringInfo msgBuf)
/*
* Begin parsing the buffer contents.
*/
- if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
- (void) pq_getmsgstring(msgBuf); /* dummy string */
-
fid = (Oid) pq_getmsgint(msgBuf, 4); /* function oid */
/*
@@ -334,10 +254,7 @@ HandleFunctionRequest(StringInfo msgBuf)
*/
InitFunctionCallInfoData(*fcinfo, &fip->flinfo, 0, InvalidOid, NULL, NULL);
- if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3)
- rformat = parse_fcall_arguments(msgBuf, fip, fcinfo);
- else
- rformat = parse_fcall_arguments_20(msgBuf, fip, fcinfo);
+ rformat = parse_fcall_arguments(msgBuf, fip, fcinfo);
/* Verify we reached the end of the message where expected. */
pq_getmsgend(msgBuf);
@@ -533,81 +450,3 @@ parse_fcall_arguments(StringInfo msgBuf, struct fp_info *fip,
/* Return result format code */
return (int16) pq_getmsgint(msgBuf, 2);
}
-
-/*
- * Parse function arguments in a 2.0 protocol message
- *
- * Argument values are loaded into *fcinfo, and the desired result format
- * is returned.
- */
-static int16
-parse_fcall_arguments_20(StringInfo msgBuf, struct fp_info *fip,
- FunctionCallInfo fcinfo)
-{
- int nargs;
- int i;
- StringInfoData abuf;
-
- nargs = pq_getmsgint(msgBuf, 4); /* # of arguments */
-
- if (fip->flinfo.fn_nargs != nargs || nargs > FUNC_MAX_ARGS)
- ereport(ERROR,
- (errcode(ERRCODE_PROTOCOL_VIOLATION),
- errmsg("function call message contains %d arguments but function requires %d",
- nargs, fip->flinfo.fn_nargs)));
-
- fcinfo->nargs = nargs;
-
- initStringInfo(&abuf);
-
- /*
- * Copy supplied arguments into arg vector. In protocol 2.0 these are
- * always assumed to be supplied in binary format.
- *
- * Note: although the original protocol 2.0 code did not have any way for
- * the frontend to specify a NULL argument, we now choose to interpret
- * length == -1 as meaning a NULL.
- */
- for (i = 0; i < nargs; ++i)
- {
- int argsize;
- Oid typreceive;
- Oid typioparam;
-
- getTypeBinaryInputInfo(fip->argtypes[i], &typreceive, &typioparam);
-
- argsize = pq_getmsgint(msgBuf, 4);
- if (argsize == -1)
- {
- fcinfo->args[i].isnull = true;
- fcinfo->args[i].value = OidReceiveFunctionCall(typreceive, NULL,
- typioparam, -1);
- continue;
- }
- fcinfo->args[i].isnull = false;
- if (argsize < 0)
- ereport(ERROR,
- (errcode(ERRCODE_PROTOCOL_VIOLATION),
- errmsg("invalid argument size %d in function call message",
- argsize)));
-
- /* Reset abuf to empty, and insert raw data into it */
- resetStringInfo(&abuf);
- appendBinaryStringInfo(&abuf,
- pq_getmsgbytes(msgBuf, argsize),
- argsize);
-
- fcinfo->args[i].value = OidReceiveFunctionCall(typreceive, &abuf,
- typioparam, -1);
-
- /* Trouble if it didn't eat the whole buffer */
- if (abuf.cursor != abuf.len)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
- errmsg("incorrect binary data format in function argument %d",
- i + 1)));
- }
-
- /* Desired result format is always binary in protocol 2.0 */
- return 1;
-}