brin_internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * brin_internal.h
  3. * internal declarations for BRIN indexes
  4. *
  5. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  6. * Portions Copyright (c) 1994, Regents of the University of California
  7. *
  8. * IDENTIFICATION
  9. * src/include/access/brin_internal.h
  10. */
  11. #ifndef BRIN_INTERNAL_H
  12. #define BRIN_INTERNAL_H
  13. #include "access/amapi.h"
  14. #include "storage/bufpage.h"
  15. #include "utils/typcache.h"
  16. /*
  17. * A BrinDesc is a struct designed to enable decoding a BRIN tuple from the
  18. * on-disk format to an in-memory tuple and vice-versa.
  19. */
  20. /* struct returned by "OpcInfo" amproc */
  21. typedef struct BrinOpcInfo
  22. {
  23. /* Number of columns stored in an index column of this opclass */
  24. uint16 oi_nstored;
  25. /* Regular processing of NULLs in BrinValues? */
  26. bool oi_regular_nulls;
  27. /* Opaque pointer for the opclass' private use */
  28. void *oi_opaque;
  29. /* Type cache entries of the stored columns */
  30. TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];
  31. } BrinOpcInfo;
  32. /* the size of a BrinOpcInfo for the given number of columns */
  33. #define SizeofBrinOpcInfo(ncols) \
  34. (offsetof(BrinOpcInfo, oi_typcache) + sizeof(TypeCacheEntry *) * ncols)
  35. typedef struct BrinDesc
  36. {
  37. /* Containing memory context */
  38. MemoryContext bd_context;
  39. /* the index relation itself */
  40. Relation bd_index;
  41. /* tuple descriptor of the index relation */
  42. TupleDesc bd_tupdesc;
  43. /* cached copy for on-disk tuples; generated at first use */
  44. TupleDesc bd_disktdesc;
  45. /* total number of Datum entries that are stored on-disk for all columns */
  46. int bd_totalstored;
  47. /* per-column info; bd_tupdesc->natts entries long */
  48. BrinOpcInfo *bd_info[FLEXIBLE_ARRAY_MEMBER];
  49. } BrinDesc;
  50. /*
  51. * Globally-known function support numbers for BRIN indexes. Individual
  52. * opclasses can define more function support numbers, which must fall into
  53. * BRIN_FIRST_OPTIONAL_PROCNUM .. BRIN_LAST_OPTIONAL_PROCNUM.
  54. */
  55. #define BRIN_PROCNUM_OPCINFO 1
  56. #define BRIN_PROCNUM_ADDVALUE 2
  57. #define BRIN_PROCNUM_CONSISTENT 3
  58. #define BRIN_PROCNUM_UNION 4
  59. #define BRIN_MANDATORY_NPROCS 4
  60. #define BRIN_PROCNUM_OPTIONS 5 /* optional */
  61. /* procedure numbers up to 10 are reserved for BRIN future expansion */
  62. #define BRIN_FIRST_OPTIONAL_PROCNUM 11
  63. #define BRIN_LAST_OPTIONAL_PROCNUM 15
  64. #undef BRIN_DEBUG
  65. #ifdef BRIN_DEBUG
  66. #define BRIN_elog(args) elog args
  67. #else
  68. #define BRIN_elog(args) ((void) 0)
  69. #endif
  70. /* brin.c */
  71. extern BrinDesc *brin_build_desc(Relation rel);
  72. extern void brin_free_desc(BrinDesc *bdesc);
  73. extern IndexBuildResult *brinbuild(Relation heap, Relation index,
  74. struct IndexInfo *indexInfo);
  75. extern void brinbuildempty(Relation index);
  76. extern bool brininsert(Relation idxRel, Datum *values, bool *nulls,
  77. ItemPointer heaptid, Relation heapRel,
  78. IndexUniqueCheck checkUnique,
  79. bool indexUnchanged,
  80. struct IndexInfo *indexInfo);
  81. extern IndexScanDesc brinbeginscan(Relation r, int nkeys, int norderbys);
  82. extern int64 bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
  83. extern void brinrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
  84. ScanKey orderbys, int norderbys);
  85. extern void brinendscan(IndexScanDesc scan);
  86. extern IndexBulkDeleteResult *brinbulkdelete(IndexVacuumInfo *info,
  87. IndexBulkDeleteResult *stats,
  88. IndexBulkDeleteCallback callback,
  89. void *callback_state);
  90. extern IndexBulkDeleteResult *brinvacuumcleanup(IndexVacuumInfo *info,
  91. IndexBulkDeleteResult *stats);
  92. extern bytea *brinoptions(Datum reloptions, bool validate);
  93. /* brin_validate.c */
  94. extern bool brinvalidate(Oid opclassoid);
  95. #endif /* BRIN_INTERNAL_H */