Re: Improve eviction algorithm in ReorderBuffer - Mailing list pgsql-hackers
From | Masahiko Sawada |
---|---|
Subject | Re: Improve eviction algorithm in ReorderBuffer |
Date | |
Msg-id | CAD21AoCveeJopoZ_raNdT80GMqntOFQe558zFuC4w9s=zzWd4Q@mail.gmail.com Whole thread Raw |
In response to | Re: Improve eviction algorithm in ReorderBuffer (Peter Smith <smithpb2250@gmail.com>) |
Responses |
Re: Improve eviction algorithm in ReorderBuffer
|
List | pgsql-hackers |
On Wed, Mar 13, 2024 at 10:15 AM Peter Smith <smithpb2250@gmail.com> wrote: > > On Tue, Mar 12, 2024 at 4:23 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote: > > > > On Fri, Mar 8, 2024 at 12:58 PM Peter Smith <smithpb2250@gmail.com> wrote: > > > > ... > > > > > 5. > > > > > + * > > > > > + * If 'indexed' is true, we create a hash table to track of each node's > > > > > + * index in the heap, enabling to perform some operations such as removing > > > > > + * the node from the heap. > > > > > */ > > > > > binaryheap * > > > > > -binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg) > > > > > +binaryheap_allocate(int capacity, binaryheap_comparator compare, > > > > > + bool indexed, void *arg) > > > > > > > > > > BEFORE > > > > > ... enabling to perform some operations such as removing the node from the heap. > > > > > > > > > > SUGGESTION > > > > > ... to help make operations such as removing nodes more efficient. > > > > > > > > > > > > > But these operations literally require the indexed binary heap as we > > > > have an assertion: > > > > > > > > void > > > > binaryheap_remove_node_ptr(binaryheap *heap, bh_node_type d) > > > > { > > > > bh_nodeidx_entry *ent; > > > > > > > > Assert(!binaryheap_empty(heap) && heap->bh_has_heap_property); > > > > Assert(heap->bh_indexed); > > > > > > > > > > I didn’t quite understand -- the operations mentioned are "operations > > > such as removing the node", but binaryheap_remove_node() also removes > > > a node from the heap. So I still felt the comment wording of the patch > > > is not quite correct. > > > > Now I understand your point. That's a valid point. > > > > > > > > Now, if the removal of a node from an indexed heap can *only* be done > > > using binaryheap_remove_node_ptr() then: > > > - the other removal functions (binaryheap_remove_*) probably need some > > > comments to make sure nobody is tempted to call them directly for an > > > indexed heap. > > > - maybe some refactoring and assertions are needed to ensure those > > > *cannot* be called directly for an indexed heap. > > > > > > > If the 'index' is true, the caller can not only use the existing > > functions but also newly added functions such as > > binaryheap_remove_node_ptr() and binaryheap_update_up() etc. How about > > something like below? > > > > You said: "can not only use the existing functions but also..." > > Hmm. Is that right? IIUC those existing "remove" functions should NOT > be called directly if the heap was "indexed" because they'll delete > the node from the heap OK, but any corresponding index for that > deleted node will be left lying around -- i.e. everything gets out of > sync. This was the reason for my original concern. > All existing binaryheap functions should be available even if the binaryheap is 'indexed'. For instance, with the patch, binaryheap_remote_node() is: void binaryheap_remove_node(binaryheap *heap, int n) { int cmp; Assert(!binaryheap_empty(heap) && heap->bh_has_heap_property); Assert(n >= 0 && n < heap->bh_size); /* compare last node to the one that is being removed */ cmp = heap->bh_compare(heap->bh_nodes[--heap->bh_size], heap->bh_nodes[n], heap->bh_arg); /* remove the last node, placing it in the vacated entry */ replace_node(heap, n, heap->bh_nodes[heap->bh_size]); /* sift as needed to preserve the heap property */ if (cmp > 0) sift_up(heap, n); else if (cmp < 0) sift_down(heap, n); } The replace_node(), sift_up() and sift_down() update node's index as well if the binaryheap is indexed. When deleting the node from the binaryheap, it will also delete its index from the hash table. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
pgsql-hackers by date: