postgresql/src/backend
Tomas Vondra 7577dd8480 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:39:19 +01:00
..
access Properly detoast data in brin_form_tuple 2020-11-07 00:39:19 +01:00
bootstrap Don't use custom OID symbols in pg_type.dat, either. 2020-10-29 13:33:38 -04:00
catalog Remove useless entries for aggregate functions from fmgrtab.c. 2020-11-04 11:25:56 -05:00
commands Revert "Accept relations of any kind in LOCK TABLE". 2020-11-06 16:17:56 -05:00
executor Remove useless entries for aggregate functions from fmgrtab.c. 2020-11-04 11:25:56 -05:00
foreign Update copyrights for 2020 2020-01-01 12:21:45 -05:00
jit llvmjit: Work around bug in LLVM 3.9 causing crashes after 72559438f9. 2020-10-15 18:17:00 -07:00
lib Use pg_bitutils for HyperLogLog. 2020-07-30 09:14:23 -07:00
libpq Improve error handling in backend OpenSSL implementation 2020-11-03 09:55:51 +01:00
main Clean up includes of s_lock.h. 2020-06-18 19:41:05 -07:00
nodes Improve our ability to regurgitate SQL-syntax function calls. 2020-11-04 12:34:50 -05:00
optimizer Fix get_useful_pathkeys_for_relation for volatile expressions 2020-11-03 22:31:57 +01:00
parser Improve our ability to regurgitate SQL-syntax function calls. 2020-11-04 12:34:50 -05:00
partitioning Fix some grammar and typos in comments and docs 2020-11-02 15:14:41 +09:00
po Translation updates 2020-05-18 12:49:30 +02:00
port Fix -Wcast-function-type warnings on Windows/MinGW 2020-10-21 08:17:51 +02:00
postmaster Add pg_strong_random_init function to initialize random number generator 2020-11-06 13:21:28 +01:00
regex Dial back -Wimplicit-fallthrough to level 3 2020-05-13 15:31:14 -04:00
replication Use Enum for top level logical replication message types. 2020-11-02 08:18:18 +05:30
rewrite Calculate extraUpdatedCols in query rewriter, not parser. 2020-10-28 13:47:02 -04:00
snowball code: replace most remaining uses of 'master'. 2020-07-08 13:24:35 -07:00
statistics Fix some grammar and typos in comments and docs 2020-11-02 15:14:41 +09:00
storage Revert pg_relation_check_pages() 2020-11-04 10:21:46 +09:00
tcop Remove pg_collation.collversion. 2020-11-03 00:44:59 +13:00
tsearch Improve behavior of tsearch_readline(), and remove t_readline(). 2020-09-23 20:26:58 -04:00
utils Improve our ability to regurgitate SQL-syntax function calls. 2020-11-04 12:34:50 -05:00
.gitignore
common.mk
Makefile Update copyrights for 2020 2020-01-01 12:21:45 -05:00
nls.mk Add missing gettext triggers 2020-04-28 13:35:40 +02:00