BeginReportingGUCOptions函数利用ParameterStatus 消息向客户端启动对标记为 GUC_REPORT 的变量更改的自动报告。这是在后端启动完成时执行的。

void BeginReportingGUCOptions(void){
int i;
/* Don't do anything unless talking to an interactive frontend of protocol 3.0 or later. 除非与协议 3.0 或更高版本的交互式前端交谈,否则不要做任何事情。 */
if (whereToSendOutput != DestRemote || PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
return;
reporting_enabled = true;
/* Transmit initial values of interesting variables */
for (i = 0; i < num_guc_variables; i++) {
struct config_generic *conf = guc_variables[i];
if (conf->flags & GUC_REPORT) ReportGUCOption(conf);
}
}

ReportGUCOption向客户端发送消息。

/* ReportGUCOption: if appropriate, transmit option value to frontend */
static void ReportGUCOption(struct config_generic *record) {
if (reporting_enabled && (record->flags & GUC_REPORT)) {
char *val = _ShowOption(record, false);
StringInfoData msgbuf;
pq_beginmessage(&msgbuf, 'S');
pq_sendstring(&msgbuf, record->name);
pq_sendstring(&msgbuf, val);
pq_endmessage(&msgbuf);
pfree(val);
}
}

CommandDest 是一种识别所需目的地的简单方法。 总有一天,这可能需要改进。注意:只有值 DestNone、DestDebug、DestRemote 对于全局变量 whereToSendOutput 是合法的。 其他值可用作各个命令的目的地。

/* ----------------
* CommandDest is a simplistic means of identifying the desired
* destination. Someday this will probably need to be improved.
*
* Note: only the values DestNone, DestDebug, DestRemote are legal for the
* global variable whereToSendOutput. The other values may be used
* as the destination for individual commands.
* ----------------
*/
typedef enum {
DestNone, /* results are discarded */
DestDebug, /* results go to debugging output */
DestRemote, /* results sent to frontend process 结果发送给前端处理 */
DestRemoteExecute, /* sent to frontend, in Execute command */
DestRemoteSimple, /* sent to frontend, w/no catalog access */
DestSPI, /* results sent to SPI manager 结果发送给SPI管理器 */
DestTuplestore, /* results sent to Tuplestore 结果发送给Tuplestore */
DestIntoRel, /* results sent to relation (SELECT INTO) 结果发送到relation表 */
DestCopyOut, /* results sent to COPY TO code 结果发送到COPY TO */
DestSQLFunction, /* results sent to SQL-language func mgr 结果发送到SQL-language func mgr */
DestTransientRel, /* results sent to transient relation 结果发送到transient relation表 */
DestTupleQueue /* results sent to tuple queue 结果发送给Tuple队列 */
} CommandDest;