postgresql/src/backend/access
Tom Lane d97b714a21 Avoid using lcons and list_delete_first where it's easy to do so.
Formerly, lcons was about the same speed as lappend, but with the new
List implementation, that's not so; with a long List, data movement
imposes an O(N) cost on lcons and list_delete_first, but not lappend.

Hence, invent list_delete_last with semantics parallel to
list_delete_first (but O(1) cost), and change various places to use
lappend and list_delete_last where this can be done without much
violence to the code logic.

There are quite a few places that construct result lists using lcons not
lappend.  Some have semantic rationales for that; I added comments about
it to a couple that didn't have them already.  In many such places though,
I think the coding is that way only because back in the dark ages lcons
was faster than lappend.  Hence, switch to lappend where this can be done
without causing semantic changes.

In ExecInitExprRec(), this results in aggregates and window functions that
are in the same plan node being executed in a different order than before.
Generally, the executions of such functions ought to be independent of
each other, so this shouldn't result in visibly different query results.
But if you push it, as one regression test case does, you can show that
the order is different.  The new order seems saner; it's closer to
the order of the functions in the query text.  And we never documented
or promised anything about this, anyway.

Also, in gistfinishsplit(), don't bother building a reverse-order list;
it's easy now to iterate backwards through the original list.

It'd be possible to go further towards removing uses of lcons and
list_delete_first, but it'd require more extensive logic changes,
and I'm not convinced it's worth it.  Most of the remaining uses
deal with queues that probably never get long enough to be worth
sweating over.  (Actually, I doubt that any of the changes in this
patch will have measurable performance effects either.  But better
to have good examples than bad ones in the code base.)

Patch by me, thanks to David Rowley and Daniel Gustafsson for review.

Discussion: https://postgr.es/m/21272.1563318411@sss.pgh.pa.us
2019-07-17 11:15:34 -04:00
..
brin Fix many typos and inconsistencies 2019-07-01 10:00:23 +09:00
common Represent Lists as expansible arrays, not chains of cons-cells. 2019-07-15 13:41:58 -04:00
gin Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
gist Avoid using lcons and list_delete_first where it's easy to do so. 2019-07-17 11:15:34 -04:00
hash Fix more typos and inconsistencies in the tree 2019-06-17 16:13:16 +09:00
heap tableam: Provide helper functions for relation sizing. 2019-07-08 14:51:53 -04:00
index Update comment 2019-06-27 15:57:14 +02:00
nbtree Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
rmgrdesc Use appendStringInfoString and appendPQExpBufferStr where possible 2019-07-04 13:01:13 +12:00
spgist Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
table tableam: Provide helper functions for relation sizing. 2019-07-08 14:51:53 -04:00
tablesample Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
transam Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
Makefile Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00