88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.19 2007/05/1416:50:36 alvherre Exp $
11+ * $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.20 2007/05/1420:07:01 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -458,7 +458,7 @@ typedef struct
458458 * descriptions that depend on the shared object, or NULL if none is found.
459459 * The size of the returned string is limited to about MAX_REPORTED_DEPS lines;
460460 * if there are more objects than that, the output is returned truncated at
461- * that pointand the full message is logged to the postmaster log.
461+ * that pointwhile the full message is logged to the postmaster log.
462462 *
463463 * We can find three different kinds of dependencies: dependencies on objects
464464 * of the current database; dependencies on shared objects; and dependencies
@@ -475,8 +475,8 @@ checkSharedDependencies(Oid classId, Oid objectId)
475475ScanKeyData key [2 ];
476476SysScanDesc scan ;
477477HeapTuple tup ;
478- int numNotReportedDeps = 0 ;
479478int numReportedDeps = 0 ;
479+ int numNotReportedDeps = 0 ;
480480int numNotReportedDbs = 0 ;
481481List * remDeps = NIL ;
482482ListCell * cell ;
@@ -485,11 +485,11 @@ checkSharedDependencies(Oid classId, Oid objectId)
485485StringInfoData alldescs ;
486486
487487/*
488- * Wetry to limit the number of dependencies reported to the client to
489- *something sane, both for the user's sake and to avoid blowing out
490- *memory . The server log always gets a full report, which is collected
491- * in a separate StringInfo if and only if we detect that the original
492- * report is going to be truncated.
488+ * We limit the number of dependencies reported to the client to
489+ *MAX_REPORTED_DEPS, since client software may not deal well with
490+ *enormous error strings . The server log always gets a full report,
491+ *which is collected in a separate StringInfo if and only if we detect
492+ *that the client report is going to be truncated.
493493 */
494494#define MAX_REPORTED_DEPS 100
495495
@@ -539,9 +539,12 @@ checkSharedDependencies(Oid classId, Oid objectId)
539539 */
540540if (sdepForm -> dbid == MyDatabaseId )
541541{
542- if (++ numReportedDeps <=MAX_REPORTED_DEPS )
542+ if (numReportedDeps < MAX_REPORTED_DEPS )
543+ {
544+ numReportedDeps ++ ;
543545storeObjectDescription (& descs ,LOCAL_OBJECT ,& object ,
544546sdepForm -> deptype ,0 );
547+ }
545548else
546549{
547550numNotReportedDeps ++ ;
@@ -555,9 +558,12 @@ checkSharedDependencies(Oid classId, Oid objectId)
555558}
556559else if (sdepForm -> dbid == InvalidOid )
557560{
558- if (++ numReportedDeps <=MAX_REPORTED_DEPS )
561+ if (numReportedDeps < MAX_REPORTED_DEPS )
562+ {
563+ numReportedDeps ++ ;
559564storeObjectDescription (& descs ,SHARED_OBJECT ,& object ,
560565sdepForm -> deptype ,0 );
566+ }
561567else
562568{
563569numNotReportedDeps ++ ;
@@ -618,35 +624,22 @@ checkSharedDependencies(Oid classId, Oid objectId)
618624object .objectId = dep -> dbOid ;
619625object .objectSubId = 0 ;
620626
621- if (alldescs . len != 0 )
627+ if (numReportedDeps < MAX_REPORTED_DEPS )
622628{
623- numNotReportedDbs ++ ;
624- storeObjectDescription (& alldescs ,REMOTE_OBJECT ,& object ,
629+ numReportedDeps ++ ;
630+ storeObjectDescription (& descs ,REMOTE_OBJECT ,& object ,
625631SHARED_DEPENDENCY_INVALID ,dep -> count );
626632}
627633else
628634{
629- if (numReportedDeps <=MAX_REPORTED_DEPS )
630- {
631- numReportedDeps ++ ;
632- storeObjectDescription (& descs ,REMOTE_OBJECT ,& object ,
633- SHARED_DEPENDENCY_INVALID ,dep -> count );
634- }
635- else
636- {
637- /* initialize the server-only log line */
638- numNotReportedDbs ++ ;
635+ numNotReportedDbs ++ ;
636+ /* initialize the server-only log line */
637+ if (alldescs .len == 0 )
639638appendBinaryStringInfo (& alldescs ,descs .data ,descs .len );
640- storeObjectDescription (& alldescs ,REMOTE_OBJECT ,& object ,
641- SHARED_DEPENDENCY_INVALID ,dep -> count );
642- }
643- }
644- }
645639
646- if (numNotReportedDbs > 0 )
647- {
648- appendStringInfo (& descs ,"\nand objects in other %d databases" ,
649- numNotReportedDbs );
640+ storeObjectDescription (& alldescs ,REMOTE_OBJECT ,& object ,
641+ SHARED_DEPENDENCY_INVALID ,dep -> count );
642+ }
650643}
651644
652645list_free_deep (remDeps );
@@ -658,21 +651,28 @@ checkSharedDependencies(Oid classId, Oid objectId)
658651return NULL ;
659652}
660653
661- if (numNotReportedDbs + numNotReportedDeps > 0 )
654+ if (numNotReportedDeps > 0 )
655+ appendStringInfo (& descs ,_ ("\nand %d other objects "
656+ "(see server log for list)" ),
657+ numNotReportedDeps );
658+ if (numNotReportedDbs > 0 )
659+ appendStringInfo (& descs ,_ ("\nand objects in %d other databases "
660+ "(see server log for list)" ),
661+ numNotReportedDbs );
662+
663+ if (numNotReportedDeps > 0 || numNotReportedDbs > 0 )
662664{
663665ObjectAddress obj ;
664666
665667obj .classId = classId ;
666668obj .objectId = objectId ;
667669obj .objectSubId = 0 ;
668670ereport (LOG ,
669- (errmsg ("objects dependent on %s" ,getObjectDescription (& obj )),
671+ (errmsg ("there are objects dependent on %s" ,
672+ getObjectDescription (& obj )),
670673errdetail (alldescs .data )));
671-
672- if (numNotReportedDeps > 0 )
673- appendStringInfo (& descs ,"\nand other %d objects" ,
674- numNotReportedDeps );
675674}
675+
676676pfree (alldescs .data );
677677
678678return descs .data ;
@@ -1030,12 +1030,8 @@ storeObjectDescription(StringInfo descs, objectType type,
10301030break ;
10311031
10321032case REMOTE_OBJECT :
1033- if (count == 1 )
1034- /* translator: %s will always be "database %s" */
1035- appendStringInfo (descs ,_ ("one object in %s" ),objdesc );
1036- else
1037- /* translator: %s will always be "database %s" */
1038- appendStringInfo (descs ,_ ("%d objects in %s" ),count ,objdesc );
1033+ /* translator: %s will always be "database %s" */
1034+ appendStringInfo (descs ,_ ("%d objects in %s" ),count ,objdesc );
10391035break ;
10401036
10411037default :