Re: query_id: jumble names of temp tables for better pg_stat_statement UX
Sami Imseih <samimseih@gmail.com>
From: Sami Imseih <samimseih@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Christoph Berg <myon@debian.org>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
ma lz <ma100@hotmail.com>
Date: 2025-03-25T01:51:14Z
Lists: pgsql-hackers, pgsql-general
> So your idea to use the relation name in eref while skipping the
> column list looks kind of promising. Per se the attached. Thoughts?
I feel really uneasy about this behavior becoming the default.
I can bet there are some users which run common queries across
different schemas ( e.g. multi-tenancy ) will consider this behavior a
regression
in pg_stat_statements as now all their common queries have been merged
into a single entry.
For example, I have seen users add comments to SQLs to differentiate
similar SQLs coming from different tenants. This patch makes this no longer a
somewhat decent workaround to overcome the fact that pg_stat_statements
does not track schemas or search path.
```
select pg_stat_statements_reset();
set search_path = s1;
select /*+ user s1 */ * from foo;
set search_path = s2;
select /*+ user s2 */ * from foo;
reset search_path;
select userid, queryid, query, calls from public.pg_stat_statements;
test=# select userid, queryid, query, calls from public.pg_stat_statements;
userid | queryid | query | calls
--------+----------------------+-----------------------------------+-------
10 | 1788423388555345932 | select /*+ user s1 */ * from foo | 2
10 | -8935568138104064674 | select pg_stat_statements_reset() | 1
10 | -8663970364987885379 | set search_path = $1 | 2
10 | -6563543739552933350 | reset search_path | 1
(4 rows)
```
--
Sami Imseih
Amazon Web Services (AWS)
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Use relation name instead of OID in query jumbling for RangeTblEntry
- 787514b30bb7 18.0 landed
-
Fix two issues with custom_query_jumble in gen_node_support.pl
- 27ee6ede6bc9 18.0 landed
-
pg_stat_statements: Add more tests with temp tables and namespaces
- 3430215fe35f 18.0 landed
-
Add support for custom_query_jumble as a node field attribute
- 5ac462e2b7ac 18.0 landed