Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb40776d

Browse files
committed
Have CLUSTER advance the table's relfrozenxid. The new frozen point is the
FreezeXid introduced in a recent commit, so there isn't any data loss in thisapproach.Doing it causes ALTER TABLE (or rather, the forms of it that cause a full tablerewrite) to be affected as well. In this case, the frozen point is RecentXmin,because after the rewrite all the tuples are relabeled with the rewritingtransaction's Xid.TOAST tables are fixed automatically as well, as fallout of the way they werealready being handled in the respective code paths.With this patch, there is no longer need to VACUUM tables for Xid wraparoundpurposes that have been cleaned up via TRUNCATE or CLUSTER.
1 parent2f1bf82 commitb40776d

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

‎src/backend/commands/cluster.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.160 2007/05/17 15:28:29 alvherre Exp $
14+
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.161 2007/05/18 23:19:41 alvherre Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -55,7 +55,7 @@ typedef struct
5555

5656
staticvoidcluster_rel(RelToCluster*rv,boolrecheck);
5757
staticvoidrebuild_relation(RelationOldHeap,OidindexOid);
58-
staticvoidcopy_heap_data(OidOIDNewHeap,OidOIDOldHeap,OidOIDOldIndex);
58+
staticTransactionIdcopy_heap_data(OidOIDNewHeap,OidOIDOldHeap,OidOIDOldIndex);
5959
staticList*get_tables_to_cluster(MemoryContextcluster_context);
6060

6161

@@ -513,6 +513,7 @@ rebuild_relation(Relation OldHeap, Oid indexOid)
513513
OidtableSpace=OldHeap->rd_rel->reltablespace;
514514
OidOIDNewHeap;
515515
charNewHeapName[NAMEDATALEN];
516+
TransactionIdfrozenXid;
516517
ObjectAddressobject;
517518

518519
/* Mark the correct index as clustered */
@@ -539,13 +540,13 @@ rebuild_relation(Relation OldHeap, Oid indexOid)
539540
/*
540541
* Copy the heap data into the new table in the desired order.
541542
*/
542-
copy_heap_data(OIDNewHeap,tableOid,indexOid);
543+
frozenXid=copy_heap_data(OIDNewHeap,tableOid,indexOid);
543544

544545
/* To make the new heap's data visible (probably not needed?). */
545546
CommandCounterIncrement();
546547

547548
/* Swap the physical files of the old and new heaps. */
548-
swap_relation_files(tableOid,OIDNewHeap);
549+
swap_relation_files(tableOid,OIDNewHeap,frozenXid);
549550

550551
CommandCounterIncrement();
551552

@@ -641,9 +642,10 @@ make_new_heap(Oid OIDOldHeap, const char *NewName, Oid NewTableSpace)
641642
}
642643

643644
/*
644-
* Do the physical copying of heap data.
645+
* Do the physical copying of heap data. Returns the TransactionId used as
646+
* freeze cutoff point for the tuples.
645647
*/
646-
staticvoid
648+
staticTransactionId
647649
copy_heap_data(OidOIDNewHeap,OidOIDOldHeap,OidOIDOldIndex)
648650
{
649651
RelationNewHeap,
@@ -816,6 +818,8 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
816818
index_close(OldIndex,NoLock);
817819
heap_close(OldHeap,NoLock);
818820
heap_close(NewHeap,NoLock);
821+
822+
returnFreezeXid;
819823
}
820824

821825
/*
@@ -826,9 +830,16 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
826830
*
827831
* Also swap any TOAST links, so that the toast data moves along with
828832
* the main-table data.
833+
*
834+
* Additionally, the first relation is marked with relfrozenxid set to
835+
* frozenXid. It seems a bit ugly to have this here, but all callers would
836+
* have to do it anyway, so having it here saves a heap_update. Note: the
837+
* TOAST table needs no special handling, because since we swapped the links,
838+
* the entry for the TOAST table will now contain RecentXmin in relfrozenxid,
839+
* which is the correct value.
829840
*/
830841
void
831-
swap_relation_files(Oidr1,Oidr2)
842+
swap_relation_files(Oidr1,Oidr2,TransactionIdfrozenXid)
832843
{
833844
RelationrelRelation;
834845
HeapTuplereltup1,
@@ -872,6 +883,10 @@ swap_relation_files(Oid r1, Oid r2)
872883

873884
/* we should not swap reltoastidxid */
874885

886+
/* set rel1's frozen Xid */
887+
Assert(TransactionIdIsNormal(frozenXid));
888+
relform1->relfrozenxid=frozenXid;
889+
875890
/* swap size statistics too, since new rel has freshly-updated stats */
876891
{
877892
int4swap_pages;

‎src/backend/commands/tablecmds.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.224 2007/05/16 17:28:20 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.225 2007/05/18 23:19:41 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2285,8 +2285,13 @@ ATRewriteTables(List **wqueue)
22852285
*/
22862286
ATRewriteTable(tab,OIDNewHeap);
22872287

2288-
/* Swap the physical files of the old and new heaps. */
2289-
swap_relation_files(tab->relid,OIDNewHeap);
2288+
/*
2289+
* Swap the physical files of the old and new heaps. Since we are
2290+
* generating a new heap, we can use RecentXmin for the table's new
2291+
* relfrozenxid because we rewrote all the tuples on
2292+
* ATRewriteTable, so no older Xid remains on the table.
2293+
*/
2294+
swap_relation_files(tab->relid,OIDNewHeap,RecentXmin);
22902295

22912296
CommandCounterIncrement();
22922297

‎src/include/commands/cluster.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994-5, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/commands/cluster.h,v 1.32 2007/03/13 00:33:43 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/commands/cluster.h,v 1.33 2007/05/18 23:19:42 alvherre Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -24,6 +24,6 @@ extern void check_index_is_clusterable(Relation OldHeap, Oid indexOid,
2424
externvoidmark_index_clustered(Relationrel,OidindexOid);
2525
externOidmake_new_heap(OidOIDOldHeap,constchar*NewName,
2626
OidNewTableSpace);
27-
externvoidswap_relation_files(Oidr1,Oidr2);
27+
externvoidswap_relation_files(Oidr1,Oidr2,TransactionIdfrozenXid);
2828

2929
#endif/* CLUSTER_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp