Re: Performance issue on temporary relations

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: 章晨曦 <zhangchenxi(at)halodbtech(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Performance issue on temporary relations
Date: 2025-08-19 15:35:51
Message-ID: 582768.1755617751@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"=?utf-8?B?56ug5pmo5pum?=" <zhangchenxi(at)halodbtech(dot)com> writes:
> Recently I noticed a performance issue on temporary relation. The issue will happened on
> ON COMMIT DELETE temporary relations. If one session only create a few temporary relations,
> well, it's fine. But if one session creates plenty of ON COMMIT DELETE kind temporary relations,
> say 3,000, it will face a significant performance degradation issue.

Do you think that's supposed to be free?

> To overcome this issue, A new list named in_use has been introduced to record the actually
> accessed temporary relations, and then will do the truncate only on the actually accessed
> temporary relations. And it seems works well.

I do not think this is something we ought to consider. It might help
certain corner use-cases, but it's probably a net loss for most.
In particular, I don't think that creating thousands of temp tables in
a session but then touching only a few of them in any one transaction
is a very plausible usage pattern.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2025-08-19 15:37:27 Re: Standardize LSN-based filename
Previous Message 章晨曦 2025-08-19 15:26:12 Performance issue on temporary relations