Commit fe280694 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Scan GiST indexes in physical order during VACUUM.

Scanning an index in physical order is faster than walking it in logical
order, because sequential I/O is faster than random I/O. The idea and code
structure is borrowed from B-tree vacuum code.

Patch by Andrey Borodin, with changes by me. Based on early work by
Konstantin Kuznetsov, although the patch has been rewritten multiple times
since his original version.

Discussion: https://www.postgresql.org/message-id/1B9FAC6F-FA19-4A24-8C1B-F4F574844892%40yandex-team.ru
parent 35bc0ec7
...@@ -38,8 +38,8 @@ static bool gistinserttuples(GISTInsertState *state, GISTInsertStack *stack, ...@@ -38,8 +38,8 @@ static bool gistinserttuples(GISTInsertState *state, GISTInsertStack *stack,
bool unlockbuf, bool unlockleftchild); bool unlockbuf, bool unlockleftchild);
static void gistfinishsplit(GISTInsertState *state, GISTInsertStack *stack, static void gistfinishsplit(GISTInsertState *state, GISTInsertStack *stack,
GISTSTATE *giststate, List *splitinfo, bool releasebuf); GISTSTATE *giststate, List *splitinfo, bool releasebuf);
static void gistvacuumpage(Relation rel, Page page, Buffer buffer, static void gistprunepage(Relation rel, Page page, Buffer buffer,
Relation heapRel); Relation heapRel);
#define ROTATEDIST(d) do { \ #define ROTATEDIST(d) do { \
...@@ -261,7 +261,7 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, ...@@ -261,7 +261,7 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate,
*/ */
if (is_split && GistPageIsLeaf(page) && GistPageHasGarbage(page)) if (is_split && GistPageIsLeaf(page) && GistPageHasGarbage(page))
{ {
gistvacuumpage(rel, page, buffer, heapRel); gistprunepage(rel, page, buffer, heapRel);
is_split = gistnospace(page, itup, ntup, oldoffnum, freespace); is_split = gistnospace(page, itup, ntup, oldoffnum, freespace);
} }
...@@ -1544,11 +1544,11 @@ freeGISTstate(GISTSTATE *giststate) ...@@ -1544,11 +1544,11 @@ freeGISTstate(GISTSTATE *giststate)
} }
/* /*
* gistvacuumpage() -- try to remove LP_DEAD items from the given page. * gistprunepage() -- try to remove LP_DEAD items from the given page.
* Function assumes that buffer is exclusively locked. * Function assumes that buffer is exclusively locked.
*/ */
static void static void
gistvacuumpage(Relation rel, Page page, Buffer buffer, Relation heapRel) gistprunepage(Relation rel, Page page, Buffer buffer, Relation heapRel)
{ {
OffsetNumber deletable[MaxIndexTuplesPerPage]; OffsetNumber deletable[MaxIndexTuplesPerPage];
int ndeletable = 0; int ndeletable = 0;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment