Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relfrozenxid, relminmxid and relallvisible on table data files swap #157

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions lib/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ swap_heap_or_index_files(Oid r1, Oid r2)
Form_pg_class relform1,
relform2;
Oid swaptemp;
TransactionId swaptempxid;
CatalogIndexState indstate;

/* We need writable copies of both pg_class tuples. */
Expand Down Expand Up @@ -1128,15 +1129,18 @@ swap_heap_or_index_files(Oid r1, Oid r2)
relform1->reltoastrelid = relform2->reltoastrelid;
relform2->reltoastrelid = swaptemp;

/* set rel1's frozen Xid to larger one */
if (TransactionIdIsNormal(relform1->relfrozenxid))
{
if (TransactionIdFollows(relform1->relfrozenxid,
relform2->relfrozenxid))
relform1->relfrozenxid = relform2->relfrozenxid;
else
relform2->relfrozenxid = relform1->relfrozenxid;
}
/*
* Swap relfrozenxid and relminmxid, as they must be consistent with the data
*/
swaptemp = relform1->relfrozenxid;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swaptempxid not swaptemp should be initialized here

relform1->relfrozenxid = relform2->relfrozenxid;
relform2->relfrozenxid = swaptempxid;

#if PG_VERSION_NUM >= 90300
swaptemp = relform1->relminmxid;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swaptempxid not swaptemp should be initialized here

relform1->relminmxid = relform2->relminmxid;
relform2->relminmxid = swaptempxid;
#endif

/* swap size statistics too, since new rel has freshly-updated stats */
{
Expand All @@ -1154,6 +1158,12 @@ swap_heap_or_index_files(Oid r1, Oid r2)
swap_tuples = relform1->reltuples;
relform1->reltuples = relform2->reltuples;
relform2->reltuples = swap_tuples;

#if PG_VERSION_NUM >= 90200
swap_pages = relform1->relallvisible;
relform1->relallvisible = relform2->relallvisible;
relform2->relallvisible = swap_pages;
#endif
}

indstate = CatalogOpenIndexes(relRelation);
Expand Down