Hi hackers,
Please find attached a patch proposal to avoid 2 calls to
pgstat_fetch_stat_tabentry_ext() in pgstat_fetch_stat_tabentry() in case
the relation is not a shared one and no statistics are found.
Thanks Andres for the suggestion done in [1].
[1]:
https://www.postgresql.org/message-id/20221116201202.3k74ajawyom2c3eq%40awork3.anarazel.de
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
diff --git a/src/backend/utils/activity/pgstat_relation.c
b/src/backend/utils/activity/pgstat_relation.c
index 55a355f583..a2a4fc6e2c 100644
--- a/src/backend/utils/activity/pgstat_relation.c
+++ b/src/backend/utils/activity/pgstat_relation.c
@@ -25,6 +25,7 @@
#include "utils/pgstat_internal.h"
#include "utils/rel.h"
#include "utils/timestamp.h"
+#include "catalog/catalog.h"
/* Record that's written to 2PC state file when pgstat state is persisted */
@@ -439,14 +440,8 @@ pgstat_fetch_stat_tabentry(Oid relid)
{
PgStat_StatTabEntry *tabentry;
- tabentry = pgstat_fetch_stat_tabentry_ext(false, relid);
- if (tabentry != NULL)
- return tabentry;
+ tabentry = pgstat_fetch_stat_tabentry_ext(IsSharedRelation(relid),
relid);
- /*
- * If we didn't find it, maybe it's a shared table.
- */
- tabentry = pgstat_fetch_stat_tabentry_ext(true, relid);
return tabentry;
}