tidbitmap.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*-------------------------------------------------------------------------
  2. *
  3. * tidbitmap.h
  4. * PostgreSQL tuple-id (TID) bitmap package
  5. *
  6. * This module provides bitmap data structures that are spiritually
  7. * similar to Bitmapsets, but are specially adapted to store sets of
  8. * tuple identifiers (TIDs), or ItemPointers. In particular, the division
  9. * of an ItemPointer into BlockNumber and OffsetNumber is catered for.
  10. * Also, since we wish to be able to store very large tuple sets in
  11. * memory with this data structure, we support "lossy" storage, in which
  12. * we no longer remember individual tuple offsets on a page but only the
  13. * fact that a particular page needs to be visited.
  14. *
  15. *
  16. * Copyright (c) 2003-2022, PostgreSQL Global Development Group
  17. *
  18. * src/include/nodes/tidbitmap.h
  19. *
  20. *-------------------------------------------------------------------------
  21. */
  22. #ifndef TIDBITMAP_H
  23. #define TIDBITMAP_H
  24. #include "storage/itemptr.h"
  25. #include "utils/dsa.h"
  26. /*
  27. * Actual bitmap representation is private to tidbitmap.c. Callers can
  28. * do IsA(x, TIDBitmap) on it, but nothing else.
  29. */
  30. typedef struct TIDBitmap TIDBitmap;
  31. /* Likewise, TBMIterator is private */
  32. typedef struct TBMIterator TBMIterator;
  33. typedef struct TBMSharedIterator TBMSharedIterator;
  34. /* Result structure for tbm_iterate */
  35. typedef struct TBMIterateResult
  36. {
  37. BlockNumber blockno; /* page number containing tuples */
  38. int ntuples; /* -1 indicates lossy result */
  39. bool recheck; /* should the tuples be rechecked? */
  40. /* Note: recheck is always true if ntuples < 0 */
  41. OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
  42. } TBMIterateResult;
  43. /* function prototypes in nodes/tidbitmap.c */
  44. extern TIDBitmap *tbm_create(long maxbytes, dsa_area *dsa);
  45. extern void tbm_free(TIDBitmap *tbm);
  46. extern void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp);
  47. extern void tbm_add_tuples(TIDBitmap *tbm,
  48. const ItemPointer tids, int ntids,
  49. bool recheck);
  50. extern void tbm_add_page(TIDBitmap *tbm, BlockNumber pageno);
  51. extern void tbm_union(TIDBitmap *a, const TIDBitmap *b);
  52. extern void tbm_intersect(TIDBitmap *a, const TIDBitmap *b);
  53. extern bool tbm_is_empty(const TIDBitmap *tbm);
  54. extern TBMIterator *tbm_begin_iterate(TIDBitmap *tbm);
  55. extern dsa_pointer tbm_prepare_shared_iterate(TIDBitmap *tbm);
  56. extern TBMIterateResult *tbm_iterate(TBMIterator *iterator);
  57. extern TBMIterateResult *tbm_shared_iterate(TBMSharedIterator *iterator);
  58. extern void tbm_end_iterate(TBMIterator *iterator);
  59. extern void tbm_end_shared_iterate(TBMSharedIterator *iterator);
  60. extern TBMSharedIterator *tbm_attach_shared_iterate(dsa_area *dsa,
  61. dsa_pointer dp);
  62. extern long tbm_calculate_entries(double maxbytes);
  63. #endif /* TIDBITMAP_H */