Re: Improve eviction algorithm in ReorderBuffer
Masahiko Sawada <sawada.mshk@gmail.com>
From: Masahiko Sawada <sawada.mshk@gmail.com>
To: Euler Taveira <euler@eulerto.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-12-16T12:13:54Z
Lists: pgsql-hackers
On Sat, Dec 16, 2023 at 1:36 AM Euler Taveira <euler@eulerto.com> wrote: > > On Fri, Dec 15, 2023, at 9:11 AM, Masahiko Sawada wrote: > > > I assume you mean to add ReorderBufferTXN entries to the binaryheap > and then build it by comparing their sizes (i.e. txn->size). But > ReorderBufferTXN entries are removed and deallocated once the > transaction finished. How can we efficiently remove these entries from > binaryheap? I guess it would be O(n) to find the entry among the > unordered entries, where n is the number of transactions in the > reorderbuffer. > > > O(log n) for both functions: binaryheap_remove_first() and > binaryheap_remove_node(). Right. The binaryheap_binaryheap_remove_first() removes the topmost entry in O(log n), but the ReorderBufferTXN being removed is not necessarily the topmost entry, since we remove the entry when the transaction completes (committed or aborted). The binaryheap_remove_node() removes the entry at the given Nth in O(log n), but I'm not sure how we can know the indexes of each entry. I think we can remember the index of newly added entry after calling binaryheap_add_unordered() but once we call binaryheap_build() the index is out-of-date. So I think that in the worst case we would need to check all entries in order to remove an arbitrary entry in binaryheap. It's O(n). I might be missing something though. > I didn't read your patch but do you really need to > free entries one by one? If not, binaryheap_free(). The patch doesn't touch on how to free entries. ReorderBufferTXN entries are freed one by one after each of which completes (committed or aborted). Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
Commits
-
Revert indexed and enlargable binary heap implementation.
- 810f64a01567 17.0 landed
-
Replace binaryheap + index with pairingheap in reorderbuffer.c
- efb8acc0d058 17.0 landed
-
Improve eviction algorithm in ReorderBuffer using max-heap for many subtransactions.
- 5bec1d6bc5e3 17.0 landed
-
Add functions to binaryheap for efficient key removal and update.
- b84050864415 17.0 landed
-
Make binaryheap enlargeable.
- bcb14f4abca0 17.0 landed