postgresql/src
Tom Lane 2f5b8eb5a2 Clean up some ad-hoc code for sorting and de-duplicating Lists.
heap.c and relcache.c contained nearly identical copies of logic
to insert OIDs into an OID list while preserving the list's OID
ordering (and rejecting duplicates, in one case but not the other).

The comments argue that this is faster than qsort for small numbers
of OIDs, which is at best unproven, and seems even less likely to be
true now that lappend_cell_oid has to move data around.  In any case
it's ugly and hard-to-follow code, and if we do have a lot of OIDs
to consider, it's O(N^2).

Hence, replace with simply lappend'ing OIDs to a List, then list_sort
the completed List, then remove adjacent duplicates if necessary.
This is demonstrably O(N log N) and it's much simpler for the
callers.  It's possible that this would be somewhat inefficient
if there were a very large number of duplicates, but that seems
unlikely in the existing usage.

This adds list_deduplicate_oid and list_oid_cmp infrastructure
to list.c.  I didn't bother with equivalent functionality for
integer or pointer Lists, but such could always be added later
if we find a use for it.

Discussion: https://postgr.es/m/26193.1563228600@sss.pgh.pa.us
2019-07-16 12:04:06 -04:00
..
backend Clean up some ad-hoc code for sorting and de-duplicating Lists. 2019-07-16 12:04:06 -04:00
bin Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
common Use consistent style for checking return from system calls 2019-07-07 15:28:49 +02:00
fe_utils Use appendStringInfoString and appendPQExpBufferStr where possible 2019-07-04 13:01:13 +12:00
include Clean up some ad-hoc code for sorting and de-duplicating Lists. 2019-07-16 12:04:06 -04:00
interfaces Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
makefiles Remove support for non-ELF BSD systems 2019-07-01 23:56:20 +01:00
pl Represent Lists as expansible arrays, not chains of cons-cells. 2019-07-15 13:41:58 -04:00
port Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
template Yet further rethinking of build changes for macOS Mojave. 2018-11-02 18:54:00 -04:00
test Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
timezone Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
tools Fix some inconsistencies in MSVC scripts 2019-07-13 16:51:31 +09:00
tutorial Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
.gitignore
DEVELOPERS
Makefile Fix partial-build problems introduced by having more generated headers. 2018-04-09 16:42:10 -04:00
Makefile.global.in Remove support for non-ELF BSD systems 2019-07-01 23:56:20 +01:00
Makefile.shlib Remove support for non-ELF BSD systems 2019-07-01 23:56:20 +01:00
nls-global.mk Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00