postgresql/src/include/access
Tom Lane 0dc6bf633a Allow btree comparison functions to return INT_MIN.
Historically we forbade datatype-specific comparison functions from
returning INT_MIN, so that it would be safe to invert the sort order
just by negating the comparison result.  However, this was never
really safe for comparison functions that directly return the result
of memcmp(), strcmp(), etc, as POSIX doesn't place any such restriction
on those library functions.  Buildfarm results show that at least on
recent Linux on s390x, memcmp() actually does return INT_MIN sometimes,
causing sort failures.

The agreed-on answer is to remove this restriction and fix relevant
call sites to not make such an assumption; code such as "res = -res"
should be replaced by "INVERT_COMPARE_RESULT(res)".  The same is needed
in a few places that just directly negated the result of memcmp or
strcmp.

To help find places having this problem, I've also added a compile option
to nbtcompare.c that causes some of the commonly used comparators to
return INT_MIN/INT_MAX instead of their usual -1/+1.  It'd likely be
a good idea to have at least one buildfarm member running with
"-DSTRESS_SORT_INT_MIN".  That's far from a complete test of course,
but it should help to prevent fresh introductions of such bugs.

This is a longstanding portability hazard, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/20180928185215.ffoq2xrq5d3pafna@alap3.anarazel.de
2018-10-05 16:01:30 -04:00
..
attnum.h Fix various typos and grammar errors in comments. 2015-04-26 18:42:31 +02:00
brin.h Fix BRIN to use SnapshotAny during summarization 2015-08-05 16:20:50 -03:00
brin_internal.h Add BRIN infrastructure for "inclusion" opclasses 2015-05-15 18:05:22 -03:00
brin_page.h Close some holes in BRIN page assignment 2015-08-12 14:20:38 -03:00
brin_pageops.h Close some holes in BRIN page assignment 2015-08-12 14:20:38 -03:00
brin_revmap.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
brin_tuple.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
brin_xlog.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
clog.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
commit_ts.h Rename (new|old)estCommitTs to (new|old)estCommitTsXid 2015-12-28 12:35:16 -08:00
genam.h More fixes for lossy-GiST-distance-functions patch. 2015-05-21 19:47:48 -04:00
gin.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
gin_private.h Fix memory leak and other bugs in ginPlaceToPage() & subroutines. 2016-04-20 14:25:15 -04:00
gist.h Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
gist_private.h Fix outdated comments, GIST search queue is not an RBTree anymore. 2016-09-20 11:40:20 +03:00
gistscan.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
hash.h Fix building of large (bigger than shared_buffers) hash indexes. 2016-06-24 16:57:36 -04:00
heapam.h Perform a lot more sanity checks when freezing tuples. 2017-12-14 18:20:48 -08:00
heapam_xlog.h Perform a lot more sanity checks when freezing tuples. 2017-12-14 18:20:48 -08:00
hio.h Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE. 2015-05-08 05:43:10 +02:00
htup.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
htup_details.h Change some test macros to return true booleans 2017-01-18 18:06:13 -03:00
itup.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
multixact.h Remove legacy multixact truncation support. 2015-09-26 19:04:25 +02:00
nbtree.h Allow btree comparison functions to return INT_MIN. 2018-10-05 16:01:30 -04:00
parallel.h Don't use bgw_main even to specify in-core bgworker entrypoints. 2017-03-31 20:50:31 -04:00
printtup.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
reloptions.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
relscan.h Fix some oversights in BRIN patch. 2015-07-21 13:38:24 -04:00
rewriteheap.h Collection of typo fixes. 2015-05-20 16:56:22 +03:00
rmgr.h Add rmgr callback to name xlog record types for display purposes. 2014-09-19 16:20:29 +02:00
rmgrlist.h Collection of typo fixes. 2015-05-20 16:56:22 +03:00
sdir.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
skey.h Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
slru.h Rework the way multixact truncations work. 2015-09-26 19:04:25 +02:00
spgist.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
spgist_private.h Don't assume that 'char' is signed. 2015-07-27 21:51:49 +03:00
stratnum.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
subtrans.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
sysattr.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
timeline.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
transam.h Rename (new|old)estCommitTs to (new|old)estCommitTsXid 2015-12-28 12:35:16 -08:00
tsmapi.h Redesign tablesample method API, and do extensive code review. 2015-07-25 14:39:00 -04:00
tupconvert.h Fix ALTER TABLE / SET TYPE for irregular inheritance 2017-01-09 19:26:58 -03:00
tupdesc.h Backpatch introduction of TupleDescAttr(tupdesc, i). 2017-08-22 07:47:46 -07:00
tupmacs.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
tuptoaster.h Fix deletion of speculatively inserted TOAST on conflict 2016-08-17 17:03:36 -07:00
twophase.h Mark assorted variables PGDLLIMPORT. 2017-12-05 09:30:57 -05:00
twophase_rmgr.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
valid.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
visibilitymap.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
xact.h Fix typos in comments. 2017-02-06 11:34:18 +02:00
xlog.h Remove files signaling a standby promotion request at postmaster startup 2015-09-09 22:52:28 +09:00
xlog_fn.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
xlog_internal.h Fix comment. 2017-08-01 08:08:47 +09:00
xlogdefs.h Introduce replication progress tracking infrastructure. 2015-04-29 19:30:53 +02:00
xloginsert.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
xlogreader.h Fix scenario where streaming standby gets stuck at a continuation record. 2018-05-05 01:35:15 +03:00
xlogrecord.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
xlogutils.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00