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-2023, 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  bool rd_attrsvalid; /* are bitmaps of attrs valid? */
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  Bitmapset *rd_hotblockingattr; /* cols blocking HOT update */
164  Bitmapset *rd_summarizedattr; /* cols indexed by summarizing indexes */
165 
166  PublicationDesc *rd_pubdesc; /* publication descriptor, or NULL */
167 
168  /*
169  * rd_options is set whenever rd_rel is loaded into the relcache entry.
170  * Note that you can NOT look into rd_rel for this data. NULL means "use
171  * defaults".
172  */
173  bytea *rd_options; /* parsed pg_class.reloptions */
174 
175  /*
176  * Oid of the handler for this relation. For an index this is a function
177  * returning IndexAmRoutine, for table like relations a function returning
178  * TableAmRoutine. This is stored separately from rd_indam, rd_tableam as
179  * its lookup requires syscache access, but during relcache bootstrap we
180  * need to be able to initialize rd_tableam without syscache lookups.
181  */
182  Oid rd_amhandler; /* OID of index AM's handler function */
183 
184  /*
185  * Table access method.
186  */
187  const struct TableAmRoutine *rd_tableam;
188 
189  /* These are non-NULL only for an index relation: */
190  Form_pg_index rd_index; /* pg_index tuple describing this index */
191  /* use "struct" here to avoid needing to include htup.h: */
192  struct HeapTupleData *rd_indextuple; /* all of pg_index tuple */
193 
194  /*
195  * index access support info (used only for an index relation)
196  *
197  * Note: only default support procs for each opclass are cached, namely
198  * those with lefttype and righttype equal to the opclass's opcintype. The
199  * arrays are indexed by support function number, which is a sufficient
200  * identifier given that restriction.
201  */
202  MemoryContext rd_indexcxt; /* private memory cxt for this stuff */
203  /* use "struct" here to avoid needing to include amapi.h: */
204  struct IndexAmRoutine *rd_indam; /* index AM's API struct */
205  Oid *rd_opfamily; /* OIDs of op families for each index col */
206  Oid *rd_opcintype; /* OIDs of opclass declared input data types */
207  RegProcedure *rd_support; /* OIDs of support procedures */
208  struct FmgrInfo *rd_supportinfo; /* lookup info for support procedures */
209  int16 *rd_indoption; /* per-column AM-specific flags */
210  List *rd_indexprs; /* index expression trees, if any */
211  List *rd_indpred; /* index predicate tree, if any */
212  Oid *rd_exclops; /* OIDs of exclusion operators, if any */
213  Oid *rd_exclprocs; /* OIDs of exclusion ops' procs, if any */
214  uint16 *rd_exclstrats; /* exclusion ops' strategy numbers, if any */
215  Oid *rd_indcollation; /* OIDs of index collations */
216  bytea **rd_opcoptions; /* parsed opclass-specific options */
217 
218  /*
219  * rd_amcache is available for index and table AMs to cache private data
220  * about the relation. This must be just a cache since it may get reset
221  * at any time (in particular, it will get reset by a relcache inval
222  * message for the relation). If used, it must point to a single memory
223  * chunk palloc'd in CacheMemoryContext, or in rd_indexcxt for an index
224  * relation. A relcache reset will include freeing that chunk and setting
225  * rd_amcache = NULL.
226  */
227  void *rd_amcache; /* available for use by index/table AM */
228 
229  /*
230  * foreign-table support
231  *
232  * rd_fdwroutine must point to a single memory chunk palloc'd in
233  * CacheMemoryContext. It will be freed and reset to NULL on a relcache
234  * reset.
235  */
236 
237  /* use "struct" here to avoid needing to include fdwapi.h: */
238  struct FdwRoutine *rd_fdwroutine; /* cached function pointers, or NULL */
239 
240  /*
241  * Hack for CLUSTER, rewriting ALTER TABLE, etc: when writing a new
242  * version of a table, we need to make any toast pointers inserted into it
243  * have the existing toast table's OID, not the OID of the transient toast
244  * table. If rd_toastoid isn't InvalidOid, it is the OID to place in
245  * toast pointers inserted into this rel. (Note it's set on the new
246  * version of the main heap, not the toast table itself.) This also
247  * causes toast_save_datum() to try to preserve toast value OIDs.
248  */
249  Oid rd_toastoid; /* Real TOAST table's OID, or InvalidOid */
250 
251  bool pgstat_enabled; /* should relation stats be counted */
252  /* use "struct" here to avoid needing to include pgstat.h: */
253  struct PgStat_TableStatus *pgstat_info; /* statistics collection area */
255 
256 
257 /*
258  * ForeignKeyCacheInfo
259  * Information the relcache can cache about foreign key constraints
260  *
261  * This is basically just an image of relevant columns from pg_constraint.
262  * We make it a subclass of Node so that copyObject() can be used on a list
263  * of these, but we also ensure it is a "flat" object without substructure,
264  * so that list_free_deep() is sufficient to free such a list.
265  * The per-FK-column arrays can be fixed-size because we allow at most
266  * INDEX_MAX_KEYS columns in a foreign key constraint.
267  *
268  * Currently, we mostly cache fields of interest to the planner, but the set
269  * of fields has already grown the constraint OID for other uses.
270  */
271 typedef struct ForeignKeyCacheInfo
272 {
273  pg_node_attr(no_equal, no_read, no_query_jumble)
274 
275  NodeTag type;
276  /* oid of the constraint itself */
278  /* relation constrained by the foreign key */
280  /* relation referenced by the foreign key */
282  /* number of columns in the foreign key */
283  int nkeys;
284 
285  /*
286  * these arrays each have nkeys valid entries:
287  */
288  /* cols in referencing table */
290  /* cols in referenced table */
292  /* PK = FK operator OIDs */
293  Oid conpfeqop[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys));
295 
296 
297 /*
298  * StdRdOptions
299  * Standard contents of rd_options for heaps.
300  *
301  * RelationGetFillFactor() and RelationGetTargetPageFreeSpace() can only
302  * be applied to relations that use this format or a superset for
303  * private options data.
304  */
305  /* autovacuum-related reloptions. */
306 typedef struct AutoVacOpts
307 {
308  bool enabled;
325 
326 /* StdRdOptions->vacuum_index_cleanup values */
328 {
333 
334 typedef struct StdRdOptions
335 {
336  int32 vl_len_; /* varlena header (do not touch directly!) */
337  int fillfactor; /* page fill factor in percent (0..100) */
338  int toast_tuple_target; /* target for tuple toasting */
339  AutoVacOpts autovacuum; /* autovacuum-related options */
340  bool user_catalog_table; /* use as an additional catalog relation */
341  int parallel_workers; /* max number of parallel workers */
342  StdRdOptIndexCleanup vacuum_index_cleanup; /* controls index vacuuming */
343  bool vacuum_truncate; /* enables vacuum to truncate a relation */
345 
346 #define HEAP_MIN_FILLFACTOR 10
347 #define HEAP_DEFAULT_FILLFACTOR 100
348 
349 /*
350  * RelationGetToastTupleTarget
351  * Returns the relation's toast_tuple_target. Note multiple eval of argument!
352  */
353 #define RelationGetToastTupleTarget(relation, defaulttarg) \
354  ((relation)->rd_options ? \
355  ((StdRdOptions *) (relation)->rd_options)->toast_tuple_target : (defaulttarg))
356 
357 /*
358  * RelationGetFillFactor
359  * Returns the relation's fillfactor. Note multiple eval of argument!
360  */
361 #define RelationGetFillFactor(relation, defaultff) \
362  ((relation)->rd_options ? \
363  ((StdRdOptions *) (relation)->rd_options)->fillfactor : (defaultff))
364 
365 /*
366  * RelationGetTargetPageUsage
367  * Returns the relation's desired space usage per page in bytes.
368  */
369 #define RelationGetTargetPageUsage(relation, defaultff) \
370  (BLCKSZ * RelationGetFillFactor(relation, defaultff) / 100)
371 
372 /*
373  * RelationGetTargetPageFreeSpace
374  * Returns the relation's desired freespace per page in bytes.
375  */
376 #define RelationGetTargetPageFreeSpace(relation, defaultff) \
377  (BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100)
378 
379 /*
380  * RelationIsUsedAsCatalogTable
381  * Returns whether the relation should be treated as a catalog table
382  * from the pov of logical decoding. Note multiple eval of argument!
383  */
384 #define RelationIsUsedAsCatalogTable(relation) \
385  ((relation)->rd_options && \
386  ((relation)->rd_rel->relkind == RELKIND_RELATION || \
387  (relation)->rd_rel->relkind == RELKIND_MATVIEW) ? \
388  ((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
389 
390 /*
391  * RelationGetParallelWorkers
392  * Returns the relation's parallel_workers reloption setting.
393  * Note multiple eval of argument!
394  */
395 #define RelationGetParallelWorkers(relation, defaultpw) \
396  ((relation)->rd_options ? \
397  ((StdRdOptions *) (relation)->rd_options)->parallel_workers : (defaultpw))
398 
399 /* ViewOptions->check_option values */
400 typedef enum ViewOptCheckOption
401 {
406 
407 /*
408  * ViewOptions
409  * Contents of rd_options for views
410  */
411 typedef struct ViewOptions
412 {
413  int32 vl_len_; /* varlena header (do not touch directly!) */
418 
419 /*
420  * RelationIsSecurityView
421  * Returns whether the relation is security view, or not. Note multiple
422  * eval of argument!
423  */
424 #define RelationIsSecurityView(relation) \
425  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
426  (relation)->rd_options ? \
427  ((ViewOptions *) (relation)->rd_options)->security_barrier : false)
428 
429 /*
430  * RelationHasSecurityInvoker
431  * Returns true if the relation has the security_invoker property set.
432  * Note multiple eval of argument!
433  */
434 #define RelationHasSecurityInvoker(relation) \
435  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
436  (relation)->rd_options ? \
437  ((ViewOptions *) (relation)->rd_options)->security_invoker : false)
438 
439 /*
440  * RelationHasCheckOption
441  * Returns true if the relation is a view defined with either the local
442  * or the cascaded check option. Note multiple eval of argument!
443  */
444 #define RelationHasCheckOption(relation) \
445  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
446  (relation)->rd_options && \
447  ((ViewOptions *) (relation)->rd_options)->check_option != \
448  VIEW_OPTION_CHECK_OPTION_NOT_SET)
449 
450 /*
451  * RelationHasLocalCheckOption
452  * Returns true if the relation is a view defined with the local check
453  * option. Note multiple eval of argument!
454  */
455 #define RelationHasLocalCheckOption(relation) \
456  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
457  (relation)->rd_options && \
458  ((ViewOptions *) (relation)->rd_options)->check_option == \
459  VIEW_OPTION_CHECK_OPTION_LOCAL)
460 
461 /*
462  * RelationHasCascadedCheckOption
463  * Returns true if the relation is a view defined with the cascaded check
464  * option. Note multiple eval of argument!
465  */
466 #define RelationHasCascadedCheckOption(relation) \
467  (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
468  (relation)->rd_options && \
469  ((ViewOptions *) (relation)->rd_options)->check_option == \
470  VIEW_OPTION_CHECK_OPTION_CASCADED)
471 
472 /*
473  * RelationIsValid
474  * True iff relation descriptor is valid.
475  */
476 #define RelationIsValid(relation) PointerIsValid(relation)
477 
478 #define InvalidRelation ((Relation) NULL)
479 
480 /*
481  * RelationHasReferenceCountZero
482  * True iff relation reference count is zero.
483  *
484  * Note:
485  * Assumes relation descriptor is valid.
486  */
487 #define RelationHasReferenceCountZero(relation) \
488  ((bool)((relation)->rd_refcnt == 0))
489 
490 /*
491  * RelationGetForm
492  * Returns pg_class tuple for a relation.
493  *
494  * Note:
495  * Assumes relation descriptor is valid.
496  */
497 #define RelationGetForm(relation) ((relation)->rd_rel)
498 
499 /*
500  * RelationGetRelid
501  * Returns the OID of the relation
502  */
503 #define RelationGetRelid(relation) ((relation)->rd_id)
504 
505 /*
506  * RelationGetNumberOfAttributes
507  * Returns the total number of attributes in a relation.
508  */
509 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
510 
511 /*
512  * IndexRelationGetNumberOfAttributes
513  * Returns the number of attributes in an index.
514  */
515 #define IndexRelationGetNumberOfAttributes(relation) \
516  ((relation)->rd_index->indnatts)
517 
518 /*
519  * IndexRelationGetNumberOfKeyAttributes
520  * Returns the number of key attributes in an index.
521  */
522 #define IndexRelationGetNumberOfKeyAttributes(relation) \
523  ((relation)->rd_index->indnkeyatts)
524 
525 /*
526  * RelationGetDescr
527  * Returns tuple descriptor for a relation.
528  */
529 #define RelationGetDescr(relation) ((relation)->rd_att)
530 
531 /*
532  * RelationGetRelationName
533  * Returns the rel's name.
534  *
535  * Note that the name is only unique within the containing namespace.
536  */
537 #define RelationGetRelationName(relation) \
538  (NameStr((relation)->rd_rel->relname))
539 
540 /*
541  * RelationGetNamespace
542  * Returns the rel's namespace OID.
543  */
544 #define RelationGetNamespace(relation) \
545  ((relation)->rd_rel->relnamespace)
546 
547 /*
548  * RelationIsMapped
549  * True if the relation uses the relfilenumber map. Note multiple eval
550  * of argument!
551  */
552 #define RelationIsMapped(relation) \
553  (RELKIND_HAS_STORAGE((relation)->rd_rel->relkind) && \
554  ((relation)->rd_rel->relfilenode == InvalidRelFileNumber))
555 
556 #ifndef FRONTEND
557 /*
558  * RelationGetSmgr
559  * Returns smgr file handle for a relation, opening it if needed.
560  *
561  * Very little code is authorized to touch rel->rd_smgr directly. Instead
562  * use this function to fetch its value.
563  *
564  * Note: since a relcache flush can cause the file handle to be closed again,
565  * it's unwise to hold onto the pointer returned by this function for any
566  * long period. Recommended practice is to just re-execute RelationGetSmgr
567  * each time you need to access the SMgrRelation. It's quite cheap in
568  * comparison to whatever an smgr function is going to do.
569  */
570 static inline SMgrRelation
572 {
573  if (unlikely(rel->rd_smgr == NULL))
574  smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_locator, rel->rd_backend));
575  return rel->rd_smgr;
576 }
577 
578 /*
579  * RelationCloseSmgr
580  * Close the relation at the smgr level, if not already done.
581  */
582 static inline void
584 {
585  if (relation->rd_smgr != NULL)
586  smgrclose(relation->rd_smgr);
587 
588  /* smgrclose should unhook from owner pointer */
589  Assert(relation->rd_smgr == NULL);
590 }
591 #endif /* !FRONTEND */
592 
593 /*
594  * RelationGetTargetBlock
595  * Fetch relation's current insertion target block.
596  *
597  * Returns InvalidBlockNumber if there is no current target block. Note
598  * that the target block status is discarded on any smgr-level invalidation,
599  * so there's no need to re-open the smgr handle if it's not currently open.
600  */
601 #define RelationGetTargetBlock(relation) \
602  ( (relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber )
603 
604 /*
605  * RelationSetTargetBlock
606  * Set relation's current insertion target block.
607  */
608 #define RelationSetTargetBlock(relation, targblock) \
609  do { \
610  RelationGetSmgr(relation)->smgr_targblock = (targblock); \
611  } while (0)
612 
613 /*
614  * RelationIsPermanent
615  * True if relation is permanent.
616  */
617 #define RelationIsPermanent(relation) \
618  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
619 
620 /*
621  * RelationNeedsWAL
622  * True if relation needs WAL.
623  *
624  * Returns false if wal_level = minimal and this relation is created or
625  * truncated in the current transaction. See "Skipping WAL for New
626  * RelFileLocator" in src/backend/access/transam/README.
627  */
628 #define RelationNeedsWAL(relation) \
629  (RelationIsPermanent(relation) && (XLogIsNeeded() || \
630  (relation->rd_createSubid == InvalidSubTransactionId && \
631  relation->rd_firstRelfilelocatorSubid == InvalidSubTransactionId)))
632 
633 /*
634  * RelationUsesLocalBuffers
635  * True if relation's pages are stored in local buffers.
636  */
637 #define RelationUsesLocalBuffers(relation) \
638  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
639 
640 /*
641  * RELATION_IS_LOCAL
642  * If a rel is either temp or newly created in the current transaction,
643  * it can be assumed to be accessible only to the current backend.
644  * This is typically used to decide that we can skip acquiring locks.
645  *
646  * Beware of multiple eval of argument
647  */
648 #define RELATION_IS_LOCAL(relation) \
649  ((relation)->rd_islocaltemp || \
650  (relation)->rd_createSubid != InvalidSubTransactionId)
651 
652 /*
653  * RELATION_IS_OTHER_TEMP
654  * Test for a temporary relation that belongs to some other session.
655  *
656  * Beware of multiple eval of argument
657  */
658 #define RELATION_IS_OTHER_TEMP(relation) \
659  ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \
660  !(relation)->rd_islocaltemp)
661 
662 
663 /*
664  * RelationIsScannable
665  * Currently can only be false for a materialized view which has not been
666  * populated by its query. This is likely to get more complicated later,
667  * so use a macro which looks like a function.
668  */
669 #define RelationIsScannable(relation) ((relation)->rd_rel->relispopulated)
670 
671 /*
672  * RelationIsPopulated
673  * Currently, we don't physically distinguish the "populated" and
674  * "scannable" properties of matviews, but that may change later.
675  * Hence, use the appropriate one of these macros in code tests.
676  */
677 #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated)
678 
679 /*
680  * RelationIsAccessibleInLogicalDecoding
681  * True if we need to log enough information to have access via
682  * decoding snapshot.
683  */
684 #define RelationIsAccessibleInLogicalDecoding(relation) \
685  (XLogLogicalInfoActive() && \
686  RelationNeedsWAL(relation) && \
687  (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation)))
688 
689 /*
690  * RelationIsLogicallyLogged
691  * True if we need to log enough information to extract the data from the
692  * WAL stream.
693  *
694  * We don't log information for unlogged tables (since they don't WAL log
695  * anyway), for foreign tables (since they don't WAL log, either),
696  * and for system tables (their content is hard to make sense of, and
697  * it would complicate decoding slightly for little gain). Note that we *do*
698  * log information for user defined catalog tables since they presumably are
699  * interesting to the user...
700  */
701 #define RelationIsLogicallyLogged(relation) \
702  (XLogLogicalInfoActive() && \
703  RelationNeedsWAL(relation) && \
704  (relation)->rd_rel->relkind != RELKIND_FOREIGN_TABLE && \
705  !IsCatalogRelation(relation))
706 
707 /* routines in utils/cache/relcache.c */
710 
711 #endif /* REL_H */
int16 AttrNumber
Definition: attnum.h:21
int BackendId
Definition: backendid.h:21
unsigned short uint16
Definition: c.h:489
signed short int16
Definition: c.h:477
uint32 SubTransactionId
Definition: c.h:640
signed int int32
Definition: c.h:478
double float8
Definition: c.h:614
regproc RegProcedure
Definition: c.h:634
#define unlikely(x)
Definition: c.h:295
uint32 TransactionId
Definition: c.h:636
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:401
@ VIEW_OPTION_CHECK_OPTION_NOT_SET
Definition: rel.h:402
@ VIEW_OPTION_CHECK_OPTION_LOCAL
Definition: rel.h:403
@ VIEW_OPTION_CHECK_OPTION_CASCADED
Definition: rel.h:404
struct ForeignKeyCacheInfo ForeignKeyCacheInfo
static SMgrRelation RelationGetSmgr(Relation rel)
Definition: rel.h:571
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:583
StdRdOptIndexCleanup
Definition: rel.h:328
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO
Definition: rel.h:329
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF
Definition: rel.h:330
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON
Definition: rel.h:331
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:310
int log_min_duration
Definition: rel.h:319
float8 vacuum_cost_delay
Definition: rel.h:320
int multixact_freeze_max_age
Definition: rel.h:317
int vacuum_cost_limit
Definition: rel.h:312
float8 vacuum_scale_factor
Definition: rel.h:321
int analyze_threshold
Definition: rel.h:311
float8 vacuum_ins_scale_factor
Definition: rel.h:322
bool enabled
Definition: rel.h:308
int multixact_freeze_table_age
Definition: rel.h:318
int freeze_min_age
Definition: rel.h:313
int freeze_table_age
Definition: rel.h:315
int freeze_max_age
Definition: rel.h:314
int vacuum_threshold
Definition: rel.h:309
int multixact_freeze_min_age
Definition: rel.h:316
float8 analyze_scale_factor
Definition: rel.h:323
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, no_query_jumble) NodeTag type
Definition: pg_list.h:54
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:251
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:249
MemoryContext rd_partkeycxt
Definition: rel.h:126
const struct TableAmRoutine * rd_tableam
Definition: rel.h:187
TransactionId rd_partdesc_nodetached_xmin
Definition: rel.h:143
bool rd_indexvalid
Definition: rel.h:63
List * rd_indpred
Definition: rel.h:211
struct IndexAmRoutine * rd_indam
Definition: rel.h:204
List * rd_fkeylist
Definition: rel.h:121
Oid * rd_exclprocs
Definition: rel.h:213
SubTransactionId rd_firstRelfilelocatorSubid
Definition: rel.h:105
LockInfoData rd_lockInfo
Definition: rel.h:113
uint16 * rd_exclstrats
Definition: rel.h:214
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:207
PartitionDesc rd_partdesc_nodetached
Definition: rel.h:133
bytea ** rd_opcoptions
Definition: rel.h:216
PublicationDesc * rd_pubdesc
Definition: rel.h:166
struct FdwRoutine * rd_fdwroutine
Definition: rel.h:238
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:210
bool rd_attrsvalid
Definition: rel.h:159
Oid * rd_exclops
Definition: rel.h:212
Oid * rd_opcintype
Definition: rel.h:206
struct HeapTupleData * rd_indextuple
Definition: rel.h:192
MemoryContext rd_partcheckcxt
Definition: rel.h:148
int16 * rd_indoption
Definition: rel.h:209
TupleDesc rd_att
Definition: rel.h:111
Form_pg_index rd_index
Definition: rel.h:190
Bitmapset * rd_hotblockingattr
Definition: rel.h:163
void * rd_amcache
Definition: rel.h:227
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:182
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:202
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:208
Oid * rd_opfamily
Definition: rel.h:205
SubTransactionId rd_droppedSubid
Definition: rel.h:108
MemoryContext rd_rulescxt
Definition: rel.h:115
Bitmapset * rd_summarizedattr
Definition: rel.h:164
Bitmapset * rd_pkattr
Definition: rel.h:161
PartitionKey rd_partkey
Definition: rel.h:125
bytea * rd_options
Definition: rel.h:173
Oid * rd_indcollation
Definition: rel.h:215
Form_pg_class rd_rel
Definition: rel.h:110
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:253
int32 vl_len_
Definition: rel.h:336
bool user_catalog_table
Definition: rel.h:340
StdRdOptIndexCleanup vacuum_index_cleanup
Definition: rel.h:342
int fillfactor
Definition: rel.h:337
AutoVacOpts autovacuum
Definition: rel.h:339
int toast_tuple_target
Definition: rel.h:338
int parallel_workers
Definition: rel.h:341
bool vacuum_truncate
Definition: rel.h:343
bool security_invoker
Definition: rel.h:415
int32 vl_len_
Definition: rel.h:413
bool security_barrier
Definition: rel.h:414
ViewOptCheckOption check_option
Definition: rel.h:416
Definition: c.h:671