src/bin/pg_dump/pg_dump.c
static void
collectComments(Archive *fout)
{
	PGresult   *res;
	PQExpBuffer query;
	int			i_description;
	int			i_classoid;
	int			i_objoid;
	int			i_objsubid;
	int			ntups;
	int			i;
	DumpableObject *dobj;

	query = createPQExpBuffer();

	appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
						 "FROM pg_catalog.pg_description "
						 "ORDER BY classoid, objoid, objsubid");

	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);

	/* Construct lookup table containing OIDs in numeric form */

	i_description = PQfnumber(res, "description");
	i_classoid = PQfnumber(res, "classoid");
	i_objoid = PQfnumber(res, "objoid");
	i_objsubid = PQfnumber(res, "objsubid");

	ntups = PQntuples(res);

	comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
	ncomments = 0;
	dobj = NULL;

	for (i = 0; i < ntups; i++)
	{
		CatalogId	objId;
		int			subid;

		objId.tableoid = atooid(PQgetvalue(res, i, i_classoid));
		objId.oid = atooid(PQgetvalue(res, i, i_objoid));
		subid = atoi(PQgetvalue(res, i, i_objsubid));

		/* We needn't remember comments that don't match any dumpable object */
		if (dobj == NULL ||
			dobj->catId.tableoid != objId.tableoid ||
			dobj->catId.oid != objId.oid)
			dobj = findObjectByCatalogId(objId);
		if (dobj == NULL)
			continue;

		/*
		 * Comments on columns of composite types are linked to the type's
		 * pg_class entry, but we need to set the DUMP_COMPONENT_COMMENT flag
		 * in the type's own DumpableObject.
		 */
		if (subid != 0 && dobj->objType == DO_TABLE &&
			((TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
		{
			TypeInfo   *cTypeInfo;

			cTypeInfo = findTypeByOid(((TableInfo *) dobj)->reltype);
			if (cTypeInfo)
				cTypeInfo->dobj.components |= DUMP_COMPONENT_COMMENT;
		}
		else
			dobj->components |= DUMP_COMPONENT_COMMENT;

		comments[ncomments].descr = pg_strdup(PQgetvalue(res, i, i_description));
		comments[ncomments].classoid = objId.tableoid;
		comments[ncomments].objoid = objId.oid;
		comments[ncomments].objsubid = subid;
		ncomments++;
	}

	PQclear(res);
	destroyPQExpBuffer(query);
}
/*
 * collectComments --
 *
 * Construct a table of all comments available for database objects;
 * also set the has-comment component flag for each relevant object.
 *
 * We used to do per-object queries for the comments, but it's much faster
 * to pull them all over at once, and on most databases the memory cost
 * isn't high.
 *
 * The table is sorted by classoid/objid/objsubid for speed in lookup.
 */
collectComments
Construct a table of all comments available for database objects;
also set the has-comment component flag for each relevant object.

We used to do per-object queries for the comments, but it's much faster
to pull them all over at once, and on most databases the memory cost
isn't high.

The table is sorted by classoid/objid/objsubid for speed in lookup.
collectComments Construct a table of all comments available for database objects ; also set the has - comment component flag for each relevant object . We used to do per - object queries for the comments but it ' s much faster to pull them all over at once and on most databases the memory cost isn ' t high . The table is sorted by classoid / objid / objsubid for speed in lookup .
static void
collectComments(Archive *fout)
{
	PGresult   *res;
	PQExpBuffer query;
	int			i_description;
	int			i_classoid;
	int			i_objoid;
	int			i_objsubid;
	int			ntups;
	int			i;
	DumpableObject *dobj;
	query = createPQExpBuffer();
	appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
						 "FROM pg_catalog.pg_description "
						 "ORDER BY classoid, objoid, objsubid");
	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
	i_description = PQfnumber(res, "description");
	i_classoid = PQfnumber(res, "classoid");
	i_objoid = PQfnumber(res, "objoid");
	i_objsubid = PQfnumber(res, "objsubid");
	ntups = PQntuples(res);
	comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
	ncomments = 0;
	dobj = NULL;
	for (i = 0; i < ntups; i++)
	{
		CatalogId	objId;
		int			subid;
		objId.tableoid = atooid(PQgetvalue(res, i, i_classoid));
		objId.oid = atooid(PQgetvalue(res, i, i_objoid));
		subid = atoi(PQgetvalue(res, i, i_objsubid));
		if (dobj == NULL ||
			dobj->catId.tableoid != objId.tableoid ||
			dobj->catId.oid != objId.oid)
			dobj = findObjectByCatalogId(objId);
		if (dobj == NULL)
			continue;
		if (subid != 0 && dobj->objType == DO_TABLE &&
			((TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
		{
			TypeInfo   *cTypeInfo;
			cTypeInfo = findTypeByOid(((TableInfo *) dobj)->reltype);
			if (cTypeInfo)
				cTypeInfo->dobj.components |= DUMP_COMPONENT_COMMENT;
		}
		else
			dobj->components |= DUMP_COMPONENT_COMMENT;
		comments[ncomments].descr = pg_strdup(PQgetvalue(res, i, i_description));
		comments[ncomments].classoid = objId.tableoid;
		comments[ncomments].objoid = objId.oid;
		comments[ncomments].objsubid = subid;
		ncomments++;
	}
	PQclear(res);
	destroyPQExpBuffer(query);
}
static void collectComments ( Archive * fout ) { PGresult * res ; PQExpBuffer query ; int i_description ; int i_classoid ; int i_objoid ; int i_objsubid ; int ntups ; int i ; DumpableObject * dobj ; query = createPQExpBuffer ( ) ; appendPQExpBufferStr ( query , " " " " " " ) ; res = ExecuteSqlQuery ( fout , query -> data , PGRES_TUPLES_OK ) ; i_description = PQfnumber ( res , " " ) ; i_classoid = PQfnumber ( res , " " ) ; i_objoid = PQfnumber ( res , " " ) ; i_objsubid = PQfnumber ( res , " " ) ; ntups = PQntuples ( res ) ; comments = ( CommentItem * ) pg_malloc ( ntups * sizeof ( CommentItem ) ) ; ncomments = 0 ; dobj = NULL ; for ( i = 0 ; i < ntups ; i ++ ) { CatalogId objId ; int subid ; objId . tableoid = atooid ( PQgetvalue ( res , i , i_classoid ) ) ; objId . oid = atooid ( PQgetvalue ( res , i , i_objoid ) ) ; subid = atoi ( PQgetvalue ( res , i , i_objsubid ) ) ; if ( dobj == NULL || dobj -> catId . tableoid != objId . tableoid || dobj -> catId . oid != objId . oid ) dobj = findObjectByCatalogId ( objId ) ; if ( dobj == NULL ) continue ; if ( subid != 0 && dobj -> objType == DO_TABLE && ( ( TableInfo * ) dobj ) -> relkind == RELKIND_COMPOSITE_TYPE ) { TypeInfo * cTypeInfo ; cTypeInfo = findTypeByOid ( ( ( TableInfo * ) dobj ) -> reltype ) ; if ( cTypeInfo ) cTypeInfo -> dobj . components |= DUMP_COMPONENT_COMMENT ; } else dobj -> components |= DUMP_COMPONENT_COMMENT ; comments [ ncomments ] . descr = pg_strdup ( PQgetvalue ( res , i , i_description ) ) ; comments [ ncomments ] . classoid = objId . tableoid ; comments [ ncomments ] . objoid = objId . oid ; comments [ ncomments ] . objsubid = subid ; ncomments ++ ; } PQclear ( res ) ; destroyPQExpBuffer ( query ) ; }
collectComments
 Construct a table of all comments available for database objects;
 also set the has-comment component flag for each relevant object.
collectComments Construct a table of all comments available for database objects ; also set the has - comment component flag for each relevant object .
/* Construct lookup table containing OIDs in numeric form */ /* We needn't remember comments that don't match any dumpable object */ /*
		 * Comments on columns of composite types are linked to the type's
		 * pg_class entry, but we need to set the DUMP_COMPONENT_COMMENT flag
		 * in the type's own DumpableObject.
		 */