v1-0001-misc-minor-refactoring.no-cfbot

application/octet-stream

Filename: v1-0001-misc-minor-refactoring.no-cfbot
Type: application/octet-stream
Part: 0
Message: Re: Statistics Import and Export
From 95a12a8ae143f12569d92a483904ed36a116d80d Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Sat, 18 Jan 2025 23:27:42 +0800
Subject: [PATCH v1 1/1] misc minor refactoring.

---
 src/bin/pg_dump/pg_dump.c    | 13 ++++++++++---
 src/bin/pg_dump/pg_restore.c | 14 ++++++++++----
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 9e7cb2c48f..4a2e3e123c 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -818,9 +818,16 @@ main(int argc, char **argv)
 		pg_fatal("option --if-exists requires option -c/--clean");
 
 	/* set derivative flags */
-	dopt.dumpData = data_only || (!schema_only && !statistics_only && !dopt.no_data);
-	dopt.dumpSchema = schema_only || (!data_only && !statistics_only && !dopt.no_schema);
-	dopt.dumpStatistics = statistics_only || (!data_only && !schema_only && !dopt.no_statistics);
+	dopt.dumpData = data_only || (!schema_only && !statistics_only);
+	dopt.dumpSchema = schema_only || (!data_only && !statistics_only);
+	dopt.dumpStatistics = statistics_only || (!data_only && !schema_only);
+
+	if (dopt.no_data)
+		dopt.dumpData = false;
+	if (dopt.no_schema)
+		dopt.dumpSchema = false;
+	if (dopt.no_statistics)
+		dopt.dumpStatistics = false;
 
 	/*
 	 * --inserts are already implied above if --column-inserts or
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 9586bd032c..0e0e6edc0a 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -112,7 +112,7 @@ main(int argc, char **argv)
 		{"username", 1, NULL, 'U'},
 		{"verbose", 0, NULL, 'v'},
 		{"single-transaction", 0, NULL, '1'},
-		{"statistics-only", no_argument, NULL, 'P'},
+		{"statistics-only", no_argument, NULL, 'X'},
 
 		/*
 		 * the following options don't have an equivalent short option letter
@@ -378,9 +378,15 @@ main(int argc, char **argv)
 		pg_fatal("cannot specify both --single-transaction and multiple jobs");
 
 	/* set derivative flags */
-	opts->dumpData = data_only || (!no_data && !schema_only && !statistics_only);
-	opts->dumpSchema = schema_only || (!no_schema && !data_only && !statistics_only);
-	opts->dumpStatistics = statistics_only || (!no_statistics && !data_only && !schema_only);
+	opts->dumpData = data_only || (!schema_only && !statistics_only);
+	opts->dumpSchema = schema_only || (!data_only && !statistics_only);
+	opts->dumpStatistics = statistics_only || (!data_only && !schema_only);
+	if (no_data)
+		opts->dumpData = false;
+	if (no_schema)
+		opts->dumpSchema = false;
+	if (no_statistics)
+		opts->dumpStatistics = false;
 
 	opts->disable_triggers = disable_triggers;
 	opts->enable_row_security = enable_row_security;
-- 
2.34.1