Skip to content

Commit 4bb5023

Browse files
committed
tableam: Formatting and other minor cleanups.
The superflous heapam_xlog.h includes were reported by Peter Geoghegan.
1 parent 76a39f2 commit 4bb5023

File tree

7 files changed

+162
-118
lines changed

7 files changed

+162
-118
lines changed

src/backend/access/hash/hash_xlog.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
#include "postgres.h"
1616

17-
#include "access/heapam_xlog.h"
1817
#include "access/bufmask.h"
1918
#include "access/hash.h"
2019
#include "access/hash_xlog.h"

src/backend/access/heap/heapam_handler.c

Lines changed: 100 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848
#include "utils/rel.h"
4949

5050

51-
static void
52-
reform_and_rewrite_tuple(HeapTuple tuple,
51+
static void reform_and_rewrite_tuple(HeapTuple tuple,
5352
Relation OldHeap, Relation NewHeap,
5453
Datum *values, bool *isnull, RewriteState rwstate);
5554

@@ -247,8 +246,9 @@ heapam_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid,
247246
}
248247

249248
static void
250-
heapam_tuple_insert_speculative(Relation relation, TupleTableSlot *slot, CommandId cid,
251-
int options, BulkInsertState bistate, uint32 specToken)
249+
heapam_tuple_insert_speculative(Relation relation, TupleTableSlot *slot,
250+
CommandId cid, int options,
251+
BulkInsertState bistate, uint32 specToken)
252252
{
253253
bool shouldFree = true;
254254
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -269,8 +269,8 @@ heapam_tuple_insert_speculative(Relation relation, TupleTableSlot *slot, Command
269269
}
270270

271271
static void
272-
heapam_tuple_complete_speculative(Relation relation, TupleTableSlot *slot, uint32 spekToken,
273-
bool succeeded)
272+
heapam_tuple_complete_speculative(Relation relation, TupleTableSlot *slot,
273+
uint32 spekToken, bool succeeded)
274274
{
275275
bool shouldFree = true;
276276
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -703,11 +703,11 @@ heapam_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
703703
*/
704704
if (OldIndex != NULL && !use_sort)
705705
{
706-
const int ci_index[] = {
706+
const int ci_index[] = {
707707
PROGRESS_CLUSTER_PHASE,
708708
PROGRESS_CLUSTER_INDEX_RELID
709709
};
710-
int64 ci_val[2];
710+
int64 ci_val[2];
711711

712712
/* Set phase and OIDOldIndex to columns */
713713
ci_val[0] = PROGRESS_CLUSTER_PHASE_INDEX_SCAN_HEAP;
@@ -765,7 +765,10 @@ heapam_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
765765
if (!table_scan_getnextslot(tableScan, ForwardScanDirection, slot))
766766
break;
767767

768-
/* In scan-and-sort mode and also VACUUM FULL, set heap blocks scanned */
768+
/*
769+
* In scan-and-sort mode and also VACUUM FULL, set heap blocks
770+
* scanned
771+
*/
769772
pgstat_progress_update_param(PROGRESS_CLUSTER_HEAP_BLKS_SCANNED,
770773
heapScan->rs_cblock + 1);
771774
}
@@ -844,17 +847,20 @@ heapam_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
844847
{
845848
tuplesort_putheaptuple(tuplesort, tuple);
846849

847-
/* In scan-and-sort mode, report increase in number of tuples scanned */
850+
/*
851+
* In scan-and-sort mode, report increase in number of tuples
852+
* scanned
853+
*/
848854
pgstat_progress_update_param(PROGRESS_CLUSTER_HEAP_TUPLES_SCANNED,
849855
*num_tuples);
850856
}
851857
else
852858
{
853-
const int ct_index[] = {
859+
const int ct_index[] = {
854860
PROGRESS_CLUSTER_HEAP_TUPLES_SCANNED,
855861
PROGRESS_CLUSTER_HEAP_TUPLES_WRITTEN
856862
};
857-
int64 ct_val[2];
863+
int64 ct_val[2];
858864

859865
reform_and_rewrite_tuple(tuple, OldHeap, NewHeap,
860866
values, isnull, rwstate);
@@ -882,7 +888,8 @@ heapam_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
882888
*/
883889
if (tuplesort != NULL)
884890
{
885-
double n_tuples = 0;
891+
double n_tuples = 0;
892+
886893
/* Report that we are now sorting tuples */
887894
pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE,
888895
PROGRESS_CLUSTER_PHASE_SORT_TUPLES);
@@ -925,10 +932,10 @@ heapam_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
925932
}
926933

927934
static bool
928-
heapam_scan_analyze_next_block(TableScanDesc sscan, BlockNumber blockno,
935+
heapam_scan_analyze_next_block(TableScanDesc scan, BlockNumber blockno,
929936
BufferAccessStrategy bstrategy)
930937
{
931-
HeapScanDesc scan = (HeapScanDesc) sscan;
938+
HeapScanDesc hscan = (HeapScanDesc) scan;
932939

933940
/*
934941
* We must maintain a pin on the target page's buffer to ensure that
@@ -939,40 +946,40 @@ heapam_scan_analyze_next_block(TableScanDesc sscan, BlockNumber blockno,
939946
* doing much work per tuple, the extra lock traffic is probably better
940947
* avoided.
941948
*/
942-
scan->rs_cblock = blockno;
943-
scan->rs_cindex = FirstOffsetNumber;
944-
scan->rs_cbuf = ReadBufferExtended(scan->rs_base.rs_rd, MAIN_FORKNUM,
945-
blockno, RBM_NORMAL, bstrategy);
946-
LockBuffer(scan->rs_cbuf, BUFFER_LOCK_SHARE);
949+
hscan->rs_cblock = blockno;
950+
hscan->rs_cindex = FirstOffsetNumber;
951+
hscan->rs_cbuf = ReadBufferExtended(scan->rs_rd, MAIN_FORKNUM,
952+
blockno, RBM_NORMAL, bstrategy);
953+
LockBuffer(hscan->rs_cbuf, BUFFER_LOCK_SHARE);
947954

948955
/* in heap all blocks can contain tuples, so always return true */
949956
return true;
950957
}
951958

952959
static bool
953-
heapam_scan_analyze_next_tuple(TableScanDesc sscan, TransactionId OldestXmin,
960+
heapam_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin,
954961
double *liverows, double *deadrows,
955962
TupleTableSlot *slot)
956963
{
957-
HeapScanDesc scan = (HeapScanDesc) sscan;
964+
HeapScanDesc hscan = (HeapScanDesc) scan;
958965
Page targpage;
959966
OffsetNumber maxoffset;
960967
BufferHeapTupleTableSlot *hslot;
961968

962969
Assert(TTS_IS_BUFFERTUPLE(slot));
963970

964971
hslot = (BufferHeapTupleTableSlot *) slot;
965-
targpage = BufferGetPage(scan->rs_cbuf);
972+
targpage = BufferGetPage(hscan->rs_cbuf);
966973
maxoffset = PageGetMaxOffsetNumber(targpage);
967974

968975
/* Inner loop over all tuples on the selected page */
969-
for (; scan->rs_cindex <= maxoffset; scan->rs_cindex++)
976+
for (; hscan->rs_cindex <= maxoffset; hscan->rs_cindex++)
970977
{
971978
ItemId itemid;
972979
HeapTuple targtuple = &hslot->base.tupdata;
973980
bool sample_it = false;
974981

975-
itemid = PageGetItemId(targpage, scan->rs_cindex);
982+
itemid = PageGetItemId(targpage, hscan->rs_cindex);
976983

977984
/*
978985
* We ignore unused and redirect line pointers. DEAD line pointers
@@ -987,13 +994,14 @@ heapam_scan_analyze_next_tuple(TableScanDesc sscan, TransactionId OldestXmin,
987994
continue;
988995
}
989996

990-
ItemPointerSet(&targtuple->t_self, scan->rs_cblock, scan->rs_cindex);
997+
ItemPointerSet(&targtuple->t_self, hscan->rs_cblock, hscan->rs_cindex);
991998

992-
targtuple->t_tableOid = RelationGetRelid(scan->rs_base.rs_rd);
999+
targtuple->t_tableOid = RelationGetRelid(scan->rs_rd);
9931000
targtuple->t_data = (HeapTupleHeader) PageGetItem(targpage, itemid);
9941001
targtuple->t_len = ItemIdGetLength(itemid);
9951002

996-
switch (HeapTupleSatisfiesVacuum(targtuple, OldestXmin, scan->rs_cbuf))
1003+
switch (HeapTupleSatisfiesVacuum(targtuple, OldestXmin,
1004+
hscan->rs_cbuf))
9971005
{
9981006
case HEAPTUPLE_LIVE:
9991007
sample_it = true;
@@ -1073,17 +1081,17 @@ heapam_scan_analyze_next_tuple(TableScanDesc sscan, TransactionId OldestXmin,
10731081

10741082
if (sample_it)
10751083
{
1076-
ExecStoreBufferHeapTuple(targtuple, slot, scan->rs_cbuf);
1077-
scan->rs_cindex++;
1084+
ExecStoreBufferHeapTuple(targtuple, slot, hscan->rs_cbuf);
1085+
hscan->rs_cindex++;
10781086

10791087
/* note that we leave the buffer locked here! */
10801088
return true;
10811089
}
10821090
}
10831091

10841092
/* Now release the lock and pin on the page */
1085-
UnlockReleaseBuffer(scan->rs_cbuf);
1086-
scan->rs_cbuf = InvalidBuffer;
1093+
UnlockReleaseBuffer(hscan->rs_cbuf);
1094+
hscan->rs_cbuf = InvalidBuffer;
10871095

10881096
/* also prevent old slot contents from having pin on page */
10891097
ExecClearTuple(slot);
@@ -1290,9 +1298,10 @@ heapam_index_build_range_scan(Relation heapRelation,
12901298

12911299
/*
12921300
* The criteria for counting a tuple as live in this block need to
1293-
* match what analyze.c's acquire_sample_rows() does, otherwise
1294-
* CREATE INDEX and ANALYZE may produce wildly different reltuples
1295-
* values, e.g. when there are many recently-dead tuples.
1301+
* match what analyze.c's heapam_scan_analyze_next_tuple() does,
1302+
* otherwise CREATE INDEX and ANALYZE may produce wildly different
1303+
* reltuples values, e.g. when there are many recently-dead
1304+
* tuples.
12961305
*/
12971306
switch (HeapTupleSatisfiesVacuum(heapTuple, OldestXmin,
12981307
hscan->rs_cbuf))
@@ -1323,7 +1332,7 @@ heapam_index_build_range_scan(Relation heapRelation,
13231332
* index as unusable for them.
13241333
*
13251334
* We don't count recently-dead tuples in reltuples, even
1326-
* if we index them; see acquire_sample_rows().
1335+
* if we index them; see heapam_scan_analyze_next_tuple().
13271336
*/
13281337
if (HeapTupleIsHotUpdated(heapTuple))
13291338
{
@@ -1387,7 +1396,8 @@ heapam_index_build_range_scan(Relation heapRelation,
13871396
else
13881397
{
13891398
/*
1390-
* For consistency with acquire_sample_rows(), count
1399+
* For consistency with
1400+
* heapam_scan_analyze_next_tuple(), count
13911401
* HEAPTUPLE_INSERT_IN_PROGRESS tuples as live only
13921402
* when inserted by our own transaction.
13931403
*/
@@ -1460,8 +1470,9 @@ heapam_index_build_range_scan(Relation heapRelation,
14601470
/*
14611471
* Count HEAPTUPLE_DELETE_IN_PROGRESS tuples as live,
14621472
* if they were not deleted by the current
1463-
* transaction. That's what acquire_sample_rows()
1464-
* does, and we want the behavior to be consistent.
1473+
* transaction. That's what
1474+
* heapam_scan_analyze_next_tuple() does, and we want
1475+
* the behavior to be consistent.
14651476
*/
14661477
reltuples += 1;
14671478
}
@@ -1596,7 +1607,7 @@ heapam_index_validate_scan(Relation heapRelation,
15961607
Relation indexRelation,
15971608
IndexInfo *indexInfo,
15981609
Snapshot snapshot,
1599-
ValidateIndexState * state)
1610+
ValidateIndexState *state)
16001611
{
16011612
TableScanDesc scan;
16021613
HeapScanDesc hscan;
@@ -1824,55 +1835,6 @@ heapam_index_validate_scan(Relation heapRelation,
18241835
}
18251836

18261837

1827-
/* ----------------------------------------------------------------------------
1828-
* Helper functions for the above.
1829-
* ----------------------------------------------------------------------------
1830-
*/
1831-
1832-
/*
1833-
* Reconstruct and rewrite the given tuple
1834-
*
1835-
* We cannot simply copy the tuple as-is, for several reasons:
1836-
*
1837-
* 1. We'd like to squeeze out the values of any dropped columns, both
1838-
* to save space and to ensure we have no corner-case failures. (It's
1839-
* possible for example that the new table hasn't got a TOAST table
1840-
* and so is unable to store any large values of dropped cols.)
1841-
*
1842-
* 2. The tuple might not even be legal for the new table; this is
1843-
* currently only known to happen as an after-effect of ALTER TABLE
1844-
* SET WITHOUT OIDS.
1845-
*
1846-
* So, we must reconstruct the tuple from component Datums.
1847-
*/
1848-
static void
1849-
reform_and_rewrite_tuple(HeapTuple tuple,
1850-
Relation OldHeap, Relation NewHeap,
1851-
Datum *values, bool *isnull, RewriteState rwstate)
1852-
{
1853-
TupleDesc oldTupDesc = RelationGetDescr(OldHeap);
1854-
TupleDesc newTupDesc = RelationGetDescr(NewHeap);
1855-
HeapTuple copiedTuple;
1856-
int i;
1857-
1858-
heap_deform_tuple(tuple, oldTupDesc, values, isnull);
1859-
1860-
/* Be sure to null out any dropped columns */
1861-
for (i = 0; i < newTupDesc->natts; i++)
1862-
{
1863-
if (TupleDescAttr(newTupDesc, i)->attisdropped)
1864-
isnull[i] = true;
1865-
}
1866-
1867-
copiedTuple = heap_form_tuple(newTupDesc, values, isnull);
1868-
1869-
/* The heap rewrite module does the rest */
1870-
rewrite_heap_tuple(rwstate, tuple, copiedTuple);
1871-
1872-
heap_freetuple(copiedTuple);
1873-
}
1874-
1875-
18761838
/* ------------------------------------------------------------------------
18771839
* Planner related callbacks for the heap AM
18781840
* ------------------------------------------------------------------------
@@ -1981,6 +1943,55 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
19811943
}
19821944

19831945

1946+
/* ----------------------------------------------------------------------------
1947+
* Helper functions for the above.
1948+
* ----------------------------------------------------------------------------
1949+
*/
1950+
1951+
/*
1952+
* Reconstruct and rewrite the given tuple
1953+
*
1954+
* We cannot simply copy the tuple as-is, for several reasons:
1955+
*
1956+
* 1. We'd like to squeeze out the values of any dropped columns, both
1957+
* to save space and to ensure we have no corner-case failures. (It's
1958+
* possible for example that the new table hasn't got a TOAST table
1959+
* and so is unable to store any large values of dropped cols.)
1960+
*
1961+
* 2. The tuple might not even be legal for the new table; this is
1962+
* currently only known to happen as an after-effect of ALTER TABLE
1963+
* SET WITHOUT OIDS.
1964+
*
1965+
* So, we must reconstruct the tuple from component Datums.
1966+
*/
1967+
static void
1968+
reform_and_rewrite_tuple(HeapTuple tuple,
1969+
Relation OldHeap, Relation NewHeap,
1970+
Datum *values, bool *isnull, RewriteState rwstate)
1971+
{
1972+
TupleDesc oldTupDesc = RelationGetDescr(OldHeap);
1973+
TupleDesc newTupDesc = RelationGetDescr(NewHeap);
1974+
HeapTuple copiedTuple;
1975+
int i;
1976+
1977+
heap_deform_tuple(tuple, oldTupDesc, values, isnull);
1978+
1979+
/* Be sure to null out any dropped columns */
1980+
for (i = 0; i < newTupDesc->natts; i++)
1981+
{
1982+
if (TupleDescAttr(newTupDesc, i)->attisdropped)
1983+
isnull[i] = true;
1984+
}
1985+
1986+
copiedTuple = heap_form_tuple(newTupDesc, values, isnull);
1987+
1988+
/* The heap rewrite module does the rest */
1989+
rewrite_heap_tuple(rwstate, tuple, copiedTuple);
1990+
1991+
heap_freetuple(copiedTuple);
1992+
}
1993+
1994+
19841995
/* ------------------------------------------------------------------------
19851996
* Definition of the heap table access method.
19861997
* ------------------------------------------------------------------------

src/backend/access/nbtree/nbtxlog.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "postgres.h"
1616

1717
#include "access/bufmask.h"
18-
#include "access/heapam_xlog.h"
1918
#include "access/nbtree.h"
2019
#include "access/nbtxlog.h"
2120
#include "access/transam.h"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy