PostgreSQL Source Code  git master
rel.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * rel.h
4  * POSTGRES relation descriptor (a/k/a relcache entry) definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/utils/rel.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef REL_H
15 #define REL_H
16 
17 #include "access/tupdesc.h"
18 #include "access/xlog.h"
19 #include "catalog/pg_class.h"
20 #include "catalog/pg_index.h"
21 #include "catalog/pg_publication.h"
22 #include "nodes/bitmapset.h"
23 #include "partitioning/partdefs.h"
24 #include "rewrite/prs2lock.h"
25 #include "storage/block.h"
26 #include "storage/relfilenode.h"
27 #include "storage/smgr.h"
28 #include "utils/relcache.h"
29 #include "utils/reltrigger.h"
30 
31 
32 /*
33  * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
34  * to declare them here so we can have a LockInfoData field in a Relation.
35  */
36 
37 typedef struct LockRelId
38 {
39  Oid relId; /* a relation identifier */
40  Oid dbId; /* a database identifier */
42 
43 typedef struct LockInfoData
44 {
47 
49 
50 /*
51  * Here are the contents of a relation cache entry.
52  */
53 
54 typedef struct RelationData
55 {
56  RelFileNode rd_node; /* relation physical identifier */
57  SMgrRelation rd_smgr; /* cached file handle, or NULL */
58  int rd_refcnt; /* reference count */
59  BackendId rd_backend; /* owning backend id, if temporary relation */
60  bool rd_islocaltemp; /* rel is a temp rel of this session */
61  bool rd_isnailed; /* rel is nailed in cache */
62  bool rd_isvalid; /* relcache entry is valid */
63  bool rd_indexvalid; /* is rd_indexlist valid? (also rd_pkindex and
64  * rd_replidindex) */
65  bool rd_statvalid; /* is rd_statlist valid? */
66 
67  /*----------
68  * rd_createSubid is the ID of the highest subtransaction the rel has
69  * survived into or zero if the rel or its rd_node was created before the
70  * current top transaction. (IndexStmt.oldNode leads to the case of a new
71  * rel with an old rd_node.) rd_firstRelfilenodeSubid is the ID of the
72  * highest subtransaction an rd_node change has survived into or zero if
73  * rd_node matches the value it had at the start of the current top
74  * transaction. (Rolling back the subtransaction that
75  * rd_firstRelfilenodeSubid denotes would restore rd_node to the value it
76  * had at the start of the current top transaction. Rolling back any
77  * lower subtransaction would not.) Their accuracy is critical to
78  * RelationNeedsWAL().
79  *
80  * rd_newRelfilenodeSubid is the ID of the highest subtransaction the
81  * most-recent relfilenode change has survived into or zero if not changed
82  * in the current transaction (or we have forgotten changing it). This
83  * field is accurate when non-zero, but it can be zero when a relation has
84  * multiple new relfilenodes within a single transaction, with one of them
85  * occurring in a subsequently aborted subtransaction, e.g.
86  * BEGIN;
87  * TRUNCATE t;
88  * SAVEPOINT save;
89  * TRUNCATE t;
90  * ROLLBACK TO save;
91  * -- rd_newRelfilenodeSubid is now forgotten
92  *
93  * If every rd_*Subid field is zero, they are read-only outside
94  * relcache.c. Files that trigger rd_node changes by updating
95  * pg_class.reltablespace and/or pg_class.relfilenode call
96  * RelationAssumeNewRelfilenode() to update rd_*Subid.
97  *
98  * rd_droppedSubid is the ID of the highest subtransaction that a drop of
99  * the rel has survived into. In entries visible outside relcache.c, this
100  * is always zero.
101  */
102  SubTransactionId rd_createSubid; /* rel was created in current xact */
103  SubTransactionId rd_newRelfilenodeSubid; /* highest subxact changing
104  * rd_node to current value */
105  SubTransactionId rd_firstRelfilenodeSubid; /* highest subxact changing
106  * rd_node to any value */
107  SubTransactionId rd_droppedSubid; /* dropped with another Subid set */
108 
109  Form_pg_class rd_rel; /* RELATION tuple */
110  TupleDesc rd_att; /* tuple descriptor */
111  Oid rd_id; /* relation's object id */
112  LockInfoData rd_lockInfo; /* lock mgr's info for locking relation */
113  RuleLock *rd_rules; /* rewrite rules */
114  MemoryContext rd_rulescxt; /* private memory cxt for rd_rules, if any */
115  TriggerDesc *trigdesc; /* Trigger info, or NULL if rel has none */
116  /* use "struct" here to avoid needing to include rowsecurity.h: */
117  struct RowSecurityDesc *rd_rsdesc; /* row security policies, or NULL */
118 
119  /* data managed by RelationGetFKeyList: */
120  List *rd_fkeylist; /* list of ForeignKeyCacheInfo (see below) */
121  bool rd_fkeyvalid; /* true if list has been computed */
122 
123  /* data managed by RelationGetPartitionKey: */
124  PartitionKey rd_partkey; /* partition key, or NULL */
125  MemoryContext rd_partkeycxt; /* private context for rd_partkey, if any */
126 
127  /* data managed by RelationGetPartitionDesc: */
128  PartitionDesc rd_partdesc; /* partition descriptor, or NULL */
129  MemoryContext rd_pdcxt; /* private context for rd_partdesc, if any */
130 
131  /* Same as above, for partdescs that omit detached partitions */
132  PartitionDesc rd_partdesc_nodetached; /* partdesc w/o detached parts */
133  MemoryContext rd_pddcxt; /* for rd_partdesc_nodetached, if any */
134 
135  /*
136  * pg_inherits.xmin of the partition that was excluded in
137  * rd_partdesc_nodetached. This informs a future user of that partdesc:
138  * if this value is not in progress for the active snapshot, then the
139  * partdesc can be used, otherwise they have to build a new one. (This
140  * matches what find_inheritance_children_extended would do).
141  */
143 
144  /* data managed by RelationGetPartitionQual: */
145  List *rd_partcheck; /* partition CHECK quals */
146  bool rd_partcheckvalid; /* true if list has been computed */
147  MemoryContext rd_partcheckcxt; /* private cxt for rd_partcheck, if any */
148 
149  /* data managed by RelationGetIndexList: */
150  List *rd_indexlist; /* list of OIDs of indexes on relation */
151  Oid rd_pkindex; /* OID of primary key, if any */
152  Oid rd_replidindex; /* OID of replica identity index, if any */
153 
154  /* data managed by RelationGetStatExtList: */
155  List *rd_statlist; /* list of OIDs of extended stats */
156 
157  /* data managed by RelationGetIndexAttrBitmap: */
158  bool rd_attrsvalid; /* are bitmaps of attrs valid? */
159  Bitmapset *rd_keyattr; /* cols that can be ref'd by foreign keys */
160  Bitmapset *rd_pkattr; /* cols included in primary key */
161  Bitmapset *rd_idattr; /* included in replica identity index */
162  Bitmapset *rd_hotblockingattr; /* cols blocking HOT update */
163 
164  PublicationActions *rd_pubactions; /* publication actions */
165 
166  /*
167  * rd_options is set whenever rd_rel is loaded into the relcache entry.
168  * Note that you can NOT look into rd_rel for this data. NULL means "use
169  * defaults".
170  */
171  bytea *rd_options; /* parsed pg_class.reloptions */
172 
173  /*
174  * Oid of the handler for this relation. For an index this is a function
175  * returning IndexAmRoutine, for table like relations a function returning
176  * TableAmRoutine. This is stored separately from rd_indam, rd_tableam as
177  * its lookup requires syscache access, but during relcache bootstrap we
178  * need to be able to initialize rd_tableam without syscache lookups.
179  */
180  Oid rd_amhandler; /* OID of index AM's handler function */
181 
182  /*
183  * Table access method.
184  */
185  const struct TableAmRoutine *rd_tableam;
186 
187  /* These are non-NULL only for an index relation: */
188  Form_pg_index rd_index; /* pg_index tuple describing this index */
189  /* use "struct" here to avoid needing to include htup.h: */
190  struct HeapTupleData *rd_indextuple; /* all of pg_index tuple */
191 
192  /*
193  * index access support info (used only for an index relation)
194  *
195  * Note: only default support procs for each opclass are cached, namely
196  * those with lefttype and righttype equal to the opclass's opcintype. The
197  * arrays are indexed by support function number, which is a sufficient
198  * identifier given that restriction.
199  */
200  MemoryContext rd_indexcxt; /* private memory cxt for this stuff */
201  /* use "struct" here to avoid needing to include amapi.h: */
202  struct IndexAmRoutine *rd_indam; /* index AM's API struct */
203  Oid *rd_opfamily; /* OIDs of op families for each index col */
204  Oid *rd_opcintype; /* OIDs of opclass declared input data types */
205  RegProcedure *rd_support; /* OIDs of support procedures */
206  struct FmgrInfo *rd_supportinfo; /* lookup info for support procedures */
207  int16 *rd_indoption; /* per-column AM-specific flags */
208  List *rd_indexprs; /* index expression trees, if any */
209  List *rd_indpred; /* index predicate tree, if any */
210  Oid *rd_exclops; /* OIDs of exclusion operators, if any */
211  Oid *rd_exclprocs; /* OIDs of exclusion ops' procs, if any */
212  uint16 *rd_exclstrats; /* exclusion ops' strategy numbers, if any */
213  Oid *rd_indcollation; /* OIDs of index collations */
214  bytea **rd_opcoptions; /* parsed opclass-specific options */
215 
216  /*
217  * rd_amcache is available for index and table AMs to cache private data
218  * about the relation. This must be just a cache since it may get reset
219  * at any time (in particular, it will get reset by a relcache inval
220  * message for the relation). If used, it must point to a single memory
221  * chunk palloc'd in CacheMemoryContext, or in rd_indexcxt for an index
222  * relation. A relcache reset will include freeing that chunk and setting
223  * rd_amcache = NULL.
224  */
225  void *rd_amcache; /* available for use by index/table AM */
226 
227  /*
228  * foreign-table support
229  *
230  * rd_fdwroutine must point to a single memory chunk palloc'd in
231  * CacheMemoryContext. It will be freed and reset to NULL on a relcache
232  * reset.
233  */
234 
235  /* use "struct" here to avoid needing to include fdwapi.h: */
236  struct FdwRoutine *rd_fdwroutine; /* cached function pointers, or NULL */
237 
238  /*
239  * Hack for CLUSTER, rewriting ALTER TABLE, etc: when writing a new
240  * version of a table, we need to make any toast pointers inserted into it
241  * have the existing toast table's OID, not the OID of the transient toast
242  * table. If rd_toastoid isn't InvalidOid, it is the OID to place in
243  * toast pointers inserted into this rel. (Note it's set on the new
244  * version of the main heap, not the toast table itself.) This also
245  * causes toast_save_datum() to try to preserve toast value OIDs.
246  */
247  Oid rd_toastoid; /* Real TOAST table's OID, or InvalidOid */
248 
249  /* use "struct" here to avoid needing to include pgstat.h: */
250  struct PgStat_TableStatus *pgstat_info; /* statistics collection area */
252 
253 
254 /*
255  * ForeignKeyCacheInfo
256  * Information the relcache can cache about foreign key constraints
257  *
258  * This is basically just an image of relevant columns from pg_constraint.
259  * We make it a subclass of Node so that copyObject() can be used on a list
260  * of these, but we also ensure it is a "flat" object without substructure,
261  * so that list_free_deep() is sufficient to free such a list.
262  * The per-FK-column arrays can be fixed-size because we allow at most
263  * INDEX_MAX_KEYS columns in a foreign key constraint.
264  *
265  * Currently, we mostly cache fields of interest to the planner, but the set
266  * of fields has already grown the constraint OID for other uses.
267  */
268 typedef struct ForeignKeyCacheInfo
269 {
271  Oid conoid; /* oid of the constraint itself */
272  Oid conrelid; /* relation constrained by the foreign key */
273  Oid confrelid; /* relation referenced by the foreign key */
274  int nkeys; /* number of columns in the foreign key */
275  /* these arrays each have nkeys valid entries: */
276  AttrNumber conkey[INDEX_MAX_KEYS]; /* cols in referencing table */
277  AttrNumber confkey[INDEX_MAX_KEYS]; /* cols in referenced table */
278  Oid conpfeqop[INDEX_MAX_KEYS]; /* PK = FK operator OIDs */
280 
281 
282 /*
283  * StdRdOptions
284  * Standard contents of rd_options for heaps.
285  *
286  * RelationGetFillFactor() and RelationGetTargetPageFreeSpace() can only
287  * be applied to relations that use this format or a superset for
288  * private options data.
289  */
290  /* autovacuum-related reloptions. */
291 typedef struct AutoVacOpts
292 {
293  bool enabled;
310 
311 /* StdRdOptions->vacuum_index_cleanup values */
313 {
318 
319 typedef struct StdRdOptions
320 {
321  int32 vl_len_; /* varlena header (do not touch directly!) */
322  int fillfactor; /* page fill factor in percent (0..100) */
323  /* fraction of newly inserted tuples prior to trigger index cleanup */
324  int toast_tuple_target; /* target for tuple toasting */
325  AutoVacOpts autovacuum; /* autovacuum-related options */
326  bool user_catalog_table; /* use as an additional catalog relation */
327  int parallel_workers; /* max number of parallel workers */
328  StdRdOptIndexCleanup vacuum_index_cleanup; /* controls index vacuuming */
329  bool vacuum_truncate; /* enables vacuum to truncate a relation */
331 
332 #define HEAP_MIN_FILLFACTOR 10
333 #define HEAP_DEFAULT_FILLFACTOR 100
334 
335 /*
336  * RelationGetToastTupleTarget
337  * Returns the relation's toast_tuple_target. Note multiple eval of argument!
338  */
339 #define RelationGetToastTupleTarget(relation, defaulttarg) \
340  ((relation)->rd_options ? \
341  ((StdRdOptions *) (relation)->rd_options)->toast_tuple_target : (defaulttarg))
342 
343 /*
344  * RelationGetFillFactor
345  * Returns the relation's fillfactor. Note multiple eval of argument!
346  */
347 #define RelationGetFillFactor(relation, defaultff) \
348  ((relation)->rd_options ? \
349  ((StdRdOptions *) (relation)->rd_options)->fillfactor : (defaultff))
350 
351 /*
352  * RelationGetTargetPageUsage
353  * Returns the relation's desired space usage per page in bytes.
354  */
355 #define RelationGetTargetPageUsage(relation, defaultff) \
356  (BLCKSZ * RelationGetFillFactor(relation, defaultff) / 100)
357 
358 /*
359  * RelationGetTargetPageFreeSpace
360  * Returns the relation's desired freespace per page in bytes.
361  */
362 #define RelationGetTargetPageFreeSpace(relation, defaultff) \
363  (BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100)
364 
365 /*
366  * RelationIsUsedAsCatalogTable
367  * Returns whether the relation should be treated as a catalog table
368  * from the pov of logical decoding. Note multiple eval of argument!
369  */
370 #define RelationIsUsedAsCatalogTable(relation) \
371  ((relation)->rd_options && \
372  ((relation)->rd_rel->relkind == RELKIND_RELATION || \
373  (relation)->rd_rel->relkind == RELKIND_MATVIEW) ? \
374  ((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
375 
376 /*
377  * RelationGetParallelWorkers
378  * Returns the relation's parallel_workers reloption setting.
379  * Note multiple eval of argument!
380  */
381 #define RelationGetParallelWorkers(relation, defaultpw) \
382  ((relation)->rd_options ? \
383  ((StdRdOptions *) (relation)->rd_options)->parallel_workers : (defaultpw))
384 
385 /* ViewOptions->check_option values */
386 typedef enum ViewOptCheckOption
387 {
392 
393 /*
394  * ViewOptions
395  * Contents of rd_options for views
396  */
397 typedef struct ViewOptions
398 {
399  int32 vl_len_; /* varlena header (do not touch directly!) */
403 
404 /*
405  * RelationIsSecurityView
406  * Returns whether the relation is security view, or not. Note multiple
407  * eval of argument!
408  */
409 #define RelationIsSecurityView(relation) \
410  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
411  (relation)->rd_options ? \
412  ((ViewOptions *) (relation)->rd_options)->security_barrier : false)
413 
414 /*
415  * RelationHasCheckOption
416  * Returns true if the relation is a view defined with either the local
417  * or the cascaded check option. Note multiple eval of argument!
418  */
419 #define RelationHasCheckOption(relation) \
420  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
421  (relation)->rd_options && \
422  ((ViewOptions *) (relation)->rd_options)->check_option != \
423  VIEW_OPTION_CHECK_OPTION_NOT_SET)
424 
425 /*
426  * RelationHasLocalCheckOption
427  * Returns true if the relation is a view defined with the local check
428  * option. Note multiple eval of argument!
429  */
430 #define RelationHasLocalCheckOption(relation) \
431  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
432  (relation)->rd_options && \
433  ((ViewOptions *) (relation)->rd_options)->check_option == \
434  VIEW_OPTION_CHECK_OPTION_LOCAL)
435 
436 /*
437  * RelationHasCascadedCheckOption
438  * Returns true if the relation is a view defined with the cascaded check
439  * option. Note multiple eval of argument!
440  */
441 #define RelationHasCascadedCheckOption(relation) \
442  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
443  (relation)->rd_options && \
444  ((ViewOptions *) (relation)->rd_options)->check_option == \
445  VIEW_OPTION_CHECK_OPTION_CASCADED)
446 
447 /*
448  * RelationIsValid
449  * True iff relation descriptor is valid.
450  */
451 #define RelationIsValid(relation) PointerIsValid(relation)
452 
453 #define InvalidRelation ((Relation) NULL)
454 
455 /*
456  * RelationHasReferenceCountZero
457  * True iff relation reference count is zero.
458  *
459  * Note:
460  * Assumes relation descriptor is valid.
461  */
462 #define RelationHasReferenceCountZero(relation) \
463  ((bool)((relation)->rd_refcnt == 0))
464 
465 /*
466  * RelationGetForm
467  * Returns pg_class tuple for a relation.
468  *
469  * Note:
470  * Assumes relation descriptor is valid.
471  */
472 #define RelationGetForm(relation) ((relation)->rd_rel)
473 
474 /*
475  * RelationGetRelid
476  * Returns the OID of the relation
477  */
478 #define RelationGetRelid(relation) ((relation)->rd_id)
479 
480 /*
481  * RelationGetNumberOfAttributes
482  * Returns the total number of attributes in a relation.
483  */
484 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
485 
486 /*
487  * IndexRelationGetNumberOfAttributes
488  * Returns the number of attributes in an index.
489  */
490 #define IndexRelationGetNumberOfAttributes(relation) \
491  ((relation)->rd_index->indnatts)
492 
493 /*
494  * IndexRelationGetNumberOfKeyAttributes
495  * Returns the number of key attributes in an index.
496  */
497 #define IndexRelationGetNumberOfKeyAttributes(relation) \
498  ((relation)->rd_index->indnkeyatts)
499 
500 /*
501  * RelationGetDescr
502  * Returns tuple descriptor for a relation.
503  */
504 #define RelationGetDescr(relation) ((relation)->rd_att)
505 
506 /*
507  * RelationGetRelationName
508  * Returns the rel's name.
509  *
510  * Note that the name is only unique within the containing namespace.
511  */
512 #define RelationGetRelationName(relation) \
513  (NameStr((relation)->rd_rel->relname))
514 
515 /*
516  * RelationGetNamespace
517  * Returns the rel's namespace OID.
518  */
519 #define RelationGetNamespace(relation) \
520  ((relation)->rd_rel->relnamespace)
521 
522 /*
523  * RelationIsMapped
524  * True if the relation uses the relfilenode map. Note multiple eval
525  * of argument!
526  */
527 #define RelationIsMapped(relation) \
528  (RELKIND_HAS_STORAGE((relation)->rd_rel->relkind) && \
529  ((relation)->rd_rel->relfilenode == InvalidOid))
530 
531 /*
532  * RelationGetSmgr
533  * Returns smgr file handle for a relation, opening it if needed.
534  *
535  * Very little code is authorized to touch rel->rd_smgr directly. Instead
536  * use this function to fetch its value.
537  *
538  * Note: since a relcache flush can cause the file handle to be closed again,
539  * it's unwise to hold onto the pointer returned by this function for any
540  * long period. Recommended practice is to just re-execute RelationGetSmgr
541  * each time you need to access the SMgrRelation. It's quite cheap in
542  * comparison to whatever an smgr function is going to do.
543  */
544 static inline SMgrRelation
546 {
547  if (unlikely(rel->rd_smgr == NULL))
548  smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_node, rel->rd_backend));
549  return rel->rd_smgr;
550 }
551 
552 /*
553  * RelationCloseSmgr
554  * Close the relation at the smgr level, if not already done.
555  *
556  * Note: smgrclose should unhook from owner pointer, hence the Assert.
557  */
558 #define RelationCloseSmgr(relation) \
559  do { \
560  if ((relation)->rd_smgr != NULL) \
561  { \
562  smgrclose((relation)->rd_smgr); \
563  Assert((relation)->rd_smgr == NULL); \
564  } \
565  } while (0)
566 
567 /*
568  * RelationGetTargetBlock
569  * Fetch relation's current insertion target block.
570  *
571  * Returns InvalidBlockNumber if there is no current target block. Note
572  * that the target block status is discarded on any smgr-level invalidation,
573  * so there's no need to re-open the smgr handle if it's not currently open.
574  */
575 #define RelationGetTargetBlock(relation) \
576  ( (relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber )
577 
578 /*
579  * RelationSetTargetBlock
580  * Set relation's current insertion target block.
581  */
582 #define RelationSetTargetBlock(relation, targblock) \
583  do { \
584  RelationGetSmgr(relation)->smgr_targblock = (targblock); \
585  } while (0)
586 
587 /*
588  * RelationIsPermanent
589  * True if relation is permanent.
590  */
591 #define RelationIsPermanent(relation) \
592  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
593 
594 /*
595  * RelationNeedsWAL
596  * True if relation needs WAL.
597  *
598  * Returns false if wal_level = minimal and this relation is created or
599  * truncated in the current transaction. See "Skipping WAL for New
600  * RelFileNode" in src/backend/access/transam/README.
601  */
602 #define RelationNeedsWAL(relation) \
603  (RelationIsPermanent(relation) && (XLogIsNeeded() || \
604  (relation->rd_createSubid == InvalidSubTransactionId && \
605  relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
606 
607 /*
608  * RelationUsesLocalBuffers
609  * True if relation's pages are stored in local buffers.
610  */
611 #define RelationUsesLocalBuffers(relation) \
612  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
613 
614 /*
615  * RELATION_IS_LOCAL
616  * If a rel is either temp or newly created in the current transaction,
617  * it can be assumed to be accessible only to the current backend.
618  * This is typically used to decide that we can skip acquiring locks.
619  *
620  * Beware of multiple eval of argument
621  */
622 #define RELATION_IS_LOCAL(relation) \
623  ((relation)->rd_islocaltemp || \
624  (relation)->rd_createSubid != InvalidSubTransactionId)
625 
626 /*
627  * RELATION_IS_OTHER_TEMP
628  * Test for a temporary relation that belongs to some other session.
629  *
630  * Beware of multiple eval of argument
631  */
632 #define RELATION_IS_OTHER_TEMP(relation) \
633  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \
634  !(relation)->rd_islocaltemp)
635 
636 
637 /*
638  * RelationIsScannable
639  * Currently can only be false for a materialized view which has not been
640  * populated by its query. This is likely to get more complicated later,
641  * so use a macro which looks like a function.
642  */
643 #define RelationIsScannable(relation) ((relation)->rd_rel->relispopulated)
644 
645 /*
646  * RelationIsPopulated
647  * Currently, we don't physically distinguish the "populated" and
648  * "scannable" properties of matviews, but that may change later.
649  * Hence, use the appropriate one of these macros in code tests.
650  */
651 #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated)
652 
653 /*
654  * RelationIsAccessibleInLogicalDecoding
655  * True if we need to log enough information to have access via
656  * decoding snapshot.
657  */
658 #define RelationIsAccessibleInLogicalDecoding(relation) \
659  (XLogLogicalInfoActive() && \
660  RelationNeedsWAL(relation) && \
661  (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation)))
662 
663 /*
664  * RelationIsLogicallyLogged
665  * True if we need to log enough information to extract the data from the
666  * WAL stream.
667  *
668  * We don't log information for unlogged tables (since they don't WAL log
669  * anyway), for foreign tables (since they don't WAL log, either),
670  * and for system tables (their content is hard to make sense of, and
671  * it would complicate decoding slightly for little gain). Note that we *do*
672  * log information for user defined catalog tables since they presumably are
673  * interesting to the user...
674  */
675 #define RelationIsLogicallyLogged(relation) \
676  (XLogLogicalInfoActive() && \
677  RelationNeedsWAL(relation) && \
678  (relation)->rd_rel->relkind != RELKIND_FOREIGN_TABLE && \
679  !IsCatalogRelation(relation))
680 
681 /* routines in utils/cache/relcache.c */
684 
685 #endif /* REL_H */
int16 AttrNumber
Definition: attnum.h:21
int BackendId
Definition: backendid.h:21
unsigned short uint16
Definition: c.h:440
signed short int16
Definition: c.h:428
uint32 SubTransactionId
Definition: c.h:591
signed int int32
Definition: c.h:429
double float8
Definition: c.h:565
regproc RegProcedure
Definition: c.h:585
#define unlikely(x)
Definition: c.h:273
uint32 TransactionId
Definition: c.h:587
NodeTag
Definition: nodes.h:27
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
#define INDEX_MAX_KEYS
FormData_pg_index * Form_pg_index
Definition: pg_index.h:69
unsigned int Oid
Definition: postgres_ext.h:31
LockInfoData * LockInfo
Definition: rel.h:48
struct LockRelId LockRelId
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2118
ViewOptCheckOption
Definition: rel.h:387
@ VIEW_OPTION_CHECK_OPTION_NOT_SET
Definition: rel.h:388
@ VIEW_OPTION_CHECK_OPTION_LOCAL
Definition: rel.h:389
@ VIEW_OPTION_CHECK_OPTION_CASCADED
Definition: rel.h:390
struct ForeignKeyCacheInfo ForeignKeyCacheInfo
static SMgrRelation RelationGetSmgr(Relation rel)
Definition: rel.h:545
void RelationIncrementReferenceCount(Relation rel)
Definition: relcache.c:2105
struct StdRdOptions StdRdOptions
struct ViewOptions ViewOptions
struct LockInfoData LockInfoData
struct AutoVacOpts AutoVacOpts
struct RelationData RelationData
StdRdOptIndexCleanup
Definition: rel.h:313
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO
Definition: rel.h:314
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF
Definition: rel.h:315
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON
Definition: rel.h:316
void smgrsetowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:198
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
Definition: smgr.c:146
int vacuum_ins_threshold
Definition: rel.h:295
int log_min_duration
Definition: rel.h:304
float8 vacuum_cost_delay
Definition: rel.h:305
int multixact_freeze_max_age
Definition: rel.h:302
int vacuum_cost_limit
Definition: rel.h:297
float8 vacuum_scale_factor
Definition: rel.h:306
int analyze_threshold
Definition: rel.h:296
float8 vacuum_ins_scale_factor
Definition: rel.h:307
bool enabled
Definition: rel.h:293
int multixact_freeze_table_age
Definition: rel.h:303
int freeze_min_age
Definition: rel.h:298
int freeze_table_age
Definition: rel.h:300
int freeze_max_age
Definition: rel.h:299
int vacuum_threshold
Definition: rel.h:294
int multixact_freeze_min_age
Definition: rel.h:301
float8 analyze_scale_factor
Definition: rel.h:308
Definition: fmgr.h:57
Oid conpfeqop[INDEX_MAX_KEYS]
Definition: rel.h:278
AttrNumber confkey[INDEX_MAX_KEYS]
Definition: rel.h:277
NodeTag type
Definition: rel.h:270
AttrNumber conkey[INDEX_MAX_KEYS]
Definition: rel.h:276
Definition: pg_list.h:51
LockRelId lockRelId
Definition: rel.h:45
Definition: rel.h:38
Oid relId
Definition: rel.h:39
Oid dbId
Definition: rel.h:40
List * rd_partcheck
Definition: rel.h:145
Bitmapset * rd_keyattr
Definition: rel.h:159
bool rd_partcheckvalid
Definition: rel.h:146
MemoryContext rd_pdcxt
Definition: rel.h:129
Oid rd_toastoid
Definition: rel.h:247
MemoryContext rd_partkeycxt
Definition: rel.h:125
const struct TableAmRoutine * rd_tableam
Definition: rel.h:185
TransactionId rd_partdesc_nodetached_xmin
Definition: rel.h:142
bool rd_indexvalid
Definition: rel.h:63
List * rd_indpred
Definition: rel.h:209
struct IndexAmRoutine * rd_indam
Definition: rel.h:202
List * rd_fkeylist
Definition: rel.h:120
Oid * rd_exclprocs
Definition: rel.h:211
SubTransactionId rd_newRelfilenodeSubid
Definition: rel.h:103
SubTransactionId rd_firstRelfilenodeSubid
Definition: rel.h:105
LockInfoData rd_lockInfo
Definition: rel.h:112
uint16 * rd_exclstrats
Definition: rel.h:212
List * rd_indexlist
Definition: rel.h:150
struct RowSecurityDesc * rd_rsdesc
Definition: rel.h:117
PartitionDesc rd_partdesc
Definition: rel.h:128
Oid rd_replidindex
Definition: rel.h:152
int rd_refcnt
Definition: rel.h:58
RegProcedure * rd_support
Definition: rel.h:205
PartitionDesc rd_partdesc_nodetached
Definition: rel.h:132
bytea ** rd_opcoptions
Definition: rel.h:214
struct FdwRoutine * rd_fdwroutine
Definition: rel.h:236
TriggerDesc * trigdesc
Definition: rel.h:115
PublicationActions * rd_pubactions
Definition: rel.h:164
Bitmapset * rd_idattr
Definition: rel.h:161
bool rd_isvalid
Definition: rel.h:62
bool rd_islocaltemp
Definition: rel.h:60
List * rd_indexprs
Definition: rel.h:208
bool rd_attrsvalid
Definition: rel.h:158
Oid * rd_exclops
Definition: rel.h:210
Oid * rd_opcintype
Definition: rel.h:204
struct HeapTupleData * rd_indextuple
Definition: rel.h:190
MemoryContext rd_partcheckcxt
Definition: rel.h:147
int16 * rd_indoption
Definition: rel.h:207
TupleDesc rd_att
Definition: rel.h:110
Form_pg_index rd_index
Definition: rel.h:188
Bitmapset * rd_hotblockingattr
Definition: rel.h:162
void * rd_amcache
Definition: rel.h:225
bool rd_isnailed
Definition: rel.h:61
Oid rd_id
Definition: rel.h:111
Oid rd_pkindex
Definition: rel.h:151
RelFileNode rd_node
Definition: rel.h:56
bool rd_fkeyvalid
Definition: rel.h:121
BackendId rd_backend
Definition: rel.h:59
Oid rd_amhandler
Definition: rel.h:180
SMgrRelation rd_smgr
Definition: rel.h:57
SubTransactionId rd_createSubid
Definition: rel.h:102
bool rd_statvalid
Definition: rel.h:65
MemoryContext rd_indexcxt
Definition: rel.h:200
List * rd_statlist
Definition: rel.h:155
MemoryContext rd_pddcxt
Definition: rel.h:133
RuleLock * rd_rules
Definition: rel.h:113
struct FmgrInfo * rd_supportinfo
Definition: rel.h:206
Oid * rd_opfamily
Definition: rel.h:203
SubTransactionId rd_droppedSubid
Definition: rel.h:107
MemoryContext rd_rulescxt
Definition: rel.h:114
Bitmapset * rd_pkattr
Definition: rel.h:160
PartitionKey rd_partkey
Definition: rel.h:124
bytea * rd_options
Definition: rel.h:171
Oid * rd_indcollation
Definition: rel.h:213
Form_pg_class rd_rel
Definition: rel.h:109
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:250
int32 vl_len_
Definition: rel.h:321
bool user_catalog_table
Definition: rel.h:326
StdRdOptIndexCleanup vacuum_index_cleanup
Definition: rel.h:328
int fillfactor
Definition: rel.h:322
AutoVacOpts autovacuum
Definition: rel.h:325
int toast_tuple_target
Definition: rel.h:324
int parallel_workers
Definition: rel.h:327
bool vacuum_truncate
Definition: rel.h:329
int32 vl_len_
Definition: rel.h:399
bool security_barrier
Definition: rel.h:400
ViewOptCheckOption check_option
Definition: rel.h:401
Definition: c.h:622