From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-hackers(at)postgreSQL(dot)org |
Cc: | Victor Drobny <v(dot)drobny(at)postgrespro(dot)ru> |
Subject: | Red-black trees: why would anyone want preorder or postorder traversal? |
Date: | 2017-09-10 00:25:11 |
Message-ID: | 17735.1505003111@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
There is quite a bit of code in src/backend/lib/rbtree.c that is currently
dead according to the code coverage report, but we're hanging onto it
with the thought that somebody might use it later. That's fine as long as
there is a plausible use-case for it ... but I have to wonder what is the
argument that anyone would ever want pre-order or post-order traversal of
one of these trees (ie, the DirectWalk or InvertedWalk options to
rb_begin_iterate). Those orderings give semantic meaning to purely
accidental aspects of the tree shape, such as which specific node happens
to be the root at the moment. You could maybe argue for using them if
you didn't care about the visitation order and just wanted the cheapest,
quickest way of visiting all the nodes --- but these methods are not
cheaper, or simpler, than the left-to-right or right-to-left tree walks.
In fact, the InvertedWalk logic requires its very own extra field in
the iterator state.
Also, the reason I noticed this in the first place is that
I was working on Victor Drobny's submission in the current CF
https://commitfest.postgresql.org/14/1225/
to add a test harness for rbtree.c. That harness currently expends
much more code, and many more cycles, on testing preorder/postorder
traversal than anything else. It also has to make several assumptions
about the implementation of red-black trees that I would rather it
didn't.
In short, therefore, I propose we rip out the DirectWalk and InvertedWalk
options along with their support code, and then drop the portions of
test_rbtree that are needed to exercise them. Any objections?
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Kapila | 2017-09-10 03:17:14 | Re: UPDATE of partition key |
Previous Message | Tom Lane | 2017-09-10 00:07:00 | Re: Red-Black tree traversal tests |