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