pg_stat_statements: remove redundant function call in pg_stat_statements_internal

Started by Dong Wook Leealmost 4 years ago4 messages
#1Dong Wook Lee
sh95119@gmail.com
1 attachment(s)

Hi,

I found some redundant function calls in
pg_stat_statements.c/pg_stat_statements_internal(),
There is no need to call GetUserId() again because the value was
previously obtained.
so I propose a patch to fix it.

--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1508,7 +1508,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
        pgssEntry  *entry;
        /* Superusers or members of pg_read_all_stats members are allowed */
-       is_allowed_role = is_member_of_role(GetUserId(),
ROLE_PG_READ_ALL_STATS);
+       is_allowed_role = is_member_of_role(userid, ROLE_PG_READ_ALL_STATS);

/* hash table must exist already */
if (!pgss || !pgss_hash)

Regards,
Lee Dong Wook.

Attachments:

v1_tiny_improvement_pg_stat_statements.patchapplication/octet-stream; name=v1_tiny_improvement_pg_stat_statements.patchDownload
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 38d92a89cc..d803253cea 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1508,7 +1508,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
 	pgssEntry  *entry;
 
 	/* Superusers or members of pg_read_all_stats members are allowed */
-	is_allowed_role = is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS);
+	is_allowed_role = is_member_of_role(userid, ROLE_PG_READ_ALL_STATS);
 
 	/* hash table must exist already */
 	if (!pgss || !pgss_hash)
#2Julien Rouhaud
rjuju123@gmail.com
In reply to: Dong Wook Lee (#1)
Re: pg_stat_statements: remove redundant function call in pg_stat_statements_internal

Hi,

On Sun, Feb 27, 2022 at 08:45:13PM +0900, Dong Wook Lee wrote:

I found some redundant function calls in
pg_stat_statements.c/pg_stat_statements_internal(),
There is no need to call GetUserId() again because the value was
previously obtained.

Indeed. I doubt it will make any real difference but it doesn't hurt to fix
it.

Patch looks good to me.

#3Michael Paquier
michael@paquier.xyz
In reply to: Julien Rouhaud (#2)
Re: pg_stat_statements: remove redundant function call in pg_stat_statements_internal

On Sun, Feb 27, 2022 at 07:55:26PM +0800, Julien Rouhaud wrote:

Indeed. I doubt it will make any real difference but it doesn't hurt to fix
it.

Patch looks good to me.

Yes, let's clean up that on HEAD. No objections from here. I'll do
that tomorrow or so.
--
Michael

#4Michael Paquier
michael@paquier.xyz
In reply to: Michael Paquier (#3)
Re: pg_stat_statements: remove redundant function call in pg_stat_statements_internal

On Sun, Feb 27, 2022 at 09:08:56PM +0900, Michael Paquier wrote:

Yes, let's clean up that on HEAD. No objections from here. I'll do
that tomorrow or so.

And done.
--
Michael