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/relfilelocator.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  RelFileLocator rd_locator; /* 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 storage was created before the
70  * current top transaction. (IndexStmt.oldNumber leads to the case of a new
71  * rel with an old rd_locator.) rd_firstRelfilelocatorSubid is the ID of the
72  * highest subtransaction an rd_locator change has survived into or zero if
73  * rd_locator matches the value it had at the start of the current top
74  * transaction. (Rolling back the subtransaction that
75  * rd_firstRelfilelocatorSubid denotes would restore rd_locator 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_newRelfilelocatorSubid is the ID of the highest subtransaction the
81  * most-recent relfilenumber 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 relfilenumbers 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_newRelfilelocatorSubid is now forgotten
92  *
93  * If every rd_*Subid field is zero, they are read-only outside
94  * relcache.c. Files that trigger rd_locator changes by updating
95  * pg_class.reltablespace and/or pg_class.relfilenode call
96  * RelationAssumeNewRelfilelocator() 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_newRelfilelocatorSubid; /* highest subxact changing
104  * rd_locator to current value */
106  * changing rd_locator to
107  * 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  /* Same as above, for partdescs that omit detached partitions */
133  PartitionDesc rd_partdesc_nodetached; /* partdesc w/o detached parts */
134  MemoryContext rd_pddcxt; /* for rd_partdesc_nodetached, if any */
135 
136  /*
137  * pg_inherits.xmin of the partition that was excluded in
138  * rd_partdesc_nodetached. This informs a future user of that partdesc:
139  * if this value is not in progress for the active snapshot, then the
140  * partdesc can be used, otherwise they have to build a new one. (This
141  * matches what find_inheritance_children_extended would do).
142  */
144 
145  /* data managed by RelationGetPartitionQual: */
146  List *rd_partcheck; /* partition CHECK quals */
147  bool rd_partcheckvalid; /* true if list has been computed */
148  MemoryContext rd_partcheckcxt; /* private cxt for rd_partcheck, if any */
149 
150  /* data managed by RelationGetIndexList: */
151  List *rd_indexlist; /* list of OIDs of indexes on relation */
152  Oid rd_pkindex; /* OID of primary key, if any */
153  Oid rd_replidindex; /* OID of replica identity index, if any */
154 
155  /* data managed by RelationGetStatExtList: */
156  List *rd_statlist; /* list of OIDs of extended stats */
157 
158  /* data managed by RelationGetIndexAttrBitmap: */
159  Bitmapset *rd_indexattr; /* identifies columns used in indexes */
160  Bitmapset *rd_keyattr; /* cols that can be ref'd by foreign keys */
161  Bitmapset *rd_pkattr; /* cols included in primary key */
162  Bitmapset *rd_idattr; /* included in replica identity index */
163 
164  PublicationDesc *rd_pubdesc; /* publication descriptor, or NULL */
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  bool pgstat_enabled; /* should relation stats be counted */
250  /* use "struct" here to avoid needing to include pgstat.h: */
251  struct PgStat_TableStatus *pgstat_info; /* statistics collection area */
253 
254 
255 /*
256  * ForeignKeyCacheInfo
257  * Information the relcache can cache about foreign key constraints
258  *
259  * This is basically just an image of relevant columns from pg_constraint.
260  * We make it a subclass of Node so that copyObject() can be used on a list
261  * of these, but we also ensure it is a "flat" object without substructure,
262  * so that list_free_deep() is sufficient to free such a list.
263  * The per-FK-column arrays can be fixed-size because we allow at most
264  * INDEX_MAX_KEYS columns in a foreign key constraint.
265  *
266  * Currently, we mostly cache fields of interest to the planner, but the set
267  * of fields has already grown the constraint OID for other uses.
268  */
269 typedef struct ForeignKeyCacheInfo
270 {
271  pg_node_attr(no_equal, no_read)
272 
273  NodeTag type;
274  /* oid of the constraint itself */
276  /* relation constrained by the foreign key */
278  /* relation referenced by the foreign key */
280  /* number of columns in the foreign key */
281  int nkeys;
282 
283  /*
284  * these arrays each have nkeys valid entries:
285  */
286  /* cols in referencing table */
288  /* cols in referenced table */
290  /* PK = FK operator OIDs */
291  Oid conpfeqop[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys));
293 
294 
295 /*
296  * StdRdOptions
297  * Standard contents of rd_options for heaps.
298  *
299  * RelationGetFillFactor() and RelationGetTargetPageFreeSpace() can only
300  * be applied to relations that use this format or a superset for
301  * private options data.
302  */
303  /* autovacuum-related reloptions. */
304 typedef struct AutoVacOpts
305 {
306  bool enabled;
323 
324 /* StdRdOptions->vacuum_index_cleanup values */
326 {
331 
332 typedef struct StdRdOptions
333 {
334  int32 vl_len_; /* varlena header (do not touch directly!) */
335  int fillfactor; /* page fill factor in percent (0..100) */
336  int toast_tuple_target; /* target for tuple toasting */
337  AutoVacOpts autovacuum; /* autovacuum-related options */
338  bool user_catalog_table; /* use as an additional catalog relation */
339  int parallel_workers; /* max number of parallel workers */
340  StdRdOptIndexCleanup vacuum_index_cleanup; /* controls index vacuuming */
341  bool vacuum_truncate; /* enables vacuum to truncate a relation */
343 
344 #define HEAP_MIN_FILLFACTOR 10
345 #define HEAP_DEFAULT_FILLFACTOR 100
346 
347 /*
348  * RelationGetToastTupleTarget
349  * Returns the relation's toast_tuple_target. Note multiple eval of argument!
350  */
351 #define RelationGetToastTupleTarget(relation, defaulttarg) \
352  ((relation)->rd_options ? \
353  ((StdRdOptions *) (relation)->rd_options)->toast_tuple_target : (defaulttarg))
354 
355 /*
356  * RelationGetFillFactor
357  * Returns the relation's fillfactor. Note multiple eval of argument!
358  */
359 #define RelationGetFillFactor(relation, defaultff) \
360  ((relation)->rd_options ? \
361  ((StdRdOptions *) (relation)->rd_options)->fillfactor : (defaultff))
362 
363 /*
364  * RelationGetTargetPageUsage
365  * Returns the relation's desired space usage per page in bytes.
366  */
367 #define RelationGetTargetPageUsage(relation, defaultff) \
368  (BLCKSZ * RelationGetFillFactor(relation, defaultff) / 100)
369 
370 /*
371  * RelationGetTargetPageFreeSpace
372  * Returns the relation's desired freespace per page in bytes.
373  */
374 #define RelationGetTargetPageFreeSpace(relation, defaultff) \
375  (BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100)
376 
377 /*
378  * RelationIsUsedAsCatalogTable
379  * Returns whether the relation should be treated as a catalog table
380  * from the pov of logical decoding. Note multiple eval of argument!
381  */
382 #define RelationIsUsedAsCatalogTable(relation) \
383  ((relation)->rd_options && \
384  ((relation)->rd_rel->relkind == RELKIND_RELATION || \
385  (relation)->rd_rel->relkind == RELKIND_MATVIEW) ? \
386  ((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
387 
388 /*
389  * RelationGetParallelWorkers
390  * Returns the relation's parallel_workers reloption setting.
391  * Note multiple eval of argument!
392  */
393 #define RelationGetParallelWorkers(relation, defaultpw) \
394  ((relation)->rd_options ? \
395  ((StdRdOptions *) (relation)->rd_options)->parallel_workers : (defaultpw))
396 
397 /* ViewOptions->check_option values */
398 typedef enum ViewOptCheckOption
399 {
404 
405 /*
406  * ViewOptions
407  * Contents of rd_options for views
408  */
409 typedef struct ViewOptions
410 {
411  int32 vl_len_; /* varlena header (do not touch directly!) */
416 
417 /*
418  * RelationIsSecurityView
419  * Returns whether the relation is security view, or not. Note multiple
420  * eval of argument!
421  */
422 #define RelationIsSecurityView(relation) \
423  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
424  (relation)->rd_options ? \
425  ((ViewOptions *) (relation)->rd_options)->security_barrier : false)
426 
427 /*
428  * RelationHasSecurityInvoker
429  * Returns true if the relation has the security_invoker property set.
430  * Note multiple eval of argument!
431  */
432 #define RelationHasSecurityInvoker(relation) \
433  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
434  (relation)->rd_options ? \
435  ((ViewOptions *) (relation)->rd_options)->security_invoker : false)
436 
437 /*
438  * RelationHasCheckOption
439  * Returns true if the relation is a view defined with either the local
440  * or the cascaded check option. Note multiple eval of argument!
441  */
442 #define RelationHasCheckOption(relation) \
443  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
444  (relation)->rd_options && \
445  ((ViewOptions *) (relation)->rd_options)->check_option != \
446  VIEW_OPTION_CHECK_OPTION_NOT_SET)
447 
448 /*
449  * RelationHasLocalCheckOption
450  * Returns true if the relation is a view defined with the local check
451  * option. Note multiple eval of argument!
452  */
453 #define RelationHasLocalCheckOption(relation) \
454  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
455  (relation)->rd_options && \
456  ((ViewOptions *) (relation)->rd_options)->check_option == \
457  VIEW_OPTION_CHECK_OPTION_LOCAL)
458 
459 /*
460  * RelationHasCascadedCheckOption
461  * Returns true if the relation is a view defined with the cascaded check
462  * option. Note multiple eval of argument!
463  */
464 #define RelationHasCascadedCheckOption(relation) \
465  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
466  (relation)->rd_options && \
467  ((ViewOptions *) (relation)->rd_options)->check_option == \
468  VIEW_OPTION_CHECK_OPTION_CASCADED)
469 
470 /*
471  * RelationIsValid
472  * True iff relation descriptor is valid.
473  */
474 #define RelationIsValid(relation) PointerIsValid(relation)
475 
476 #define InvalidRelation ((Relation) NULL)
477 
478 /*
479  * RelationHasReferenceCountZero
480  * True iff relation reference count is zero.
481  *
482  * Note:
483  * Assumes relation descriptor is valid.
484  */
485 #define RelationHasReferenceCountZero(relation) \
486  ((bool)((relation)->rd_refcnt == 0))
487 
488 /*
489  * RelationGetForm
490  * Returns pg_class tuple for a relation.
491  *
492  * Note:
493  * Assumes relation descriptor is valid.
494  */
495 #define RelationGetForm(relation) ((relation)->rd_rel)
496 
497 /*
498  * RelationGetRelid
499  * Returns the OID of the relation
500  */
501 #define RelationGetRelid(relation) ((relation)->rd_id)
502 
503 /*
504  * RelationGetNumberOfAttributes
505  * Returns the total number of attributes in a relation.
506  */
507 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
508 
509 /*
510  * IndexRelationGetNumberOfAttributes
511  * Returns the number of attributes in an index.
512  */
513 #define IndexRelationGetNumberOfAttributes(relation) \
514  ((relation)->rd_index->indnatts)
515 
516 /*
517  * IndexRelationGetNumberOfKeyAttributes
518  * Returns the number of key attributes in an index.
519  */
520 #define IndexRelationGetNumberOfKeyAttributes(relation) \
521  ((relation)->rd_index->indnkeyatts)
522 
523 /*
524  * RelationGetDescr
525  * Returns tuple descriptor for a relation.
526  */
527 #define RelationGetDescr(relation) ((relation)->rd_att)
528 
529 /*
530  * RelationGetRelationName
531  * Returns the rel's name.
532  *
533  * Note that the name is only unique within the containing namespace.
534  */
535 #define RelationGetRelationName(relation) \
536  (NameStr((relation)->rd_rel->relname))
537 
538 /*
539  * RelationGetNamespace
540  * Returns the rel's namespace OID.
541  */
542 #define RelationGetNamespace(relation) \
543  ((relation)->rd_rel->relnamespace)
544 
545 /*
546  * RelationIsMapped
547  * True if the relation uses the relfilenumber map. Note multiple eval
548  * of argument!
549  */
550 #define RelationIsMapped(relation) \
551  (RELKIND_HAS_STORAGE((relation)->rd_rel->relkind) && \
552  ((relation)->rd_rel->relfilenode == InvalidRelFileNumber))
553 
554 #ifndef FRONTEND
555 /*
556  * RelationGetSmgr
557  * Returns smgr file handle for a relation, opening it if needed.
558  *
559  * Very little code is authorized to touch rel->rd_smgr directly. Instead
560  * use this function to fetch its value.
561  *
562  * Note: since a relcache flush can cause the file handle to be closed again,
563  * it's unwise to hold onto the pointer returned by this function for any
564  * long period. Recommended practice is to just re-execute RelationGetSmgr
565  * each time you need to access the SMgrRelation. It's quite cheap in
566  * comparison to whatever an smgr function is going to do.
567  */
568 static inline SMgrRelation
570 {
571  if (unlikely(rel->rd_smgr == NULL))
572  smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_locator, rel->rd_backend));
573  return rel->rd_smgr;
574 }
575 
576 /*
577  * RelationCloseSmgr
578  * Close the relation at the smgr level, if not already done.
579  */
580 static inline void
582 {
583  if (relation->rd_smgr != NULL)
584  smgrclose(relation->rd_smgr);
585 
586  /* smgrclose should unhook from owner pointer */
587  Assert(relation->rd_smgr == NULL);
588 }
589 #endif /* !FRONTEND */
590 
591 /*
592  * RelationGetTargetBlock
593  * Fetch relation's current insertion target block.
594  *
595  * Returns InvalidBlockNumber if there is no current target block. Note
596  * that the target block status is discarded on any smgr-level invalidation,
597  * so there's no need to re-open the smgr handle if it's not currently open.
598  */
599 #define RelationGetTargetBlock(relation) \
600  ( (relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber )
601 
602 /*
603  * RelationSetTargetBlock
604  * Set relation's current insertion target block.
605  */
606 #define RelationSetTargetBlock(relation, targblock) \
607  do { \
608  RelationGetSmgr(relation)->smgr_targblock = (targblock); \
609  } while (0)
610 
611 /*
612  * RelationIsPermanent
613  * True if relation is permanent.
614  */
615 #define RelationIsPermanent(relation) \
616  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
617 
618 /*
619  * RelationNeedsWAL
620  * True if relation needs WAL.
621  *
622  * Returns false if wal_level = minimal and this relation is created or
623  * truncated in the current transaction. See "Skipping WAL for New
624  * RelFileLocator" in src/backend/access/transam/README.
625  */
626 #define RelationNeedsWAL(relation) \
627  (RelationIsPermanent(relation) && (XLogIsNeeded() || \
628  (relation->rd_createSubid == InvalidSubTransactionId && \
629  relation->rd_firstRelfilelocatorSubid == InvalidSubTransactionId)))
630 
631 /*
632  * RelationUsesLocalBuffers
633  * True if relation's pages are stored in local buffers.
634  */
635 #define RelationUsesLocalBuffers(relation) \
636  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
637 
638 /*
639  * RELATION_IS_LOCAL
640  * If a rel is either temp or newly created in the current transaction,
641  * it can be assumed to be accessible only to the current backend.
642  * This is typically used to decide that we can skip acquiring locks.
643  *
644  * Beware of multiple eval of argument
645  */
646 #define RELATION_IS_LOCAL(relation) \
647  ((relation)->rd_islocaltemp || \
648  (relation)->rd_createSubid != InvalidSubTransactionId)
649 
650 /*
651  * RELATION_IS_OTHER_TEMP
652  * Test for a temporary relation that belongs to some other session.
653  *
654  * Beware of multiple eval of argument
655  */
656 #define RELATION_IS_OTHER_TEMP(relation) \
657  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \
658  !(relation)->rd_islocaltemp)
659 
660 
661 /*
662  * RelationIsScannable
663  * Currently can only be false for a materialized view which has not been
664  * populated by its query. This is likely to get more complicated later,
665  * so use a macro which looks like a function.
666  */
667 #define RelationIsScannable(relation) ((relation)->rd_rel->relispopulated)
668 
669 /*
670  * RelationIsPopulated
671  * Currently, we don't physically distinguish the "populated" and
672  * "scannable" properties of matviews, but that may change later.
673  * Hence, use the appropriate one of these macros in code tests.
674  */
675 #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated)
676 
677 /*
678  * RelationIsAccessibleInLogicalDecoding
679  * True if we need to log enough information to have access via
680  * decoding snapshot.
681  */
682 #define RelationIsAccessibleInLogicalDecoding(relation) \
683  (XLogLogicalInfoActive() && \
684  RelationNeedsWAL(relation) && \
685  (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation)))
686 
687 /*
688  * RelationIsLogicallyLogged
689  * True if we need to log enough information to extract the data from the
690  * WAL stream.
691  *
692  * We don't log information for unlogged tables (since they don't WAL log
693  * anyway), for foreign tables (since they don't WAL log, either),
694  * and for system tables (their content is hard to make sense of, and
695  * it would complicate decoding slightly for little gain). Note that we *do*
696  * log information for user defined catalog tables since they presumably are
697  * interesting to the user...
698  */
699 #define RelationIsLogicallyLogged(relation) \
700  (XLogLogicalInfoActive() && \
701  RelationNeedsWAL(relation) && \
702  (relation)->rd_rel->relkind != RELKIND_FOREIGN_TABLE && \
703  !IsCatalogRelation(relation))
704 
705 /* routines in utils/cache/relcache.c */
708 
709 #endif /* REL_H */
int16 AttrNumber
Definition: attnum.h:21
int BackendId
Definition: backendid.h:21
unsigned short uint16
Definition: c.h:441
signed short int16
Definition: c.h:429
uint32 SubTransactionId
Definition: c.h:592
signed int int32
Definition: c.h:430
double float8
Definition: c.h:566
regproc RegProcedure
Definition: c.h:586
#define unlikely(x)
Definition: c.h:295
uint32 TransactionId
Definition: c.h:588
Assert(fmt[strlen(fmt) - 1] !='\n')
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:70
unsigned int Oid
Definition: postgres_ext.h:31
LockInfoData * LockInfo
Definition: rel.h:48
struct LockRelId LockRelId
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2140
ViewOptCheckOption
Definition: rel.h:399
@ VIEW_OPTION_CHECK_OPTION_NOT_SET
Definition: rel.h:400
@ VIEW_OPTION_CHECK_OPTION_LOCAL
Definition: rel.h:401
@ VIEW_OPTION_CHECK_OPTION_CASCADED
Definition: rel.h:402
struct ForeignKeyCacheInfo ForeignKeyCacheInfo
static SMgrRelation RelationGetSmgr(Relation rel)
Definition: rel.h:569
void RelationIncrementReferenceCount(Relation rel)
Definition: relcache.c:2127
struct StdRdOptions StdRdOptions
struct ViewOptions ViewOptions
struct LockInfoData LockInfoData
struct AutoVacOpts AutoVacOpts
struct RelationData RelationData
static void RelationCloseSmgr(Relation relation)
Definition: rel.h:581
StdRdOptIndexCleanup
Definition: rel.h:326
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO
Definition: rel.h:327
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF
Definition: rel.h:328
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON
Definition: rel.h:329
void smgrsetowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:198
void smgrclose(SMgrRelation reln)
Definition: smgr.c:256
SMgrRelation smgropen(RelFileLocator rlocator, BackendId backend)
Definition: smgr.c:146
int vacuum_ins_threshold
Definition: rel.h:308
int log_min_duration
Definition: rel.h:317
float8 vacuum_cost_delay
Definition: rel.h:318
int multixact_freeze_max_age
Definition: rel.h:315
int vacuum_cost_limit
Definition: rel.h:310
float8 vacuum_scale_factor
Definition: rel.h:319
int analyze_threshold
Definition: rel.h:309
float8 vacuum_ins_scale_factor
Definition: rel.h:320
bool enabled
Definition: rel.h:306
int multixact_freeze_table_age
Definition: rel.h:316
int freeze_min_age
Definition: rel.h:311
int freeze_table_age
Definition: rel.h:313
int freeze_max_age
Definition: rel.h:312
int vacuum_threshold
Definition: rel.h:307
int multixact_freeze_min_age
Definition: rel.h:314
float8 analyze_scale_factor
Definition: rel.h:321
Definition: fmgr.h:57
AttrNumber confkey[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys))
Oid conpfeqop[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys))
AttrNumber conkey[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys))
pg_node_attr(no_equal, no_read) NodeTag type
Definition: pg_list.h:52
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:146
bool pgstat_enabled
Definition: rel.h:249
Bitmapset * rd_keyattr
Definition: rel.h:160
bool rd_partcheckvalid
Definition: rel.h:147
MemoryContext rd_pdcxt
Definition: rel.h:130
Oid rd_toastoid
Definition: rel.h:247
MemoryContext rd_partkeycxt
Definition: rel.h:126
const struct TableAmRoutine * rd_tableam
Definition: rel.h:185
TransactionId rd_partdesc_nodetached_xmin
Definition: rel.h:143
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:121
Oid * rd_exclprocs
Definition: rel.h:211
SubTransactionId rd_firstRelfilelocatorSubid
Definition: rel.h:105
LockInfoData rd_lockInfo
Definition: rel.h:113
uint16 * rd_exclstrats
Definition: rel.h:212
List * rd_indexlist
Definition: rel.h:151
struct RowSecurityDesc * rd_rsdesc
Definition: rel.h:118
PartitionDesc rd_partdesc
Definition: rel.h:129
Oid rd_replidindex
Definition: rel.h:153
int rd_refcnt
Definition: rel.h:58
RegProcedure * rd_support
Definition: rel.h:205
PartitionDesc rd_partdesc_nodetached
Definition: rel.h:133
bytea ** rd_opcoptions
Definition: rel.h:214
PublicationDesc * rd_pubdesc
Definition: rel.h:164
struct FdwRoutine * rd_fdwroutine
Definition: rel.h:236
TriggerDesc * trigdesc
Definition: rel.h:116
Bitmapset * rd_idattr
Definition: rel.h:162
bool rd_isvalid
Definition: rel.h:62
bool rd_islocaltemp
Definition: rel.h:60
List * rd_indexprs
Definition: rel.h:208
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:148
int16 * rd_indoption
Definition: rel.h:207
TupleDesc rd_att
Definition: rel.h:111
Bitmapset * rd_indexattr
Definition: rel.h:159
Form_pg_index rd_index
Definition: rel.h:188
void * rd_amcache
Definition: rel.h:225
bool rd_isnailed
Definition: rel.h:61
Oid rd_id
Definition: rel.h:112
Oid rd_pkindex
Definition: rel.h:152
SubTransactionId rd_newRelfilelocatorSubid
Definition: rel.h:103
bool rd_fkeyvalid
Definition: rel.h:122
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:156
MemoryContext rd_pddcxt
Definition: rel.h:134
RelFileLocator rd_locator
Definition: rel.h:56
RuleLock * rd_rules
Definition: rel.h:114
struct FmgrInfo * rd_supportinfo
Definition: rel.h:206
Oid * rd_opfamily
Definition: rel.h:203
SubTransactionId rd_droppedSubid
Definition: rel.h:108
MemoryContext rd_rulescxt
Definition: rel.h:115
Bitmapset * rd_pkattr
Definition: rel.h:161
PartitionKey rd_partkey
Definition: rel.h:125
bytea * rd_options
Definition: rel.h:171
Oid * rd_indcollation
Definition: rel.h:213
Form_pg_class rd_rel
Definition: rel.h:110
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:251
int32 vl_len_
Definition: rel.h:334
bool user_catalog_table
Definition: rel.h:338
StdRdOptIndexCleanup vacuum_index_cleanup
Definition: rel.h:340
int fillfactor
Definition: rel.h:335
AutoVacOpts autovacuum
Definition: rel.h:337
int toast_tuple_target
Definition: rel.h:336
int parallel_workers
Definition: rel.h:339
bool vacuum_truncate
Definition: rel.h:341
bool security_invoker
Definition: rel.h:413
int32 vl_len_
Definition: rel.h:411
bool security_barrier
Definition: rel.h:412
ViewOptCheckOption check_option
Definition: rel.h:414
Definition: c.h:623