Various clarifications; add a clear DRAFT marker; minor adjustments in

some message types.  In particular add text/binary flag to StartCopyIn
and StartCopyOut, so that client library can know what is expected or
forthcoming.
This commit is contained in:
Tom Lane 2003-04-16 20:53:38 +00:00
parent e8ee547829
commit 26b237ffad
1 changed files with 70 additions and 30 deletions

View File

@ -1,8 +1,16 @@
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.26 2003/04/15 22:51:18 tgl Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.27 2003/04/16 20:53:38 tgl Exp $ -->
<chapter id="protocol"> <chapter id="protocol">
<title>Frontend/Backend Protocol</title> <title>Frontend/Backend Protocol</title>
<caution>
<para>
This is currently a <emphasis>DRAFT</> description of FE/BE protocol
version 3.0. Details are still subject to change.
In particular, the representation of binary data is still under debate.
</para>
</caution>
<para> <para>
<application>PostgreSQL</application> uses a message-based protocol <application>PostgreSQL</application> uses a message-based protocol
for communication between frontends and backends (clients and servers). for communication between frontends and backends (clients and servers).
@ -504,11 +512,12 @@
</Para> </Para>
<Para> <Para>
The response to a <command>SELECT</> or <command>FETCH</> query The response to a <command>SELECT</>, <command>FETCH</>, or
<command>SHOW</> query
normally consists of RowDescription, zero or more normally consists of RowDescription, zero or more
DataRow or BinaryRow messages, and then CommandComplete. DataRow or BinaryRow messages, and then CommandComplete.
<command>COPY</> to or from the frontend invokes special protocol <command>COPY</> to or from the frontend invokes special protocol
as described below. as described in <xref linkend="protocol-copy">.
All other query types normally produce only All other query types normally produce only
a CommandComplete message. a CommandComplete message.
</Para> </Para>
@ -524,7 +533,6 @@
<Para> <Para>
If a completely empty (no contents other than whitespace) query string If a completely empty (no contents other than whitespace) query string
is received, the response is EmptyQueryResponse followed by ReadyForQuery. is received, the response is EmptyQueryResponse followed by ReadyForQuery.
(The need to specially distinguish this case is historical.)
</Para> </Para>
<Para> <Para>
@ -621,7 +629,10 @@
The possible The possible
responses to Execute are the same as those described above for queries responses to Execute are the same as those described above for queries
issued via simple query protocol, except that Execute doesn't cause issued via simple query protocol, except that Execute doesn't cause
ReadyForQuery to be issued. ReadyForQuery to be issued. Also, the choice between text and binary
output (DataRow or BinaryRow messages) is determined by Execute's
format field, regardless of the command; the <literal>BINARY</> attribute
in cursor declarations is irrelevant when using this protocol.
</para> </para>
<para> <para>
@ -630,8 +641,11 @@
PortalSuspended message; the appearance of this message tells the frontend PortalSuspended message; the appearance of this message tells the frontend
that another Execute should be issued against the same portal to that another Execute should be issued against the same portal to
complete the operation. The CommandComplete message indicating complete the operation. The CommandComplete message indicating
completion of the source SELECT or FETCH command is not sent until completion of the source SQL command is not sent until
the command is completed. the portal's execution is completed. Therefore, an Execute phase is
always terminated by the appearance of exactly one of these messages:
CommandComplete, EmptyQueryResponse (if the portal was created from
an empty query string), ErrorResponse, or PortalSuspended.
</para> </para>
<para> <para>
@ -715,7 +729,16 @@
<Sect2> <Sect2>
<Title>Function Call</Title> <Title>Function Call</Title>
<Para> <note>
<para>
The Function Call sub-protocol is a legacy feature that is probably best
avoided in new code. Similar results can be accomplished by setting up
a prepared statement that does <literal>SELECT function($1, ...)</>.
The Function Call cycle can then be replaced with Bind/Execute.
</para>
</note>
<para>
A Function Call cycle is initiated by the frontend sending a A Function Call cycle is initiated by the frontend sending a
FunctionCall message to the backend. The backend then sends one FunctionCall message to the backend. The backend then sends one
or more response messages depending on the results of the function or more response messages depending on the results of the function
@ -724,7 +747,7 @@
function call. function call.
</para> </para>
<Para> <para>
The possible response messages from the backend are: The possible response messages from the backend are:
<VariableList> <VariableList>
@ -741,7 +764,9 @@
<Term>FunctionResultResponse</Term> <Term>FunctionResultResponse</Term>
<ListItem> <ListItem>
<Para> <Para>
The function call was executed and returned a result. The function call was executed and returned a non-null result.
(Note that the Function Call protocol can only handle a single
scalar result, not a rowtype or set of results.)
</Para> </Para>
</ListItem> </ListItem>
</VarListEntry> </VarListEntry>
@ -750,7 +775,7 @@
<Term>FunctionVoidResponse</Term> <Term>FunctionVoidResponse</Term>
<ListItem> <ListItem>
<Para> <Para>
The function call was executed and returned no result. The function call was executed and returned a NULL value.
</Para> </Para>
</ListItem> </ListItem>
</VarListEntry> </VarListEntry>
@ -800,8 +825,9 @@
message (allowing successful termination) or a CopyFail message (which message (allowing successful termination) or a CopyFail message (which
will cause the <command>COPY</> SQL statement to fail with an will cause the <command>COPY</> SQL statement to fail with an
error). The backend then reverts to the command-processing mode it was error). The backend then reverts to the command-processing mode it was
in before the <command>COPY</> started (which will be either simple or in before the <command>COPY</> started, which will be either simple or
extended query protocol). extended query protocol. It will next send either CommandComplete
(if successful) or ErrorResponse (if not).
</para> </para>
<para> <para>
@ -826,7 +852,8 @@
zero or more CopyDataRow messages, one per row, followed by CopyDone. zero or more CopyDataRow messages, one per row, followed by CopyDone.
(For <command>COPY BINARY</>, CopyBinaryRow messages are sent instead.) (For <command>COPY BINARY</>, CopyBinaryRow messages are sent instead.)
The backend then reverts to the command-processing mode it was The backend then reverts to the command-processing mode it was
in before the <command>COPY</> started. The frontend cannot abort in before the <command>COPY</> started, and sends CommandComplete.
The frontend cannot abort
the transfer (short of closing the connection), but it can discard the transfer (short of closing the connection), but it can discard
unwanted CopyDataRow, CopyBinaryRow, and CopyDone messages. unwanted CopyDataRow, CopyBinaryRow, and CopyDone messages.
</para> </para>
@ -1668,7 +1695,7 @@ Bind (F)
</VarListEntry> </VarListEntry>
<VarListEntry> <VarListEntry>
<Term> <Term>
Int16 Int32
</Term> </Term>
<ListItem> <ListItem>
<Para> <Para>
@ -2195,7 +2222,7 @@ CopyInResponse (B)
</VarListEntry> </VarListEntry>
<VarListEntry> <VarListEntry>
<Term> <Term>
Int32(4) Int32(5)
</Term> </Term>
<ListItem> <ListItem>
<Para> <Para>
@ -2203,6 +2230,17 @@ CopyInResponse (B)
</Para> </Para>
</ListItem> </ListItem>
</VarListEntry> </VarListEntry>
<VarListEntry>
<Term>
Int8
</Term>
<ListItem>
<Para>
0 for textual copy (CopyDataRow is expected), 1 for
binary copy (CopyBinaryRow is expected).
</Para>
</ListItem>
</VarListEntry>
</VariableList> </VariableList>
</Para> </Para>
@ -2231,7 +2269,7 @@ CopyOutResponse (B)
</VarListEntry> </VarListEntry>
<VarListEntry> <VarListEntry>
<Term> <Term>
Int32(4) Int32(5)
</Term> </Term>
<ListItem> <ListItem>
<Para> <Para>
@ -2239,6 +2277,17 @@ CopyOutResponse (B)
</Para> </Para>
</ListItem> </ListItem>
</VarListEntry> </VarListEntry>
<VarListEntry>
<Term>
Int8
</Term>
<ListItem>
<Para>
0 for textual copy (CopyDataRow will follow), 1 for
binary copy (CopyBinaryRow will follow).
</Para>
</ListItem>
</VarListEntry>
</VariableList> </VariableList>
</Para> </Para>
@ -2402,12 +2451,13 @@ EmptyQueryResponse (B)
<ListItem> <ListItem>
<Para> <Para>
Identifies the message as a response to an empty query string. Identifies the message as a response to an empty query string.
(This substitutes for CommandComplete.)
</Para> </Para>
</ListItem> </ListItem>
</VarListEntry> </VarListEntry>
<VarListEntry> <VarListEntry>
<Term> <Term>
Int32(5) Int32(4)
</Term> </Term>
<ListItem> <ListItem>
<Para> <Para>
@ -2415,16 +2465,6 @@ EmptyQueryResponse (B)
</Para> </Para>
</ListItem> </ListItem>
</VarListEntry> </VarListEntry>
<VarListEntry>
<Term>
String("")
</Term>
<ListItem>
<Para>
Unused.
</Para>
</ListItem>
</VarListEntry>
</VariableList> </VariableList>
</Para> </Para>
@ -3014,7 +3054,7 @@ ParameterDescription (B)
</VarListEntry> </VarListEntry>
<VarListEntry> <VarListEntry>
<Term> <Term>
Int16 Int32
</Term> </Term>
<ListItem> <ListItem>
<Para> <Para>
@ -3147,7 +3187,7 @@ Parse (F)
</VarListEntry> </VarListEntry>
<VarListEntry> <VarListEntry>
<Term> <Term>
Int16 Int32
</Term> </Term>
<ListItem> <ListItem>
<Para> <Para>