* Do the physical copying of table data. * * There are three output parameters: * *pSwapToastByContent is set true if toast tables must be swapped by content. * *pFreezeXid receives the TransactionId used as freeze cutoff point. * *pCutoffMulti receives the MultiXactId used as a cutoff point. */
| 975 | * *pCutoffMulti receives the MultiXactId used as a cutoff point. |
| 976 | */ |
| 977 | static void |
| 978 | copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose, |
| 979 | bool *pSwapToastByContent, TransactionId *pFreezeXid, |
| 980 | MultiXactId *pCutoffMulti) |
| 981 | { |
| 982 | Relation NewHeap, |
| 983 | OldHeap, |
| 984 | OldIndex; |
| 985 | Relation relRelation; |
| 986 | HeapTuple reltup; |
| 987 | Form_pg_class relform; |
| 988 | TupleDesc oldTupDesc PG_USED_FOR_ASSERTS_ONLY; |
| 989 | TupleDesc newTupDesc PG_USED_FOR_ASSERTS_ONLY; |
| 990 | TransactionId OldestXmin; |
| 991 | TransactionId FreezeXid; |
| 992 | MultiXactId MultiXactCutoff; |
| 993 | bool use_sort; |
| 994 | double num_tuples = 0, |
| 995 | tups_vacuumed = 0, |
| 996 | tups_recently_dead = 0; |
| 997 | BlockNumber num_pages; |
| 998 | int elevel = verbose ? INFO : DEBUG2; |
| 999 | PGRUsage ru0; |
| 1000 | |
| 1001 | pg_rusage_init(&ru0); |
| 1002 | |
| 1003 | /* |
| 1004 | * Open the relations we need. |
| 1005 | */ |
| 1006 | NewHeap = table_open(OIDNewHeap, AccessExclusiveLock); |
| 1007 | OldHeap = table_open(OIDOldHeap, AccessExclusiveLock); |
| 1008 | if (OidIsValid(OIDOldIndex)) |
| 1009 | OldIndex = index_open(OIDOldIndex, AccessExclusiveLock); |
| 1010 | else |
| 1011 | OldIndex = NULL; |
| 1012 | |
| 1013 | /* |
| 1014 | * Their tuple descriptors should be exactly alike, but here we only need |
| 1015 | * assume that they have the same number of columns. |
| 1016 | */ |
| 1017 | oldTupDesc = RelationGetDescr(OldHeap); |
| 1018 | newTupDesc = RelationGetDescr(NewHeap); |
| 1019 | Assert(newTupDesc->natts == oldTupDesc->natts); |
| 1020 | |
| 1021 | /* |
| 1022 | * If the OldHeap has a toast table, get lock on the toast table to keep |
| 1023 | * it from being vacuumed. This is needed because autovacuum processes |
| 1024 | * toast tables independently of their main tables, with no lock on the |
| 1025 | * latter. If an autovacuum were to start on the toast table after we |
| 1026 | * compute our OldestXmin below, it would use a later OldestXmin, and then |
| 1027 | * possibly remove as DEAD toast tuples belonging to main tuples we think |
| 1028 | * are only RECENTLY_DEAD. Then we'd fail while trying to copy those |
| 1029 | * tuples. |
| 1030 | * |
| 1031 | * We don't need to open the toast relation here, just lock it. The lock |
| 1032 | * will be held till end of transaction. |
| 1033 | */ |
| 1034 | if (OldHeap->rd_rel->reltoastrelid) |
no test coverage detected