RE: temp table on commit delete rows performance issue

From: Floris Van Nee <florisvannee(at)Optiver(dot)com>
To: feichanghong <feichanghong(at)qq(dot)com>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: RE: temp table on commit delete rows performance issue
Date: 2024-07-18 18:55:25
Message-ID: 1015a04ccde24dd8a0779e6f7cbdfda9@Optiver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> It seems that in your patch, WAL logging is skipped for all tables, not just
> temporary tables.

This code path is only used in two cases though:
* For the temporary tables ON COMMIT DROP
* For truncating tables that were created in the same transaction, or which
were already truncated in the same transaction (this is some special case
in the TRUNCATE command)
In both cases I believe it's not necessary to log the lock, as the table doesn't exist
on replica yet or the exclusive lock has already been obtained and logged previously.
Regular TRUNCATE commands go through a completely different code path,
as these need to be rollbackable if the transaction aborts.

> Upon further consideration, do we really need to acquire AccessExclusiveLocks
> for temporary tables? Since temporary tables can only be accessed within the
> current session, perhaps we can make the following optimizations:

This one I'm less sure of if it's correct in all cases. Logically it makes sense that no other
backends can access it, however I see some threads [1] that suggest that it's technically
possible for other backends to take locks on these tables, so it's not *that* obvious there
are no edge cases.

[1] https://postgrespro.com/list/thread-id/2477885

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Simpson 2024-07-18 18:59:35 Re: filesystem full during vacuum - space recovery issues
Previous Message Paul Jungwirth 2024-07-18 18:39:09 Re: SQL:2011 application time