Don't include heapam.h from others headers.

heapam.h previously was included in a number of widely used
headers (e.g. execnodes.h, indirectly in executor.h, ...). That's
problematic on its own, as heapam.h contains a lot of low-level
details that don't need to be exposed that widely, but becomes more
problematic with the upcoming introduction of pluggable table storage
- it seems inappropriate for heapam.h to be included that widely
afterwards.

heapam.h was largely only included in other headers to get the
HeapScanDesc typedef (which was defined in heapam.h, even though
HeapScanDescData is defined in relscan.h). The better solution here
seems to be to just use the underlying struct (forward declared where
necessary). Similar for BulkInsertState.

Another problem was that LockTupleMode was used in executor.h - parts
of the file tried to cope without heapam.h, but due to the fact that
it indirectly included it, several subsequent violations of that goal
were not not noticed. We could just reuse the approach of declaring
parameters as int, but it seems nicer to move LockTupleMode to
lockoptions.h - that's not a perfect location, but also doesn't seem
bad.

As a number of files relied on implicitly included heapam.h, a
significant number of files grew an explicit include. It's quite
probably that a few external projects will need to do the same.

Author: Andres Freund
Reviewed-By: Alvaro Herrera
Discussion: https://postgr.es/m/20190114000701.y4ttcb74jpskkcfb@alap3.anarazel.de
This commit is contained in:
Andres Freund 2019-01-14 15:54:18 -08:00
parent 42e2a58071
commit 4c850ecec6
71 changed files with 91 additions and 36 deletions

View File

@ -23,6 +23,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/nbtree.h"
#include "access/transam.h"

View File

@ -38,6 +38,7 @@
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/heapam.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_foreign_data_wrapper.h"

View File

@ -18,6 +18,7 @@
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/sysattr.h"
#include "access/heapam.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_foreign_table.h"
#include "commands/copy.h"

View File

@ -30,6 +30,7 @@
#include "pageinspect.h"
#include "access/nbtree.h"
#include "access/heapam.h"
#include "catalog/namespace.h"
#include "catalog/pg_am.h"
#include "funcapi.h"

View File

@ -27,6 +27,7 @@
#include "pageinspect.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "funcapi.h"
#include "catalog/pg_type.h"

View File

@ -18,6 +18,7 @@
#include "pageinspect.h"
#include "access/htup_details.h"
#include "access/heapam.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "funcapi.h"

View File

@ -8,6 +8,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "funcapi.h"
#include "storage/freespace.h"

View File

@ -10,6 +10,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/visibilitymap.h"
#include "catalog/pg_type.h"

View File

@ -24,6 +24,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/multixact.h"
#include "access/relscan.h"
#include "access/xact.h"

View File

@ -13,6 +13,7 @@
#include "postgres.h"
#include "access/visibilitymap.h"
#include "access/heapam.h"
#include "access/transam.h"
#include "access/xact.h"
#include "access/multixact.h"

View File

@ -26,6 +26,7 @@
#include "access/gist_private.h"
#include "access/hash.h"
#include "access/heapam.h"
#include "access/nbtree.h"
#include "access/relscan.h"
#include "catalog/namespace.h"

View File

@ -14,6 +14,7 @@
#include "postgres_fdw.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/pg_class.h"

View File

@ -28,6 +28,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/tsmapi.h"
#include "catalog/pg_type.h"

View File

@ -26,6 +26,7 @@
#include <math.h>
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/tsmapi.h"
#include "catalog/pg_type.h"

View File

@ -19,6 +19,7 @@
#include "access/brin_page.h"
#include "access/brin_pageops.h"
#include "access/brin_xlog.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/relscan.h"
#include "access/xloginsert.h"

View File

@ -16,7 +16,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/itup.h"
#include "access/tuptoaster.h"

View File

@ -19,6 +19,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/transam.h"
#include "catalog/index.h"

View File

@ -70,6 +70,7 @@
#include "postgres.h"
#include "access/amapi.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/transam.h"
#include "access/xlog.h"

View File

@ -57,6 +57,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/nbtree.h"
#include "access/parallel.h"
#include "access/relscan.h"

View File

@ -27,6 +27,7 @@
#include <math.h>
#include "access/hash.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/tsmapi.h"
#include "catalog/pg_type.h"

View File

@ -17,6 +17,7 @@
#include <unistd.h>
#include <signal.h>
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "access/xlog_internal.h"

View File

@ -15,6 +15,7 @@
#include "postgres.h"
#include "access/htup_details.h"
#include "access/heapam.h"
#include "access/xact.h"
#include "catalog/dependency.h"
#include "catalog/heap.h"

View File

@ -29,6 +29,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/multixact.h"
#include "access/sysattr.h"

View File

@ -24,6 +24,7 @@
#include <unistd.h>
#include "access/amapi.h"
#include "access/heapam.h"
#include "access/multixact.h"
#include "access/relscan.h"
#include "access/reloptions.h"

View File

@ -15,6 +15,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "catalog/index.h"
#include "catalog/indexing.h"

View File

@ -15,6 +15,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/catalog.h"

View File

@ -15,6 +15,7 @@
#include "postgres.h"
#include "access/htup_details.h"
#include "access/heapam.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"

View File

@ -14,6 +14,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/tuptoaster.h"
#include "access/xact.h"
#include "catalog/binary_upgrade.h"

View File

@ -14,6 +14,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/dependency.h"

View File

@ -16,6 +16,7 @@
#include <math.h>
#include "access/heapam.h"
#include "access/multixact.h"
#include "access/sysattr.h"
#include "access/transam.h"

View File

@ -18,6 +18,7 @@
#include "postgres.h"
#include "access/amapi.h"
#include "access/heapam.h"
#include "access/multixact.h"
#include "access/relscan.h"
#include "access/rewriteheap.h"

View File

@ -13,6 +13,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "catalog/index.h"
#include "commands/trigger.h"
#include "executor/executor.h"

View File

@ -24,6 +24,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/htup_details.h"
#include "access/sysattr.h"

View File

@ -13,6 +13,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/catalog.h"

View File

@ -29,6 +29,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "access/xact.h"

View File

@ -16,6 +16,7 @@
#include "postgres.h"
#include "access/amapi.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/sysattr.h"

View File

@ -14,6 +14,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/multixact.h"
#include "access/xact.h"

View File

@ -15,6 +15,7 @@
#include "postgres.h"
#include "access/bufmask.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/multixact.h"
#include "access/transam.h"

View File

@ -14,6 +14,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"

View File

@ -31,6 +31,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/binary_upgrade.h"

View File

@ -37,6 +37,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "access/transam.h"
@ -2435,13 +2436,10 @@ ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist)
*
* Returns a slot containing the new candidate update/delete tuple, or
* NULL if we determine we shouldn't process the row.
*
* Note: properly, lockmode should be declared as enum LockTupleMode,
* but we use "int" to avoid having to include heapam.h in executor.h.
*/
TupleTableSlot *
EvalPlanQual(EState *estate, EPQState *epqstate,
Relation relation, Index rti, int lockmode,
Relation relation, Index rti, LockTupleMode lockmode,
ItemPointer tid, TransactionId priorXmax)
{
TupleTableSlot *slot;
@ -2522,12 +2520,9 @@ EvalPlanQual(EState *estate, EPQState *epqstate,
*
* If successful, we have locked the newest tuple version, so caller does not
* need to worry about it changing anymore.
*
* Note: properly, lockmode should be declared as enum LockTupleMode,
* but we use "int" to avoid having to include heapam.h in executor.h.
*/
HeapTuple
EvalPlanQualFetch(EState *estate, Relation relation, int lockmode,
EvalPlanQualFetch(EState *estate, Relation relation, LockTupleMode lockmode,
LockWaitPolicy wait_policy,
ItemPointer tid, TransactionId priorXmax)
{

View File

@ -13,6 +13,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "catalog/partition.h"
#include "catalog/pg_inherits.h"
#include "catalog/pg_type.h"

View File

@ -14,6 +14,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/transam.h"
#include "access/xact.h"

View File

@ -45,6 +45,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/parallel.h"
#include "access/relscan.h"
#include "access/transam.h"

View File

@ -37,6 +37,7 @@
#include <math.h>
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/transam.h"
#include "access/visibilitymap.h"

View File

@ -21,6 +21,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "executor/executor.h"

View File

@ -37,6 +37,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/catalog.h"

View File

@ -15,6 +15,7 @@
#include "postgres.h"
#include "access/hash.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/tsmapi.h"
#include "executor/executor.h"

View File

@ -27,6 +27,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "executor/execdebug.h"
#include "executor/nodeSeqscan.h"

View File

@ -22,6 +22,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/sysattr.h"
#include "catalog/pg_type.h"
#include "executor/execdebug.h"

View File

@ -18,6 +18,7 @@
#include <limits.h>
#include <math.h>
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/parallel.h"
#include "access/sysattr.h"

View File

@ -16,6 +16,7 @@
#include <ctype.h>
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/heap.h"

View File

@ -27,6 +27,7 @@
#include "postgres.h"
#include "access/amapi.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "catalog/dependency.h"

View File

@ -13,6 +13,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "catalog/partition.h"
#include "catalog/pg_inherits.h"
#include "catalog/pg_type.h"

View File

@ -88,6 +88,7 @@
#include "miscadmin.h"
#include "pgstat.h"
#include "access/heapam.h"
#include "access/xact.h"
#include "catalog/pg_subscription_rel.h"

View File

@ -27,6 +27,7 @@
#include "pgstat.h"
#include "funcapi.h"
#include "access/heapam.h"
#include "access/xact.h"
#include "access/xlog_internal.h"

View File

@ -20,6 +20,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/sysattr.h"
#include "catalog/dependency.h"
#include "catalog/pg_type.h"

View File

@ -19,6 +19,7 @@
#include <math.h>
#include <unistd.h>
#include "access/heapam.h"
#include "access/sysattr.h"
#include "catalog/catalog.h"
#include "catalog/pg_tablespace.h"

View File

@ -30,6 +30,7 @@
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "access/xact.h"

View File

@ -20,6 +20,7 @@
#include <fcntl.h>
#include "access/amapi.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/dependency.h"

View File

@ -103,6 +103,7 @@
#include "access/brin.h"
#include "access/gin.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/index.h"

View File

@ -67,6 +67,7 @@
#endif
#endif /* USE_LIBXML */
#include "access/heapam.h"
#include "access/htup_details.h"
#include "catalog/namespace.h"
#include "catalog/pg_class.h"

View File

@ -31,6 +31,7 @@
#include <unistd.h>
#include "access/hash.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/multixact.h"
#include "access/nbtree.h"

View File

@ -13,6 +13,7 @@
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "catalog/namespace.h"
#include "catalog/pg_proc.h"

View File

@ -33,21 +33,6 @@
typedef struct BulkInsertStateData *BulkInsertState;
/*
* Possible lock modes for a tuple.
*/
typedef enum LockTupleMode
{
/* SELECT FOR KEY SHARE */
LockTupleKeyShare,
/* SELECT FOR SHARE */
LockTupleShare,
/* SELECT FOR NO KEY UPDATE, and UPDATEs that don't modify key columns */
LockTupleNoKeyExclusive,
/* SELECT FOR UPDATE, UPDATEs that modify key columns, and DELETE */
LockTupleExclusive
} LockTupleMode;
#define MaxLockTupleMode LockTupleExclusive
/*

View File

@ -14,7 +14,6 @@
#ifndef HIO_H
#define HIO_H
#include "access/heapam.h"
#include "access/htup.h"
#include "utils/relcache.h"
#include "storage/buf.h"
@ -39,7 +38,7 @@ extern void RelationPutHeapTuple(Relation relation, Buffer buffer,
HeapTuple tuple, bool token);
extern Buffer RelationGetBufferForTuple(Relation relation, Size len,
Buffer otherBuffer, int options,
BulkInsertState bistate,
BulkInsertStateData *bistate,
Buffer *vmbuffer, Buffer *vmbuffer_other);
#endif /* HIO_H */

View File

@ -15,7 +15,6 @@
#define RELSCAN_H
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/itup.h"
#include "access/tupdesc.h"
@ -71,7 +70,7 @@ typedef struct HeapScanDescData
BlockNumber rs_cblock; /* current block # in scan, if any */
Buffer rs_cbuf; /* current buffer in scan, if any */
/* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
ParallelHeapScanDesc rs_parallel; /* parallel scan information */
struct ParallelHeapScanDescData *rs_parallel; /* parallel scan information */
/* these fields only used in page-at-a-time mode and for bitmap scans */
int rs_cindex; /* current tuple's index in vistuples */
@ -155,7 +154,7 @@ typedef struct SysScanDescData
{
Relation heap_rel; /* catalog being scanned */
Relation irel; /* NULL if doing heap scan */
HeapScanDesc scan; /* only valid in heap-scan case */
struct HeapScanDescData *scan; /* only valid in heap-scan case */
IndexScanDesc iscan; /* only valid in index-scan case */
Snapshot snapshot; /* snapshot to unregister at end of scan */
} SysScanDescData;

View File

@ -117,7 +117,7 @@ extern double IndexBuildHeapScan(Relation heapRelation,
bool allow_sync,
IndexBuildCallback callback,
void *callback_state,
HeapScanDesc scan);
struct HeapScanDescData *scan);
extern double IndexBuildHeapRangeScan(Relation heapRelation,
Relation indexRelation,
IndexInfo *indexInfo,
@ -127,7 +127,7 @@ extern double IndexBuildHeapRangeScan(Relation heapRelation,
BlockNumber end_blockno,
IndexBuildCallback callback,
void *callback_state,
HeapScanDesc scan);
struct HeapScanDescData *scan);
extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);

View File

@ -15,6 +15,7 @@
#define EXECUTOR_H
#include "executor/execdesc.h"
#include "nodes/lockoptions.h"
#include "nodes/parsenodes.h"
#include "utils/memutils.h"
@ -184,11 +185,11 @@ extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *relinfo);
extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missing_ok);
extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist);
extern TupleTableSlot *EvalPlanQual(EState *estate, EPQState *epqstate,
Relation relation, Index rti, int lockmode,
Relation relation, Index rti, LockTupleMode lockmode,
ItemPointer tid, TransactionId priorXmax);
extern HeapTuple EvalPlanQualFetch(EState *estate, Relation relation,
int lockmode, LockWaitPolicy wait_policy, ItemPointer tid,
TransactionId priorXmax);
LockTupleMode lockmode, LockWaitPolicy wait_policy,
ItemPointer tid, TransactionId priorXmax);
extern void EvalPlanQualInit(EPQState *epqstate, EState *estate,
Plan *subplan, List *auxrowmarks, int epqParam);
extern void EvalPlanQualSetPlan(EPQState *epqstate,

View File

@ -15,7 +15,6 @@
#define EXECNODES_H
#include "access/genam.h"
#include "access/heapam.h"
#include "access/tupconvert.h"
#include "executor/instrument.h"
#include "lib/pairingheap.h"
@ -1268,7 +1267,7 @@ typedef struct ScanState
{
PlanState ps; /* its first field is NodeTag */
Relation ss_currentRelation;
HeapScanDesc ss_currentScanDesc;
struct HeapScanDescData *ss_currentScanDesc;
TupleTableSlot *ss_ScanTupleSlot;
} ScanState;

View File

@ -43,4 +43,19 @@ typedef enum LockWaitPolicy
LockWaitError
} LockWaitPolicy;
/*
* Possible lock modes for a tuple.
*/
typedef enum LockTupleMode
{
/* SELECT FOR KEY SHARE */
LockTupleKeyShare,
/* SELECT FOR SHARE */
LockTupleShare,
/* SELECT FOR NO KEY UPDATE, and UPDATEs that don't modify key columns */
LockTupleNoKeyExclusive,
/* SELECT FOR UPDATE, UPDATEs that modify key columns, and DELETE */
LockTupleExclusive
} LockTupleMode;
#endif /* LOCKOPTIONS_H */