@@ -170,12 +170,12 @@ struct TIDBitmap
170
170
};
171
171
172
172
/*
173
- * When iterating over a bitmap in sorted order, a TBMIterator is used to
174
- * track our progress. There can be several iterators scanning the same
175
- * bitmap concurrently. Note that the bitmap becomes read-only as soon as
176
- * any iterator is created.
173
+ * When iterating over a backend-local bitmap in sorted order, a
174
+ * TBMPrivateIterator is used to track our progress. There can be several
175
+ * iterators scanning the same bitmap concurrently. Note that the bitmap
176
+ * becomes read-only as soon as any iterator is created.
177
177
*/
178
- struct TBMIterator
178
+ struct TBMPrivateIterator
179
179
{
180
180
TIDBitmap * tbm ; /* TIDBitmap we're iterating over */
181
181
int spageptr ; /* next spages index */
@@ -213,8 +213,8 @@ typedef struct PTIterationArray
213
213
} PTIterationArray ;
214
214
215
215
/*
216
- * same as TBMIterator , but it is used for joint iteration, therefore this
217
- * also holds a reference to the shared state.
216
+ * same as TBMPrivateIterator , but it is used for joint iteration, therefore
217
+ * this also holds a reference to the shared state.
218
218
*/
219
219
struct TBMSharedIterator
220
220
{
@@ -673,31 +673,32 @@ tbm_is_empty(const TIDBitmap *tbm)
673
673
}
674
674
675
675
/*
676
- * tbm_begin_iterate - prepare to iterate through a TIDBitmap
676
+ * tbm_begin_private_iterate - prepare to iterate through a TIDBitmap
677
677
*
678
- * The TBMIterator struct is created in the caller's memory context.
679
- * For a clean shutdown of the iteration, call tbm_end_iterate ; but it's
680
- * okay to just allow the memory context to be released, too. It is caller's
681
- * responsibility not to touch the TBMIterator anymore once the TIDBitmap
682
- * is freed.
678
+ * The TBMPrivateIterator struct is created in the caller's memory context.
679
+ * For a clean shutdown of the iteration, call tbm_end_private_iterate ; but
680
+ * it's okay to just allow the memory context to be released, too. It is
681
+ * caller's responsibility not to touch the TBMPrivateIterator anymore once
682
+ * the TIDBitmap is freed.
683
683
*
684
684
* NB: after this is called, it is no longer allowed to modify the contents
685
685
* of the bitmap. However, you can call this multiple times to scan the
686
686
* contents repeatedly, including parallel scans.
687
687
*/
688
- TBMIterator *
689
- tbm_begin_iterate (TIDBitmap * tbm )
688
+ TBMPrivateIterator *
689
+ tbm_begin_private_iterate (TIDBitmap * tbm )
690
690
{
691
- TBMIterator * iterator ;
691
+ TBMPrivateIterator * iterator ;
692
692
693
693
Assert (tbm -> iterating != TBM_ITERATING_SHARED );
694
694
695
695
/*
696
- * Create the TBMIterator struct, with enough trailing space to serve the
697
- * needs of the TBMIterateResult sub-struct.
696
+ * Create the TBMPrivateIterator struct, with enough trailing space to
697
+ * serve the needs of the TBMIterateResult sub-struct.
698
698
*/
699
- iterator = (TBMIterator * ) palloc (sizeof (TBMIterator ) +
700
- MAX_TUPLES_PER_PAGE * sizeof (OffsetNumber ));
699
+ iterator = (TBMPrivateIterator * ) palloc (sizeof (TBMPrivateIterator ) +
700
+ MAX_TUPLES_PER_PAGE *
701
+ sizeof (OffsetNumber ));
701
702
iterator -> tbm = tbm ;
702
703
703
704
/*
@@ -878,7 +879,7 @@ tbm_prepare_shared_iterate(TIDBitmap *tbm)
878
879
ptchunks = dsa_get_address (tbm -> dsa , tbm -> ptchunks );
879
880
880
881
/*
881
- * For every shared iterator, referring to pagetable and iterator array,
882
+ * For every shared iterator referring to pagetable and iterator array,
882
883
* increase the refcount by 1 so that while freeing the shared iterator we
883
884
* don't free pagetable and iterator array until its refcount becomes 0.
884
885
*/
@@ -956,7 +957,7 @@ tbm_advance_schunkbit(PagetableEntry *chunk, int *schunkbitp)
956
957
}
957
958
958
959
/*
959
- * tbm_iterate - scan through next page of a TIDBitmap
960
+ * tbm_private_iterate - scan through next page of a TIDBitmap
960
961
*
961
962
* Returns a TBMIterateResult representing one page, or NULL if there are
962
963
* no more pages to scan. Pages are guaranteed to be delivered in numerical
@@ -968,7 +969,7 @@ tbm_advance_schunkbit(PagetableEntry *chunk, int *schunkbitp)
968
969
* testing, recheck is always set true when ntuples < 0.)
969
970
*/
970
971
TBMIterateResult *
971
- tbm_iterate ( TBMIterator * iterator )
972
+ tbm_private_iterate ( TBMPrivateIterator * iterator )
972
973
{
973
974
TIDBitmap * tbm = iterator -> tbm ;
974
975
TBMIterateResult * output = & (iterator -> output );
@@ -1136,14 +1137,14 @@ tbm_shared_iterate(TBMSharedIterator *iterator)
1136
1137
}
1137
1138
1138
1139
/*
1139
- * tbm_end_iterate - finish an iteration over a TIDBitmap
1140
+ * tbm_end_private_iterate - finish an iteration over a TIDBitmap
1140
1141
*
1141
1142
* Currently this is just a pfree, but it might do more someday. (For
1142
1143
* instance, it could be useful to count open iterators and allow the
1143
1144
* bitmap to return to read/write status when there are no more iterators.)
1144
1145
*/
1145
1146
void
1146
- tbm_end_iterate ( TBMIterator * iterator )
1147
+ tbm_end_private_iterate ( TBMPrivateIterator * iterator )
1147
1148
{
1148
1149
pfree (iterator );
1149
1150
}
@@ -1556,3 +1557,66 @@ tbm_calculate_entries(double maxbytes)
1556
1557
1557
1558
return nbuckets ;
1558
1559
}
1560
+
1561
+ /*
1562
+ * Create a shared or private bitmap iterator and start iteration.
1563
+ *
1564
+ * `tbm` is only used to create the private iterator and dsa and dsp are only
1565
+ * used to create the shared iterator.
1566
+ *
1567
+ * Before invoking tbm_begin_iterate() to create a shared iterator, one
1568
+ * process must already have invoked tbm_prepare_shared_iterate() to create
1569
+ * and set up the TBMSharedIteratorState.
1570
+ */
1571
+ TBMIterator
1572
+ tbm_begin_iterate (TIDBitmap * tbm , dsa_area * dsa , dsa_pointer dsp )
1573
+ {
1574
+ TBMIterator iterator = {0 };
1575
+
1576
+ /* Allocate a private iterator and attach the shared state to it */
1577
+ if (DsaPointerIsValid (dsp ))
1578
+ {
1579
+ iterator .shared = true;
1580
+ iterator .i .shared_iterator = tbm_attach_shared_iterate (dsa , dsp );
1581
+ }
1582
+ else
1583
+ {
1584
+ iterator .shared = false;
1585
+ iterator .i .private_iterator = tbm_begin_private_iterate (tbm );
1586
+ }
1587
+
1588
+ return iterator ;
1589
+ }
1590
+
1591
+ /*
1592
+ * Clean up shared or private bitmap iterator.
1593
+ */
1594
+ void
1595
+ tbm_end_iterate (TBMIterator * iterator )
1596
+ {
1597
+ Assert (iterator );
1598
+
1599
+ if (iterator -> shared )
1600
+ tbm_end_shared_iterate (iterator -> i .shared_iterator );
1601
+ else
1602
+ tbm_end_private_iterate (iterator -> i .private_iterator );
1603
+
1604
+ * iterator = (TBMIterator )
1605
+ {
1606
+ 0
1607
+ };
1608
+ }
1609
+
1610
+ /*
1611
+ * Get the next TBMIterateResult from the shared or private bitmap iterator.
1612
+ */
1613
+ TBMIterateResult *
1614
+ tbm_iterate (TBMIterator * iterator )
1615
+ {
1616
+ Assert (iterator );
1617
+
1618
+ if (iterator -> shared )
1619
+ return tbm_shared_iterate (iterator -> i .shared_iterator );
1620
+ else
1621
+ return tbm_private_iterate (iterator -> i .private_iterator );
1622
+ }
0 commit comments