Make better use of the new List implementation in a couple of places

Enterprise / PostgreSQL - David Rowley [postgresql.org] - 22 July 2019 07:03 EDT

In nodeAppend.c and nodeMergeAppend.c there were some foreach loops which looped over the list of subplans and only performed any work if the subplan index was found in a Bitmapset. With the old linked list implementation of List, this form made sense as accessing the Nth list element was O(N). However, thanks to 1cff1b95a we now have array-based lists, so accessing the Nth element has become O(1).

Here we make the most of the O(1) lookups and just loop over the set members of the Bitmapset with bms_next_member(). This performs slightly better when a small number of the list items are in the Bitmapset. Micro benchmarks show that when the Bitmapset contains all or most of the list items then the new code is ever so slightly slower. In practice, the cost is so small that it's drowned out by various other things such as locking the relations belonging to each subplan, etc.

The primary goal here is to leave better code examples around which benefit better from the new list implementation.

efdcca55a3 Make better use of the new List implementation in a couple of places
src/backend/executor/nodeAppend.c | 25 ++++++++++---------------
src/backend/executor/nodeMergeAppend.c | 14 +++++---------
2 files changed, 15 insertions(+), 24 deletions(-)

Upstream: git.postgresql.org


  • Share