LCOV - code coverage report
Current view: top level - src/include/catalog - index.h (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 10 10
Test Date: 2026-04-07 14:16:30 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  * index.h
       4              :  *    prototypes for catalog/index.c.
       5              :  *
       6              :  *
       7              :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       8              :  * Portions Copyright (c) 1994, Regents of the University of California
       9              :  *
      10              :  * src/include/catalog/index.h
      11              :  *
      12              :  *-------------------------------------------------------------------------
      13              :  */
      14              : #ifndef INDEX_H
      15              : #define INDEX_H
      16              : 
      17              : #include "catalog/objectaddress.h"
      18              : #include "nodes/execnodes.h"
      19              : 
      20              : 
      21              : /*
      22              :  * forward references in this file
      23              :  */
      24              : typedef struct AttrMap AttrMap;
      25              : 
      26              : 
      27              : #define DEFAULT_INDEX_TYPE  "btree"
      28              : 
      29              : /* Action code for index_set_state_flags */
      30              : typedef enum
      31              : {
      32              :     INDEX_CREATE_SET_READY,
      33              :     INDEX_CREATE_SET_VALID,
      34              :     INDEX_DROP_CLEAR_VALID,
      35              :     INDEX_DROP_SET_DEAD,
      36              : } IndexStateFlagsAction;
      37              : 
      38              : /* options for REINDEX */
      39              : typedef struct ReindexParams
      40              : {
      41              :     uint32      options;        /* bitmask of REINDEXOPT_* */
      42              :     Oid         tablespaceOid;  /* New tablespace to move indexes to.
      43              :                                  * InvalidOid to do nothing. */
      44              : } ReindexParams;
      45              : 
      46              : /* flag bits for ReindexParams->flags */
      47              : #define REINDEXOPT_VERBOSE      0x01    /* print progress info */
      48              : #define REINDEXOPT_REPORT_PROGRESS 0x02 /* report pgstat progress */
      49              : #define REINDEXOPT_MISSING_OK   0x04    /* skip missing relations */
      50              : #define REINDEXOPT_CONCURRENTLY 0x08    /* concurrent mode */
      51              : 
      52              : /* state info for validate_index bulkdelete callback */
      53              : typedef struct ValidateIndexState
      54              : {
      55              :     Tuplesortstate *tuplesort;  /* for sorting the index TIDs */
      56              :     /* statistics (for debug purposes only): */
      57              :     double      htups,
      58              :                 itups,
      59              :                 tups_inserted;
      60              : } ValidateIndexState;
      61              : 
      62              : extern void index_check_primary_key(Relation heapRel,
      63              :                                     const IndexInfo *indexInfo,
      64              :                                     bool is_alter_table,
      65              :                                     const IndexStmt *stmt);
      66              : 
      67              : #define INDEX_CREATE_IS_PRIMARY             (1 << 0)
      68              : #define INDEX_CREATE_ADD_CONSTRAINT         (1 << 1)
      69              : #define INDEX_CREATE_SKIP_BUILD             (1 << 2)
      70              : #define INDEX_CREATE_CONCURRENT             (1 << 3)
      71              : #define INDEX_CREATE_IF_NOT_EXISTS          (1 << 4)
      72              : #define INDEX_CREATE_PARTITIONED            (1 << 5)
      73              : #define INDEX_CREATE_INVALID                (1 << 6)
      74              : #define INDEX_CREATE_SUPPRESS_PROGRESS      (1 << 7)
      75              : 
      76              : extern Oid  index_create(Relation heapRelation,
      77              :                          const char *indexRelationName,
      78              :                          Oid indexRelationId,
      79              :                          Oid parentIndexRelid,
      80              :                          Oid parentConstraintId,
      81              :                          RelFileNumber relFileNumber,
      82              :                          IndexInfo *indexInfo,
      83              :                          const List *indexColNames,
      84              :                          Oid accessMethodId,
      85              :                          Oid tableSpaceId,
      86              :                          const Oid *collationIds,
      87              :                          const Oid *opclassIds,
      88              :                          const Datum *opclassOptions,
      89              :                          const int16 *coloptions,
      90              :                          const NullableDatum *stattargets,
      91              :                          Datum reloptions,
      92              :                          uint16 flags,
      93              :                          uint16 constr_flags,
      94              :                          bool allow_system_table_mods,
      95              :                          bool is_internal,
      96              :                          Oid *constraintId);
      97              : 
      98              : #define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY (1 << 0)
      99              : #define INDEX_CONSTR_CREATE_DEFERRABLE      (1 << 1)
     100              : #define INDEX_CONSTR_CREATE_INIT_DEFERRED   (1 << 2)
     101              : #define INDEX_CONSTR_CREATE_UPDATE_INDEX    (1 << 3)
     102              : #define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS (1 << 4)
     103              : #define INDEX_CONSTR_CREATE_WITHOUT_OVERLAPS (1 << 5)
     104              : 
     105              : extern Oid  index_create_copy(Relation heapRelation, uint16 flags,
     106              :                               Oid oldIndexId, Oid tablespaceOid,
     107              :                               const char *newName);
     108              : 
     109              : extern void index_concurrently_build(Oid heapRelationId,
     110              :                                      Oid indexRelationId);
     111              : 
     112              : extern void index_concurrently_swap(Oid newIndexId,
     113              :                                     Oid oldIndexId,
     114              :                                     const char *oldName);
     115              : 
     116              : extern void index_concurrently_set_dead(Oid heapId,
     117              :                                         Oid indexId);
     118              : 
     119              : extern ObjectAddress index_constraint_create(Relation heapRelation,
     120              :                                              Oid indexRelationId,
     121              :                                              Oid parentConstraintId,
     122              :                                              const IndexInfo *indexInfo,
     123              :                                              const char *constraintName,
     124              :                                              char constraintType,
     125              :                                              uint16 constr_flags,
     126              :                                              bool allow_system_table_mods,
     127              :                                              bool is_internal);
     128              : 
     129              : extern void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode);
     130              : 
     131              : extern IndexInfo *BuildIndexInfo(Relation index);
     132              : 
     133              : extern IndexInfo *BuildDummyIndexInfo(Relation index);
     134              : 
     135              : extern bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2,
     136              :                              const Oid *collations1, const Oid *collations2,
     137              :                              const Oid *opfamilies1, const Oid *opfamilies2,
     138              :                              const AttrMap *attmap);
     139              : 
     140              : extern void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii);
     141              : 
     142              : extern void FormIndexDatum(IndexInfo *indexInfo,
     143              :                            TupleTableSlot *slot,
     144              :                            EState *estate,
     145              :                            Datum *values,
     146              :                            bool *isnull);
     147              : 
     148              : extern void index_build(Relation heapRelation,
     149              :                         Relation indexRelation,
     150              :                         IndexInfo *indexInfo,
     151              :                         bool isreindex,
     152              :                         bool parallel,
     153              :                         bool progress);
     154              : 
     155              : extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
     156              : 
     157              : extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action);
     158              : 
     159              : extern Oid  IndexGetRelation(Oid indexId, bool missing_ok);
     160              : 
     161              : extern void reindex_index(const ReindexStmt *stmt, Oid indexId,
     162              :                           bool skip_constraint_checks, char persistence,
     163              :                           const ReindexParams *params);
     164              : 
     165              : /* Flag bits for reindex_relation(): */
     166              : #define REINDEX_REL_PROCESS_TOAST           0x01
     167              : #define REINDEX_REL_SUPPRESS_INDEX_USE      0x02
     168              : #define REINDEX_REL_CHECK_CONSTRAINTS       0x04
     169              : #define REINDEX_REL_FORCE_INDEXES_UNLOGGED  0x08
     170              : #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
     171              : 
     172              : extern bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags,
     173              :                              const ReindexParams *params);
     174              : 
     175              : extern bool ReindexIsProcessingHeap(Oid heapOid);
     176              : extern bool ReindexIsProcessingIndex(Oid indexOid);
     177              : 
     178              : extern void ResetReindexState(int nestLevel);
     179              : extern Size EstimateReindexStateSpace(void);
     180              : extern void SerializeReindexState(Size maxsize, char *start_address);
     181              : extern void RestoreReindexState(const void *reindexstate);
     182              : 
     183              : extern void IndexSetParentIndex(Relation partitionIdx, Oid parentOid);
     184              : 
     185              : 
     186              : /*
     187              :  * itemptr_encode - Encode ItemPointer as int64/int8
     188              :  *
     189              :  * This representation must produce values encoded as int64 that sort in the
     190              :  * same order as their corresponding original TID values would (using the
     191              :  * default int8 opclass to produce a result equivalent to the default TID
     192              :  * opclass).
     193              :  *
     194              :  * As noted in validate_index(), this can be significantly faster.
     195              :  */
     196              : static inline int64
     197       157747 : itemptr_encode(const ItemPointerData *itemptr)
     198              : {
     199       157747 :     BlockNumber block = ItemPointerGetBlockNumber(itemptr);
     200       157747 :     OffsetNumber offset = ItemPointerGetOffsetNumber(itemptr);
     201              :     int64       encoded;
     202              : 
     203              :     /*
     204              :      * Use the 16 least significant bits for the offset.  32 adjacent bits are
     205              :      * used for the block number.  Since remaining bits are unused, there
     206              :      * cannot be negative encoded values (We assume a two's complement
     207              :      * representation).
     208              :      */
     209       157747 :     encoded = ((uint64) block << 16) | (uint16) offset;
     210              : 
     211       157747 :     return encoded;
     212              : }
     213              : 
     214              : /*
     215              :  * itemptr_decode - Decode int64/int8 representation back to ItemPointer
     216              :  */
     217              : static inline void
     218       157639 : itemptr_decode(ItemPointer itemptr, int64 encoded)
     219              : {
     220       157639 :     BlockNumber block = (BlockNumber) (encoded >> 16);
     221       157639 :     OffsetNumber offset = (OffsetNumber) (encoded & 0xFFFF);
     222              : 
     223       157639 :     ItemPointerSet(itemptr, block, offset);
     224       157639 : }
     225              : 
     226              : #endif                          /* INDEX_H */
        

Generated by: LCOV version 2.0-1