From: | Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Rewrite the GiST insertion logic so that we don't need the post- |
Date: | 2010-12-23 14:26:42 |
Message-ID: | E1PVm7u-0001Pe-SA@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Rewrite the GiST insertion logic so that we don't need the post-recovery
cleanup stage to finish incomplete inserts or splits anymore. There was two
reasons for the cleanup step:
1. When a new tuple was inserted to a leaf page, the downlink in the parent
needed to be updated to contain (ie. to be consistent with) the new key.
Updating the parent in turn might require recursively updating the parent of
the parent. We now handle that by updating the parent while traversing down
the tree, so that when we insert the leaf tuple, all the parents are already
consistent with the new key, and the tree is consistent at every step.
2. When a page is split, we need to insert the downlink for the new right
page(s), and update the downlink for the original page to not include keys
that moved to the right page(s). We now handle that by setting a new flag,
F_FOLLOW_RIGHT, on the non-rightmost pages in the split. When that flag is
set, scans always follow the rightlink, regardless of the NSN mechanism used
to detect concurrent page splits. That way the tree is consistent right after
split, even though the downlink is still missing. This is very similar to the
way B-tree splits are handled. When the downlink is inserted in the parent,
the flag is cleared. To keep the insertion algorithm simple, when an
insertion sees an incomplete split, indicated by the F_FOLLOW_RIGHT flag, it
finishes the split before doing anything else.
These changes allow removing the whole "invalid tuple" mechanism, but I
retained the scan code to still follow invalid tuples correctly. While we
don't create any such tuples anymore, we want to handle them gracefully in
case you pg_upgrade a GiST index that has them. If we encounter any on an
insert, though, we just throw an error saying that you need to REINDEX.
The issue that got me into doing this is that if you did a checkpoint while
an insert or split was in progress, and the checkpoint finishes quickly so
that there is no WAL record related to the insert between RedoRecPtr and the
checkpoint record, recovery from that checkpoint would not know to finish
the incomplete insert. IOW, we have the same issue we solved with the
rm_safe_restartpoint mechanism during normal operation too. It's highly
unlikely to happen in practice, and this fix is far too large to backpatch,
so we're just going to live with in previous versions, but this refactoring
fixes it going forward.
With this patch, you don't get the annoying
'index "FOO" needs VACUUM or REINDEX to finish crash recovery' notices
anymore if you crash at an unfortunate moment.
Branch
------
master
Details
-------
http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=9de3aa65f01fb51cbc725e8508ea233e4e92c46c
Modified Files
--------------
doc/src/sgml/gist.sgml | 29 -
src/backend/access/gist/README | 181 ++++---
src/backend/access/gist/gist.c | 1009 ++++++++++++++++++++++------------
src/backend/access/gist/gistget.c | 10 +-
src/backend/access/gist/gistsplit.c | 60 --
src/backend/access/gist/gistutil.c | 28 +-
src/backend/access/gist/gistvacuum.c | 57 +--
src/backend/access/gist/gistxlog.c | 797 ++++++---------------------
src/backend/access/transam/rmgr.c | 2 +-
src/include/access/gist.h | 11 +-
src/include/access/gist_private.h | 81 ++--
11 files changed, 1030 insertions(+), 1235 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Meskes | 2010-12-23 19:46:46 | pgsql: Added rule to ecpg lexer to accept "Unicode surrogate pair in ex |
Previous Message | Hiroshi Saito | 2010-12-23 06:06:56 | psqlodbc - psqlodbc: add some changes. |