Re: Add privileges test for pg_stat_statements to improve coverage

From: kuroda(dot)keisuke(at)nttcom(dot)co(dot)jp
To: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add privileges test for pg_stat_statements to improve coverage
Date: 2024-07-22 06:23:41
Message-ID: b860741e6dc26ed7ee9526cef2dddb41@nttcom.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Fujii-san,
Thank you for your reply and comment!

attach v2 fixed patch.

> meson.build needs to be updated as well, like the Makefile.

Yes.
Update 'contrib/pg_stat_statements/meson.build'.

> For the privileges test, should we explicitly set
> pg_stat_statements.track_utility
> at the start, as done in other pg_stat_statements tests, to make sure
> if utility command statistics are collected or not?

It certainly needs consideration.
I think the results of the utility commands are not needed in privileges
test.
SET 'pg_stat_statements.track_utility = FALSE'.

> Can't we simplify "CASE ... END" to just "queryid <> 0"?

Yes.
If we add "queryid <> 0" to the WHERE clause, we can get the same
result.
Change the SQL to the following:

+SELECT query, calls, rows FROM pg_stat_statements
+ WHERE queryid <> 0 ORDER BY query COLLATE "C";

> Should the test check not only queryid and query but also
> the statistics column like "calls"? Roles that aren't superusers
> or pg_read_all_stats should be able to see statistics but not
> query or queryid. So we should test that such roles can't see
> query or queryid but can see statistics. Thoughts?

I agree. We should test that such roles can't see
query or queryid but can see statistics.
Add the SQL to the test.
Test that calls and rows are displayed even if the queryid is NULL.

+-- regress_stats_user1 can read calls and rows
+-- executed by other users
+--
+
+SET ROLE regress_stats_user1;
+SELECT query, calls, rows FROM pg_stat_statements
+ WHERE queryid IS NULL ORDER BY query COLLATE "C";

Best Regards,
Keisuke Kuroda
NTT Comware

Attachment Content-Type Size
V2_add_privileges_test_for_pg_stat_statements.patch text/x-diff 5.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2024-07-22 06:37:22 Re: proposal: schema variables
Previous Message Michael Paquier 2024-07-22 06:05:50 Re: Incremental backup from a streaming replication standby