postgres/src
Tomas Vondra bae31e75f7 Properly detoast data in brin_form_tuple
brin_form_tuple failed to consider the values may be toasted, inserting
the toast pointer into the index. This may easily result in index
corruption, as the toast data may be deleted and cleaned up by vacuum.
The cleanup however does not care about indexes, leaving invalid toast
pointers behind, which triggers errors like this:

  ERROR:  missing chunk number 0 for toast value 16433 in pg_toast_16426

A less severe consequence are inconsistent failures due to the index row
being too large, depending on whether brin_form_tuple operated on plain
or toasted version of the row. For example

    CREATE TABLE t (val TEXT);
    INSERT INTO t VALUES ('... long value ...')
    CREATE INDEX idx ON t USING brin (val);

would likely succeed, as the row would likely include toast pointer.
Switching the order of INSERT and CREATE INDEX would likely fail:

    ERROR:  index row size 8712 exceeds maximum 8152 for index "idx"

because this happens before the row values are toasted.

The bug exists since PostgreSQL 9.5 where BRIN indexes were introduced.
So backpatch all the way back.

Author: Tomas Vondra
Reviewed-by: Alvaro Herrera
Backpatch-through: 9.5
Discussion: https://postgr.es/m/20201001184133.oq5uq75sb45pu3aw@development
Discussion: https://postgr.es/m/20201104010544.zexj52mlldagzowv%40development
2020-11-07 00:41:36 +01:00
..
backend Properly detoast data in brin_form_tuple 2020-11-07 00:41:36 +01:00
bin Revert "pg_dump: Lock all relations, not just plain tables". 2020-11-06 15:48:21 -05:00
common Replace use of sys_siglist[] with strsignal(). 2020-07-15 22:05:13 -04:00
fe_utils Fix translation of special characters in psql's LaTeX output modes. 2018-11-26 17:32:51 -05:00
include doc: improve description of synchronous_commit modes 2020-10-15 15:15:28 -04:00
interfaces Fix ancient bug in ecpg's pthread_once() emulation for Windows. 2020-10-24 13:12:47 -04:00
makefiles Select CFLAGS_SL at configure time, not in platform-specific Makefiles. 2019-10-21 12:32:36 -04:00
pl Translation updates 2020-08-10 15:34:18 +02:00
port In the postmaster, rely on the signal infrastructure to block signals. 2020-10-15 12:50:57 -04:00
template Makefile comment: remove reference to tools/thread/thread_test 2020-10-27 14:00:43 -04:00
test Properly detoast data in brin_form_tuple 2020-11-07 00:41:36 +01:00
timezone Update time zone data files to tzdata release 2020d. 2020-10-22 21:24:23 -04:00
tools Sync our copy of the timezone library with IANA release tzcode2020c. 2020-10-16 21:40:16 -04:00
tutorial
.gitignore
bcc32.mak
DEVELOPERS
Makefile Install TAP test infrastructure so it's available for extension testing. 2016-09-23 15:50:00 -04:00
Makefile.global.in Select CFLAGS_SL at configure time, not in platform-specific Makefiles. 2019-10-21 12:32:36 -04:00
Makefile.shlib Ensure static libraries have correct mod time even if ranlib messes it up. 2018-11-29 15:53:44 -05:00
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00
win32.mak