From 0ed0773d920f96e2f1d2e054a81f364d45d4826d Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Tue, 25 Feb 2025 14:13:24 +0800
Subject: [PATCH v5 1/3] refactor _tocEntryRequired for STATISTICS DATA.

we don't dump STATISTICS DATA in --section=pre-data.
so in _tocEntryRequired, we evaulate "(strcmp(te->desc, "STATISTICS DATA") == 0)"
after ``switch (curSection)``.
---
 src/bin/pg_dump/pg_backup_archiver.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 632077113a4..0fc4ba04ba4 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -2932,14 +2932,6 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
 		strcmp(te->desc, "SEARCHPATH") == 0)
 		return REQ_SPECIAL;
 
-	if (strcmp(te->desc, "STATISTICS DATA") == 0)
-	{
-		if (!ropt->dumpStatistics)
-			return 0;
-		else
-			res = REQ_STATS;
-	}
-
 	/*
 	 * DATABASE and DATABASE PROPERTIES also have a special rule: they are
 	 * restored in createDB mode, and not restored otherwise, independently of
@@ -2984,10 +2976,6 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
 	if (ropt->no_subscriptions && strcmp(te->desc, "SUBSCRIPTION") == 0)
 		return 0;
 
-	/* If it's statistics and we don't want statistics, maybe ignore it */
-	if (!ropt->dumpStatistics && strcmp(te->desc, "STATISTICS DATA") == 0)
-		return 0;
-
 	/* Ignore it if section is not to be dumped/restored */
 	switch (curSection)
 	{
@@ -3008,6 +2996,15 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
 			return 0;
 	}
 
+	/* If it's statistics and we don't want statistics, ignore it */
+	if (strcmp(te->desc, "STATISTICS DATA") == 0)
+	{
+		if (!ropt->dumpStatistics)
+			return 0;
+		else
+			return REQ_STATS;
+	}
+
 	/* Ignore it if rejected by idWanted[] (cf. SortTocFromFile) */
 	if (ropt->idWanted && !ropt->idWanted[te->dumpId - 1])
 		return 0;

base-commit: f4694e0f35b218238cbc87bcf8f8f5c6639bb1d4
-- 
2.48.1

