1717#include <ctype.h>
1818
1919#include "access/attnum.h"
20+ #include "catalog/objectaddress.h"
21+ #include "catalog/pg_class.h"
22+ #include "catalog/pg_operator.h"
23+ #include "catalog/pg_proc.h"
24+ #include "catalog/pg_type.h"
2025#include "common/shortest_dec.h"
2126#include "lib/stringinfo.h"
2227#include "miscadmin.h"
@@ -30,6 +35,8 @@ static bool write_location_fields = false;
3035
3136static void outChar (StringInfo str , char c );
3237static void outDouble (StringInfo str , double d );
38+ static char * oidToString (const char * attName , Oid oid );
39+ static char * oidArrayToString (const char * attName , const Oid * oids , int len );
3340
3441
3542/*
@@ -64,7 +71,12 @@ static void outDouble(StringInfo str, double d);
6471
6572/* Write an OID field (don't hard-wire assumption that OID is same as uint) */
6673#define WRITE_OID_FIELD (fldname ) \
67- appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
74+ { \
75+ char * s = oidToString(CppAsString(fldname), node->fldname); \
76+ appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname); \
77+ if (s != NULL) \
78+ appendStringInfo(str, " # %s", s); \
79+ }
6880
6981/* Write a long-integer field */
7082#define WRITE_LONG_FIELD (fldname ) \
@@ -121,8 +133,12 @@ static void outDouble(StringInfo str, double d);
121133
122134/* Write a variable-length array of Oid */
123135#define WRITE_OID_ARRAY (fldname , len ) \
124- (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
125- writeOidCols(str, node->fldname, len))
136+ { \
137+ char *s = oidArrayToString(CppAsString(fldname), node->fldname, len); \
138+ appendStringInfoString(str, " :" CppAsString(fldname) " "); \
139+ writeOidCols(str, node->fldname, len); \
140+ if (s != NULL) appendStringInfo(str, " # %s", s); \
141+ }
126142
127143/* Write a variable-length array of Index */
128144#define WRITE_INDEX_ARRAY (fldname , len ) \
@@ -222,6 +238,69 @@ outDouble(StringInfo str, double d)
222238 appendStringInfoString (str , buf );
223239}
224240
241+ static char *
242+ oidToString (const char * attName , Oid oid )
243+ {
244+ ObjectAddress ob ;
245+
246+ ob .objectId = oid ;
247+ ob .objectSubId = 0 ;
248+ if ((strncmp (attName , "opno" , 5 ) == 0 ) ||
249+ (strncmp (attName , "eqop" , 5 ) == 0 ) ||
250+ (strncmp (attName , "sortop" , 7 ) == 0 ) ||
251+ (strncmp (attName , "sort.sortOperators" , 19 ) == 0 ))
252+ {
253+ ob .classId = OperatorRelationId ;
254+ }
255+ else if ((strncmp (attName , "opfuncid" , 9 ) == 0 ) ||
256+ (strncmp (attName , "funcid" , 7 ) == 0 ))
257+ {
258+ ob .classId = ProcedureRelationId ;
259+ }
260+ else if ((strncmp (attName , "opresulttype" , 13 ) == 0 ) ||
261+ (strncmp (attName , "vartype" , 8 ) == 0 ) ||
262+ (strncmp (attName , "consttype" , 10 ) == 0 ) ||
263+ (strncmp (attName , "funcresulttype" , 15 ) == 0 ))
264+ {
265+ ob .classId = TypeRelationId ;
266+ }
267+ else if ((strncmp (attName , "relid" , 5 ) == 0 ) ||
268+ (strncmp (attName , "indexid" , 8 ) == 0 ))
269+ {
270+ ob .classId = RelationRelationId ;
271+ }
272+ else
273+ {
274+ return NULL ;
275+ }
276+ return getObjectDescription (& ob , true);
277+ }
278+
279+ static char *
280+ oidArrayToString (const char * attName , const Oid * oids , int len )
281+ {
282+ StringInfoData str ;
283+ int i ;
284+ char * desc ;
285+
286+ initStringInfo (& str );
287+ for (i = 0 ; i < len ; i ++ )
288+ {
289+ desc = oidToString (attName , oids [i ]);
290+ if (desc != NULL )
291+ {
292+ if (i > 0 )
293+ appendStringInfoString (& str , ", " );
294+ appendStringInfo (& str , "%s" , desc );
295+ }
296+ else
297+ {
298+ return NULL ;
299+ }
300+ }
301+ return str .data ;
302+ }
303+
225304/*
226305 * common implementation for scalar-array-writing functions
227306 *
@@ -238,18 +317,22 @@ fnname(StringInfo str, const datatype *arr, int len) \
238317 { \
239318 appendStringInfoChar(str, '('); \
240319 for (int i = 0; i < len; i++) \
320+ { \
241321 appendStringInfo(str, fmtstr, convfunc(arr[i])); \
322+ if (i < len - 1) \
323+ appendStringInfoChar(str, ' '); \
324+ } \
242325 appendStringInfoChar(str, ')'); \
243326 } \
244327 else \
245328 appendStringInfoString(str, "<>"); \
246329}
247330
248- WRITE_SCALAR_ARRAY (writeAttrNumberCols , AttrNumber , " %d" ,)
249- WRITE_SCALAR_ARRAY (writeOidCols , Oid , " %u" ,)
250- WRITE_SCALAR_ARRAY (writeIndexCols , Index , " %u" ,)
251- WRITE_SCALAR_ARRAY (writeIntCols , int , " %d" ,)
252- WRITE_SCALAR_ARRAY (writeBoolCols , bool , " %s" , booltostr )
331+ WRITE_SCALAR_ARRAY (writeAttrNumberCols , AttrNumber , "%d" ,)
332+ WRITE_SCALAR_ARRAY (writeOidCols , Oid , "%u" ,)
333+ WRITE_SCALAR_ARRAY (writeIndexCols , Index , "%u" ,)
334+ WRITE_SCALAR_ARRAY (writeIntCols , int , "%d" ,)
335+ WRITE_SCALAR_ARRAY (writeBoolCols , bool , "%s" , booltostr )
253336
254337/*
255338 * Print an array (not a List) of Node pointers.
0 commit comments