pgsql: Fix nbtsort.c's page space accounting.

Поиск
Список
Период
Сортировка
От Peter Geoghegan
Тема pgsql: Fix nbtsort.c's page space accounting.
Дата
Msg-id E1hMHT8-0001wu-QN@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix nbtsort.c's page space accounting.

Commit dd299df8189, which made heap TID a tiebreaker nbtree index
column, introduced new rules on page space management to make suffix
truncation safe.  In general, suffix truncation needs to have a small
amount of extra space available on the new left page when splitting a
leaf page.  This is needed in case it turns out that truncation cannot
even "truncate away the heap TID column", resulting in a
larger-than-firstright leaf high key with an explicit heap TID
representation.

Despite all this, CREATE INDEX/nbtsort.c did not account for the
possible need for extra heap TID space on leaf pages when deciding
whether or not a new item could fit on current page.  This could lead to
"failed to add item to the index page" errors when CREATE
INDEX/nbtsort.c tried to finish off a leaf page that lacked space for a
larger-than-firstright leaf high key (it only had space for firstright
tuple, which was just short of what was needed following "truncation").

Several conditions needed to be met all at once for CREATE INDEX to
fail.  The problem was in the hard limit on what will fit on a page,
which tends to be masked by the soft fillfactor-wise limit.  The easiest
way to recreate the problem seems to be a CREATE INDEX on a low
cardinality text column, with tuples that are of non-uniform width,
using a fillfactor of 100.

To fix, bring nbtsort.c in line with nbtsplitloc.c, which already
pessimistically assumes that all leaf page splits will have high keys
that have a heap TID appended.

Reported-By: Andreas Joseph Krogh
Discussion: https://postgr.es/m/VisenaEmail.c5.3ee7fe277d514162.16a6d785bea@tc7-visena

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6dd86c269d5b9a176f6c9f67ea61cc17fef9d860

Modified Files
--------------
src/backend/access/nbtree/nbtsort.c | 60 ++++++++++++++++++++++++++-----------
1 file changed, 42 insertions(+), 18 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: pgsql: Fix some problems with VACUUM (INDEX_CLEANUP FALSE).
Следующее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: heap_prepare_freeze_tuple: Simplify coding