Re: support fix query_id for temp table

From: Christoph Berg <myon(at)debian(dot)org>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, ma lz <ma100(at)hotmail(dot)com>
Subject: Re: support fix query_id for temp table
Date: 2025-03-17 21:38:36
Message-ID: Z9iWXKGwkm8RAC93@msg.df7cb.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Re: Michael Paquier
> On Thu, Feb 01, 2024 at 07:37:32AM +0000, ma lz wrote:
> > session 1:
> > create temp table ttt ( a int );
> > insert into ttt values(3); -- query_id is XXX from pg_stat_activity
> >
> > session 2:
> > create temp table ttt ( a int );
> > insert into ttt values(3); -- query_id is YYY from pg_stat_activity
> >
> > I know temp table has different oid, so query_id is different, is
> > there a way to use table name for temp table instead of oid?
>
> The CREATE TABLE statements have indeed the same query ID (in 16~),
> and the inserts have a different one as they touch different schemas
> and relations. That's quite an old problem, that depends on the
> RangeVar attached to an InsertStmt. I don't quite see a way to
> directly handle that except by using a custom implementation in query
> jumbling for this node and its RangeVar, so there is no "easy" way to
> tackle that :/

A customer reported that pg_stat_statements is not useful for them
because they are seeing 160k different query ids in 6-8 hours. They
also proposed to use the temp table name for query jumbling and wrote
a patch for it, which I would also see as the obvious solution to the
problem.

Here's that patch with regression tests added. I would think changing
this would be a big usability improvement for anyone using temp tables
a lot.

There does not seem to be a performance impact - all test were run
with pg_stat_statements active:

Standard pgbench -S (-s 10):
without patch: tps = 154155.407337 (without initial connection time)
with patch: tps = 154223.966534 (without initial connection time)

pgbench -S on temp tables where each table has just one record:
without patch: tps = 184430.801954 (without initial connection time)
with patch: tps = 185692.602764 (without initial connection time)

Christoph

Attachment Content-Type Size
v1-0001-Jumble-temp-tables-by-name.patch text/x-diff 5.5 KB
perf.txt text/plain 7.7 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2025-03-18 03:56:42 Re: support fix query_id for temp table
Previous Message E-BLOKOS 2025-03-17 20:52:34 Cannot pg_dump_all anymore...

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2025-03-17 21:46:04 Re: BitmapHeapScan streaming read user and prelim refactoring
Previous Message Melanie Plageman 2025-03-17 20:53:57 Re: AIO v2.5