8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.19 2007/05/14 16:50:36 alvherre Exp $
11
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.20 2007/05/14 20:07:01 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -458,7 +458,7 @@ typedef struct
458
458
* descriptions that depend on the shared object, or NULL if none is found.
459
459
* The size of the returned string is limited to about MAX_REPORTED_DEPS lines;
460
460
* if there are more objects than that, the output is returned truncated at
461
- * that point and the full message is logged to the postmaster log.
461
+ * that point while the full message is logged to the postmaster log.
462
462
*
463
463
* We can find three different kinds of dependencies: dependencies on objects
464
464
* of the current database; dependencies on shared objects; and dependencies
@@ -475,8 +475,8 @@ checkSharedDependencies(Oid classId, Oid objectId)
475
475
ScanKeyData key [2 ];
476
476
SysScanDesc scan ;
477
477
HeapTuple tup ;
478
- int numNotReportedDeps = 0 ;
479
478
int numReportedDeps = 0 ;
479
+ int numNotReportedDeps = 0 ;
480
480
int numNotReportedDbs = 0 ;
481
481
List * remDeps = NIL ;
482
482
ListCell * cell ;
@@ -485,11 +485,11 @@ checkSharedDependencies(Oid classId, Oid objectId)
485
485
StringInfoData alldescs ;
486
486
487
487
/*
488
- * We try 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.
493
493
*/
494
494
#define MAX_REPORTED_DEPS 100
495
495
@@ -539,9 +539,12 @@ checkSharedDependencies(Oid classId, Oid objectId)
539
539
*/
540
540
if (sdepForm -> dbid == MyDatabaseId )
541
541
{
542
- if (++ numReportedDeps <= MAX_REPORTED_DEPS )
542
+ if (numReportedDeps < MAX_REPORTED_DEPS )
543
+ {
544
+ numReportedDeps ++ ;
543
545
storeObjectDescription (& descs , LOCAL_OBJECT , & object ,
544
546
sdepForm -> deptype , 0 );
547
+ }
545
548
else
546
549
{
547
550
numNotReportedDeps ++ ;
@@ -555,9 +558,12 @@ checkSharedDependencies(Oid classId, Oid objectId)
555
558
}
556
559
else if (sdepForm -> dbid == InvalidOid )
557
560
{
558
- if (++ numReportedDeps <= MAX_REPORTED_DEPS )
561
+ if (numReportedDeps < MAX_REPORTED_DEPS )
562
+ {
563
+ numReportedDeps ++ ;
559
564
storeObjectDescription (& descs , SHARED_OBJECT , & object ,
560
565
sdepForm -> deptype , 0 );
566
+ }
561
567
else
562
568
{
563
569
numNotReportedDeps ++ ;
@@ -618,35 +624,22 @@ checkSharedDependencies(Oid classId, Oid objectId)
618
624
object .objectId = dep -> dbOid ;
619
625
object .objectSubId = 0 ;
620
626
621
- if (alldescs . len != 0 )
627
+ if (numReportedDeps < MAX_REPORTED_DEPS )
622
628
{
623
- numNotReportedDbs ++ ;
624
- storeObjectDescription (& alldescs , REMOTE_OBJECT , & object ,
629
+ numReportedDeps ++ ;
630
+ storeObjectDescription (& descs , REMOTE_OBJECT , & object ,
625
631
SHARED_DEPENDENCY_INVALID , dep -> count );
626
632
}
627
633
else
628
634
{
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 )
639
638
appendBinaryStringInfo (& alldescs , descs .data , descs .len );
640
- storeObjectDescription (& alldescs , REMOTE_OBJECT , & object ,
641
- SHARED_DEPENDENCY_INVALID , dep -> count );
642
- }
643
- }
644
- }
645
639
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
+ }
650
643
}
651
644
652
645
list_free_deep (remDeps );
@@ -658,21 +651,28 @@ checkSharedDependencies(Oid classId, Oid objectId)
658
651
return NULL ;
659
652
}
660
653
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 )
662
664
{
663
665
ObjectAddress obj ;
664
666
665
667
obj .classId = classId ;
666
668
obj .objectId = objectId ;
667
669
obj .objectSubId = 0 ;
668
670
ereport (LOG ,
669
- (errmsg ("objects dependent on %s" , getObjectDescription (& obj )),
671
+ (errmsg ("there are objects dependent on %s" ,
672
+ getObjectDescription (& obj )),
670
673
errdetail (alldescs .data )));
671
-
672
- if (numNotReportedDeps > 0 )
673
- appendStringInfo (& descs , "\nand other %d objects" ,
674
- numNotReportedDeps );
675
674
}
675
+
676
676
pfree (alldescs .data );
677
677
678
678
return descs .data ;
@@ -1030,12 +1030,8 @@ storeObjectDescription(StringInfo descs, objectType type,
1030
1030
break ;
1031
1031
1032
1032
case 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 );
1039
1035
break ;
1040
1036
1041
1037
default :
0 commit comments