From 08cfa5981e17d9daaa861520a1d41259748732b8 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 2 Nov 2021 11:31:54 -0400 Subject: Avoid O(N^2) behavior in SyncPostCheckpoint(). As in commits 6301c3ada and e9d9ba2a4, avoid doing repetitive list_delete_first() operations, since that would be expensive when there are many files waiting to be unlinked. This is a slightly larger change than in those cases. We have to keep the list state valid for calls to AbsorbSyncRequests(), so it's necessary to invent a "canceled" field instead of immediately deleting PendingUnlinkEntry entries. Also, because we might not be able to process all the entries, we need a new list primitive list_delete_first_n(). list_delete_first_n() is almost list_copy_tail(), but it modifies the input List instead of making a new copy. I found a couple of existing uses of the latter that could profitably use the new function. (There might be more, but the other callers look like they probably shouldn't overwrite the input List.) As before, back-patch to v13. Discussion: https://postgr.es/m/CD2F0E7F-9822-45EC-A411-AE56F14DEA9F@amazon.com --- src/include/nodes/pg_list.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/include') diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index 30f98c4595f..c3f47db888f 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -564,6 +564,7 @@ extern pg_nodiscard List *list_delete_int(List *list, int datum); extern pg_nodiscard List *list_delete_oid(List *list, Oid datum); extern pg_nodiscard List *list_delete_first(List *list); extern pg_nodiscard List *list_delete_last(List *list); +extern pg_nodiscard List *list_delete_first_n(List *list, int n); extern pg_nodiscard List *list_delete_nth_cell(List *list, int n); extern pg_nodiscard List *list_delete_cell(List *list, ListCell *cell); -- cgit v1.2.3