diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 648a0c9865..dd6bad7302 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -4999,8 +4999,8 @@ printResults(StatsData *total, instr_time total_time,
 	printf("transaction type: %s\n",
 		   num_scripts == 1 ? sql_script[0].desc : "multiple scripts");
 	printf("scaling factor: %d\n", scale);
-	/* only print partitioning information if some partitioning was detected */
-	if (partition_method != PART_NONE && partition_method != PART_UNKNOWN)
+	/* print partitioning information only if there exists any partition */
+	if (partitions > 0)
 		printf("partition method: %s\npartitions: %d\n",
 				PARTITION_METHOD[partition_method], partitions);
 	printf("query mode: %s\n", QUERYMODE[querymode]);
@@ -5883,38 +5883,41 @@ main(int argc, char **argv)
 		 * on search_path settings.
 		 */
 		res = PQexec(con,
-					 "select p.partstrat, count(*) "
+					 "select count(*), p.partstrat "
 					 "from pg_catalog.pg_class as c "
-					 "left join pg_catalog.pg_partitioned_table as p on (p.partrelid = c.oid) "
-					 "left join pg_catalog.pg_inherits as i on (c.oid = i.inhparent) "
+					 "join pg_catalog.pg_partitioned_table as p on (p.partrelid = c.oid) "
+					 "join pg_catalog.pg_inherits as i on (c.oid = i.inhparent) "
 					 "where c.relname = 'pgbench_accounts' "
-					 "group by 1, c.oid");
+					 "group by 2, c.oid");
 		if (PQresultStatus(res) != PGRES_TUPLES_OK)
 		{
 			/* probably an older version, coldly assume no partitioning */
 			partition_method = PART_NONE;
 			partitions = 0;
 		}
-		else if (PQntuples(res) != 1)
+		else if (PQntuples(res) > 1)
 		{
 			/* unsure because multiple pgbench_accounts found */
 			partition_method = PART_UNKNOWN;
 			partitions = 0;
 		}
-		else
+		else if (PQntuples(res) == 1)
 		{
-			char *ps = PQgetvalue(res, 0, 0);
-
-			if (ps == NULL)
-				partition_method = PART_NONE;
-			else if (strcmp(ps, "r") == 0)
-				partition_method = PART_RANGE;
-			else if (strcmp(ps, "h") == 0)
-				partition_method = PART_HASH;
-			else /* whatever */
-				partition_method = PART_NONE;
-
-			partitions = atoi(PQgetvalue(res, 0, 1));
+			partitions = atoi(PQgetvalue(res, 0, 0));
+
+			if (partitions > 0)
+			{
+				char *ps = PQgetvalue(res, 0, 1);
+
+				Assert(ps != NULL);
+
+				if (strcmp(ps, "r") == 0)
+					partition_method = PART_RANGE;
+				else if (strcmp(ps, "h") == 0)
+					partition_method = PART_HASH;
+				else /* whatever */
+					partition_method = PART_NONE;
+			}
 		}
 		PQclear(res);
 	}
