PostgreSQL Source Code  git master
nodeBitmapHeapscan.c File Reference
#include "postgres.h"
#include <math.h>
#include "access/relscan.h"
#include "access/tableam.h"
#include "access/transam.h"
#include "access/visibilitymap.h"
#include "executor/execdebug.h"
#include "executor/nodeBitmapHeapscan.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/predicate.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/spccache.h"
Include dependency graph for nodeBitmapHeapscan.c:

Go to the source code of this file.

Functions

static TupleTableSlotBitmapHeapNext (BitmapHeapScanState *node)
 
static void BitmapDoneInitializingSharedState (ParallelBitmapHeapState *pstate)
 
static void BitmapAdjustPrefetchIterator (BitmapHeapScanState *node, TBMIterateResult *tbmres)
 
static void BitmapAdjustPrefetchTarget (BitmapHeapScanState *node)
 
static void BitmapPrefetch (BitmapHeapScanState *node, TableScanDesc scan)
 
static bool BitmapShouldInitializeSharedState (ParallelBitmapHeapState *pstate)
 
static bool BitmapHeapRecheck (BitmapHeapScanState *node, TupleTableSlot *slot)
 
static TupleTableSlotExecBitmapHeapScan (PlanState *pstate)
 
void ExecReScanBitmapHeapScan (BitmapHeapScanState *node)
 
void ExecEndBitmapHeapScan (BitmapHeapScanState *node)
 
BitmapHeapScanStateExecInitBitmapHeapScan (BitmapHeapScan *node, EState *estate, int eflags)
 
void ExecBitmapHeapEstimate (BitmapHeapScanState *node, ParallelContext *pcxt)
 
void ExecBitmapHeapInitializeDSM (BitmapHeapScanState *node, ParallelContext *pcxt)
 
void ExecBitmapHeapReInitializeDSM (BitmapHeapScanState *node, ParallelContext *pcxt)
 
void ExecBitmapHeapInitializeWorker (BitmapHeapScanState *node, ParallelWorkerContext *pwcxt)
 

Function Documentation

◆ BitmapAdjustPrefetchIterator()

static void BitmapAdjustPrefetchIterator ( BitmapHeapScanState node,
TBMIterateResult tbmres 
)
inlinestatic

Definition at line 360 of file nodeBitmapHeapscan.c.

References TBMIterateResult::blockno, elog, ERROR, ParallelBitmapHeapState::mutex, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::prefetch_maximum, ParallelBitmapHeapState::prefetch_pages, BitmapHeapScanState::prefetch_pages, BitmapHeapScanState::pstate, BitmapHeapScanState::shared_prefetch_iterator, SpinLockAcquire, SpinLockRelease, tbm_iterate(), and tbm_shared_iterate().

Referenced by BitmapHeapNext().

362 {
363 #ifdef USE_PREFETCH
364  ParallelBitmapHeapState *pstate = node->pstate;
365 
366  if (pstate == NULL)
367  {
368  TBMIterator *prefetch_iterator = node->prefetch_iterator;
369 
370  if (node->prefetch_pages > 0)
371  {
372  /* The main iterator has closed the distance by one page */
373  node->prefetch_pages--;
374  }
375  else if (prefetch_iterator)
376  {
377  /* Do not let the prefetch iterator get behind the main one */
378  TBMIterateResult *tbmpre = tbm_iterate(prefetch_iterator);
379 
380  if (tbmpre == NULL || tbmpre->blockno != tbmres->blockno)
381  elog(ERROR, "prefetch and main iterators are out of sync");
382  }
383  return;
384  }
385 
386  if (node->prefetch_maximum > 0)
387  {
388  TBMSharedIterator *prefetch_iterator = node->shared_prefetch_iterator;
389 
390  SpinLockAcquire(&pstate->mutex);
391  if (pstate->prefetch_pages > 0)
392  {
393  pstate->prefetch_pages--;
394  SpinLockRelease(&pstate->mutex);
395  }
396  else
397  {
398  /* Release the mutex before iterating */
399  SpinLockRelease(&pstate->mutex);
400 
401  /*
402  * In case of shared mode, we can not ensure that the current
403  * blockno of the main iterator and that of the prefetch iterator
404  * are same. It's possible that whatever blockno we are
405  * prefetching will be processed by another process. Therefore,
406  * we don't validate the blockno here as we do in non-parallel
407  * case.
408  */
409  if (prefetch_iterator)
410  tbm_shared_iterate(prefetch_iterator);
411  }
412  }
413 #endif /* USE_PREFETCH */
414 }
BlockNumber blockno
Definition: tidbitmap.h:42
#define SpinLockAcquire(lock)
Definition: spin.h:62
#define ERROR
Definition: elog.h:43
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1598
#define SpinLockRelease(lock)
Definition: spin.h:64
TBMIterateResult * tbm_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:970
TBMIterateResult * tbm_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1051
TBMIterator * prefetch_iterator
Definition: execnodes.h:1590
#define elog(elevel,...)
Definition: elog.h:228
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1597

◆ BitmapAdjustPrefetchTarget()

static void BitmapAdjustPrefetchTarget ( BitmapHeapScanState node)
inlinestatic

Definition at line 425 of file nodeBitmapHeapscan.c.

References ParallelBitmapHeapState::mutex, BitmapHeapScanState::prefetch_maximum, ParallelBitmapHeapState::prefetch_target, BitmapHeapScanState::prefetch_target, BitmapHeapScanState::pstate, SpinLockAcquire, and SpinLockRelease.

Referenced by BitmapHeapNext().

426 {
427 #ifdef USE_PREFETCH
428  ParallelBitmapHeapState *pstate = node->pstate;
429 
430  if (pstate == NULL)
431  {
432  if (node->prefetch_target >= node->prefetch_maximum)
433  /* don't increase any further */ ;
434  else if (node->prefetch_target >= node->prefetch_maximum / 2)
435  node->prefetch_target = node->prefetch_maximum;
436  else if (node->prefetch_target > 0)
437  node->prefetch_target *= 2;
438  else
439  node->prefetch_target++;
440  return;
441  }
442 
443  /* Do an unlocked check first to save spinlock acquisitions. */
444  if (pstate->prefetch_target < node->prefetch_maximum)
445  {
446  SpinLockAcquire(&pstate->mutex);
447  if (pstate->prefetch_target >= node->prefetch_maximum)
448  /* don't increase any further */ ;
449  else if (pstate->prefetch_target >= node->prefetch_maximum / 2)
450  pstate->prefetch_target = node->prefetch_maximum;
451  else if (pstate->prefetch_target > 0)
452  pstate->prefetch_target *= 2;
453  else
454  pstate->prefetch_target++;
455  SpinLockRelease(&pstate->mutex);
456  }
457 #endif /* USE_PREFETCH */
458 }
#define SpinLockAcquire(lock)
Definition: spin.h:62
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1598
#define SpinLockRelease(lock)
Definition: spin.h:64

◆ BitmapDoneInitializingSharedState()

static void BitmapDoneInitializingSharedState ( ParallelBitmapHeapState pstate)
inlinestatic

Definition at line 348 of file nodeBitmapHeapscan.c.

References BM_FINISHED, ConditionVariableBroadcast(), ParallelBitmapHeapState::cv, ParallelBitmapHeapState::mutex, SpinLockAcquire, SpinLockRelease, and ParallelBitmapHeapState::state.

Referenced by BitmapHeapNext().

349 {
350  SpinLockAcquire(&pstate->mutex);
351  pstate->state = BM_FINISHED;
352  SpinLockRelease(&pstate->mutex);
353  ConditionVariableBroadcast(&pstate->cv);
354 }
void ConditionVariableBroadcast(ConditionVariable *cv)
#define SpinLockAcquire(lock)
Definition: spin.h:62
#define SpinLockRelease(lock)
Definition: spin.h:64
SharedBitmapState state
Definition: execnodes.h:1548
ConditionVariable cv
Definition: execnodes.h:1549

◆ BitmapHeapNext()

static TupleTableSlot * BitmapHeapNext ( BitmapHeapScanState node)
static

Definition at line 72 of file nodeBitmapHeapscan.c.

References Assert, BitmapAdjustPrefetchIterator(), BitmapAdjustPrefetchTarget(), BitmapDoneInitializingSharedState(), BitmapPrefetch(), BitmapHeapScanState::bitmapqualorig, BitmapShouldInitializeSharedState(), TBMIterateResult::blockno, BitmapHeapScanState::can_skip_fetch, CHECK_FOR_INTERRUPTS, ExprContext::ecxt_scantuple, elog, ERROR, EState::es_query_dsa, BitmapHeapScanState::exact_pages, ExecClearTuple(), ExecQualAndReset(), ExecStoreAllNullTuple(), BitmapHeapScanState::initialized, InstrCountFiltered2, IsA, BitmapHeapScanState::lossy_pages, MultiExecProcNode(), ParallelBitmapHeapState::mutex, TBMIterateResult::ntuples, outerPlanState, ParallelBitmapHeapState::prefetch_iterator, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::prefetch_maximum, ParallelBitmapHeapState::prefetch_pages, BitmapHeapScanState::prefetch_pages, ParallelBitmapHeapState::prefetch_target, BitmapHeapScanState::prefetch_target, ScanState::ps, PlanState::ps_ExprContext, BitmapHeapScanState::pstate, TBMIterateResult::recheck, BitmapHeapScanState::return_empty_tuples, BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, SpinLockAcquire, SpinLockRelease, BitmapHeapScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, ScanState::ss_ScanTupleSlot, PlanState::state, table_scan_bitmap_next_block(), table_scan_bitmap_next_tuple(), BitmapHeapScanState::tbm, tbm_attach_shared_iterate(), tbm_begin_iterate(), tbm_iterate(), tbm_prepare_shared_iterate(), tbm_shared_iterate(), ParallelBitmapHeapState::tbmiterator, BitmapHeapScanState::tbmiterator, BitmapHeapScanState::tbmres, VM_ALL_VISIBLE, and BitmapHeapScanState::vmbuffer.

Referenced by ExecBitmapHeapScan().

73 {
74  ExprContext *econtext;
75  TableScanDesc scan;
76  TIDBitmap *tbm;
77  TBMIterator *tbmiterator = NULL;
78  TBMSharedIterator *shared_tbmiterator = NULL;
79  TBMIterateResult *tbmres;
80  TupleTableSlot *slot;
81  ParallelBitmapHeapState *pstate = node->pstate;
82  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
83 
84  /*
85  * extract necessary information from index scan node
86  */
87  econtext = node->ss.ps.ps_ExprContext;
88  slot = node->ss.ss_ScanTupleSlot;
89  scan = node->ss.ss_currentScanDesc;
90  tbm = node->tbm;
91  if (pstate == NULL)
92  tbmiterator = node->tbmiterator;
93  else
94  shared_tbmiterator = node->shared_tbmiterator;
95  tbmres = node->tbmres;
96 
97  /*
98  * If we haven't yet performed the underlying index scan, do it, and begin
99  * the iteration over the bitmap.
100  *
101  * For prefetching, we use *two* iterators, one for the pages we are
102  * actually scanning and another that runs ahead of the first for
103  * prefetching. node->prefetch_pages tracks exactly how many pages ahead
104  * the prefetch iterator is. Also, node->prefetch_target tracks the
105  * desired prefetch distance, which starts small and increases up to the
106  * node->prefetch_maximum. This is to avoid doing a lot of prefetching in
107  * a scan that stops after a few tuples because of a LIMIT.
108  */
109  if (!node->initialized)
110  {
111  if (!pstate)
112  {
113  tbm = (TIDBitmap *) MultiExecProcNode(outerPlanState(node));
114 
115  if (!tbm || !IsA(tbm, TIDBitmap))
116  elog(ERROR, "unrecognized result from subplan");
117 
118  node->tbm = tbm;
119  node->tbmiterator = tbmiterator = tbm_begin_iterate(tbm);
120  node->tbmres = tbmres = NULL;
121 
122 #ifdef USE_PREFETCH
123  if (node->prefetch_maximum > 0)
124  {
126  node->prefetch_pages = 0;
127  node->prefetch_target = -1;
128  }
129 #endif /* USE_PREFETCH */
130  }
131  else
132  {
133  /*
134  * The leader will immediately come out of the function, but
135  * others will be blocked until leader populates the TBM and wakes
136  * them up.
137  */
139  {
140  tbm = (TIDBitmap *) MultiExecProcNode(outerPlanState(node));
141  if (!tbm || !IsA(tbm, TIDBitmap))
142  elog(ERROR, "unrecognized result from subplan");
143 
144  node->tbm = tbm;
145 
146  /*
147  * Prepare to iterate over the TBM. This will return the
148  * dsa_pointer of the iterator state which will be used by
149  * multiple processes to iterate jointly.
150  */
152 #ifdef USE_PREFETCH
153  if (node->prefetch_maximum > 0)
154  {
155  pstate->prefetch_iterator =
157 
158  /*
159  * We don't need the mutex here as we haven't yet woke up
160  * others.
161  */
162  pstate->prefetch_pages = 0;
163  pstate->prefetch_target = -1;
164  }
165 #endif
166 
167  /* We have initialized the shared state so wake up others. */
169  }
170 
171  /* Allocate a private iterator and attach the shared state to it */
172  node->shared_tbmiterator = shared_tbmiterator =
174  node->tbmres = tbmres = NULL;
175 
176 #ifdef USE_PREFETCH
177  if (node->prefetch_maximum > 0)
178  {
181  }
182 #endif /* USE_PREFETCH */
183  }
184  node->initialized = true;
185  }
186 
187  for (;;)
188  {
189  bool skip_fetch;
190 
192 
193  /*
194  * Get next page of results if needed
195  */
196  if (tbmres == NULL)
197  {
198  if (!pstate)
199  node->tbmres = tbmres = tbm_iterate(tbmiterator);
200  else
201  node->tbmres = tbmres = tbm_shared_iterate(shared_tbmiterator);
202  if (tbmres == NULL)
203  {
204  /* no more entries in the bitmap */
205  break;
206  }
207 
208  BitmapAdjustPrefetchIterator(node, tbmres);
209 
210  /*
211  * We can skip fetching the heap page if we don't need any fields
212  * from the heap, and the bitmap entries don't need rechecking,
213  * and all tuples on the page are visible to our transaction.
214  *
215  * XXX: It's a layering violation that we do these checks above
216  * tableam, they should probably moved below it at some point.
217  */
218  skip_fetch = (node->can_skip_fetch &&
219  !tbmres->recheck &&
221  tbmres->blockno,
222  &node->vmbuffer));
223 
224  if (skip_fetch)
225  {
226  /* can't be lossy in the skip_fetch case */
227  Assert(tbmres->ntuples >= 0);
228 
229  /*
230  * The number of tuples on this page is put into
231  * node->return_empty_tuples.
232  */
233  node->return_empty_tuples = tbmres->ntuples;
234  }
235  else if (!table_scan_bitmap_next_block(scan, tbmres))
236  {
237  /* AM doesn't think this block is valid, skip */
238  continue;
239  }
240 
241  if (tbmres->ntuples >= 0)
242  node->exact_pages++;
243  else
244  node->lossy_pages++;
245 
246  /* Adjust the prefetch target */
248  }
249  else
250  {
251  /*
252  * Continuing in previously obtained page.
253  */
254 
255 #ifdef USE_PREFETCH
256 
257  /*
258  * Try to prefetch at least a few pages even before we get to the
259  * second page if we don't stop reading after the first tuple.
260  */
261  if (!pstate)
262  {
263  if (node->prefetch_target < node->prefetch_maximum)
264  node->prefetch_target++;
265  }
266  else if (pstate->prefetch_target < node->prefetch_maximum)
267  {
268  /* take spinlock while updating shared state */
269  SpinLockAcquire(&pstate->mutex);
270  if (pstate->prefetch_target < node->prefetch_maximum)
271  pstate->prefetch_target++;
272  SpinLockRelease(&pstate->mutex);
273  }
274 #endif /* USE_PREFETCH */
275  }
276 
277  /*
278  * We issue prefetch requests *after* fetching the current page to try
279  * to avoid having prefetching interfere with the main I/O. Also, this
280  * should happen only when we have determined there is still something
281  * to do on the current page, else we may uselessly prefetch the same
282  * page we are just about to request for real.
283  *
284  * XXX: It's a layering violation that we do these checks above
285  * tableam, they should probably moved below it at some point.
286  */
287  BitmapPrefetch(node, scan);
288 
289  if (node->return_empty_tuples > 0)
290  {
291  /*
292  * If we don't have to fetch the tuple, just return nulls.
293  */
294  ExecStoreAllNullTuple(slot);
295 
296  if (--node->return_empty_tuples == 0)
297  {
298  /* no more tuples to return in the next round */
299  node->tbmres = tbmres = NULL;
300  }
301  }
302  else
303  {
304  /*
305  * Attempt to fetch tuple from AM.
306  */
307  if (!table_scan_bitmap_next_tuple(scan, tbmres, slot))
308  {
309  /* nothing more to look at on this page */
310  node->tbmres = tbmres = NULL;
311  continue;
312  }
313 
314  /*
315  * If we are using lossy info, we have to recheck the qual
316  * conditions at every tuple.
317  */
318  if (tbmres->recheck)
319  {
320  econtext->ecxt_scantuple = slot;
321  if (!ExecQualAndReset(node->bitmapqualorig, econtext))
322  {
323  /* Fails recheck, so drop it and loop back for another */
324  InstrCountFiltered2(node, 1);
325  ExecClearTuple(slot);
326  continue;
327  }
328  }
329  }
330 
331  /* OK to return this tuple */
332  return slot;
333  }
334 
335  /*
336  * if we get here it means we are at the end of the scan..
337  */
338  return ExecClearTuple(slot);
339 }
static bool table_scan_bitmap_next_tuple(TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
Definition: tableam.h:1657
struct dsa_area * es_query_dsa
Definition: execnodes.h:583
static void BitmapPrefetch(BitmapHeapScanState *node, TableScanDesc scan)
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
ExprState * bitmapqualorig
Definition: execnodes.h:1580
static void BitmapAdjustPrefetchTarget(BitmapHeapScanState *node)
dsa_pointer tbm_prepare_shared_iterate(TIDBitmap *tbm)
Definition: tidbitmap.c:765
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
Definition: execTuples.c:1546
ExprContext * ps_ExprContext
Definition: execnodes.h:978
TIDBitmap * tbm
Definition: execnodes.h:1581
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1328
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1329
Relation ss_currentRelation
Definition: execnodes.h:1327
EState * state
Definition: execnodes.h:941
BlockNumber blockno
Definition: tidbitmap.h:42
PlanState ps
Definition: execnodes.h:1326
#define SpinLockAcquire(lock)
Definition: spin.h:62
#define ERROR
Definition: elog.h:43
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1598
#define outerPlanState(node)
Definition: execnodes.h:1033
static bool BitmapShouldInitializeSharedState(ParallelBitmapHeapState *pstate)
dsa_pointer tbmiterator
Definition: execnodes.h:1543
TBMIterateResult * tbmres
Definition: execnodes.h:1583
#define SpinLockRelease(lock)
Definition: spin.h:64
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition: executor.h:392
dsa_pointer prefetch_iterator
Definition: execnodes.h:1544
static void BitmapAdjustPrefetchIterator(BitmapHeapScanState *node, TBMIterateResult *tbmres)
TBMIterateResult * tbm_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:970
#define Assert(condition)
Definition: c.h:739
#define InstrCountFiltered2(node, delta)
Definition: execnodes.h:1046
#define VM_ALL_VISIBLE(r, b, v)
Definition: visibilitymap.h:32
TBMIterator * tbm_begin_iterate(TIDBitmap *tbm)
Definition: tidbitmap.c:688
TBMIterateResult * tbm_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1051
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:223
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1596
TBMIterator * tbmiterator
Definition: execnodes.h:1582
static void BitmapDoneInitializingSharedState(ParallelBitmapHeapState *pstate)
Definition: dsa.c:354
Node * MultiExecProcNode(PlanState *node)
Definition: execProcnode.c:482
TBMIterator * prefetch_iterator
Definition: execnodes.h:1590
static bool table_scan_bitmap_next_block(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:1641
#define elog(elevel,...)
Definition: elog.h:228
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
TBMSharedIterator * tbm_attach_shared_iterate(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:1464
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1597

◆ BitmapHeapRecheck()

static bool BitmapHeapRecheck ( BitmapHeapScanState node,
TupleTableSlot slot 
)
static

Definition at line 569 of file nodeBitmapHeapscan.c.

References BitmapHeapScanState::bitmapqualorig, ExprContext::ecxt_scantuple, ExecQualAndReset(), ScanState::ps, PlanState::ps_ExprContext, and BitmapHeapScanState::ss.

Referenced by ExecBitmapHeapScan().

570 {
571  ExprContext *econtext;
572 
573  /*
574  * extract necessary information from index scan node
575  */
576  econtext = node->ss.ps.ps_ExprContext;
577 
578  /* Does the tuple meet the original qual conditions? */
579  econtext->ecxt_scantuple = slot;
580  return ExecQualAndReset(node->bitmapqualorig, econtext);
581 }
ExprState * bitmapqualorig
Definition: execnodes.h:1580
ExprContext * ps_ExprContext
Definition: execnodes.h:978
PlanState ps
Definition: execnodes.h:1326
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition: executor.h:392
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:223

◆ BitmapPrefetch()

static void BitmapPrefetch ( BitmapHeapScanState node,
TableScanDesc  scan 
)
inlinestatic

Definition at line 464 of file nodeBitmapHeapscan.c.

References TBMIterateResult::blockno, BitmapHeapScanState::can_skip_fetch, MAIN_FORKNUM, ParallelBitmapHeapState::mutex, BitmapHeapScanState::prefetch_iterator, ParallelBitmapHeapState::prefetch_pages, BitmapHeapScanState::prefetch_pages, ParallelBitmapHeapState::prefetch_target, BitmapHeapScanState::prefetch_target, PrefetchBuffer(), BitmapHeapScanState::pstate, BitmapHeapScanState::pvmbuffer, TBMIterateResult::recheck, TableScanDescData::rs_rd, BitmapHeapScanState::shared_prefetch_iterator, SpinLockAcquire, SpinLockRelease, BitmapHeapScanState::ss, ScanState::ss_currentRelation, tbm_end_iterate(), tbm_end_shared_iterate(), tbm_iterate(), tbm_shared_iterate(), BitmapHeapScanState::tbmres, and VM_ALL_VISIBLE.

Referenced by BitmapHeapNext().

465 {
466 #ifdef USE_PREFETCH
467  ParallelBitmapHeapState *pstate = node->pstate;
468 
469  if (pstate == NULL)
470  {
471  TBMIterator *prefetch_iterator = node->prefetch_iterator;
472 
473  if (prefetch_iterator)
474  {
475  while (node->prefetch_pages < node->prefetch_target)
476  {
477  TBMIterateResult *tbmpre = tbm_iterate(prefetch_iterator);
478  bool skip_fetch;
479 
480  if (tbmpre == NULL)
481  {
482  /* No more pages to prefetch */
483  tbm_end_iterate(prefetch_iterator);
484  node->prefetch_iterator = NULL;
485  break;
486  }
487  node->prefetch_pages++;
488 
489  /*
490  * If we expect not to have to actually read this heap page,
491  * skip this prefetch call, but continue to run the prefetch
492  * logic normally. (Would it be better not to increment
493  * prefetch_pages?)
494  *
495  * This depends on the assumption that the index AM will
496  * report the same recheck flag for this future heap page as
497  * it did for the current heap page; which is not a certainty
498  * but is true in many cases.
499  */
500  skip_fetch = (node->can_skip_fetch &&
501  (node->tbmres ? !node->tbmres->recheck : false) &&
503  tbmpre->blockno,
504  &node->pvmbuffer));
505 
506  if (!skip_fetch)
507  PrefetchBuffer(scan->rs_rd, MAIN_FORKNUM, tbmpre->blockno);
508  }
509  }
510 
511  return;
512  }
513 
514  if (pstate->prefetch_pages < pstate->prefetch_target)
515  {
516  TBMSharedIterator *prefetch_iterator = node->shared_prefetch_iterator;
517 
518  if (prefetch_iterator)
519  {
520  while (1)
521  {
522  TBMIterateResult *tbmpre;
523  bool do_prefetch = false;
524  bool skip_fetch;
525 
526  /*
527  * Recheck under the mutex. If some other process has already
528  * done enough prefetching then we need not to do anything.
529  */
530  SpinLockAcquire(&pstate->mutex);
531  if (pstate->prefetch_pages < pstate->prefetch_target)
532  {
533  pstate->prefetch_pages++;
534  do_prefetch = true;
535  }
536  SpinLockRelease(&pstate->mutex);
537 
538  if (!do_prefetch)
539  return;
540 
541  tbmpre = tbm_shared_iterate(prefetch_iterator);
542  if (tbmpre == NULL)
543  {
544  /* No more pages to prefetch */
545  tbm_end_shared_iterate(prefetch_iterator);
546  node->shared_prefetch_iterator = NULL;
547  break;
548  }
549 
550  /* As above, skip prefetch if we expect not to need page */
551  skip_fetch = (node->can_skip_fetch &&
552  (node->tbmres ? !node->tbmres->recheck : false) &&
554  tbmpre->blockno,
555  &node->pvmbuffer));
556 
557  if (!skip_fetch)
558  PrefetchBuffer(scan->rs_rd, MAIN_FORKNUM, tbmpre->blockno);
559  }
560  }
561  }
562 #endif /* USE_PREFETCH */
563 }
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1145
Relation ss_currentRelation
Definition: execnodes.h:1327
BlockNumber blockno
Definition: tidbitmap.h:42
#define SpinLockAcquire(lock)
Definition: spin.h:62
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1598
TBMIterateResult * tbmres
Definition: execnodes.h:1583
#define SpinLockRelease(lock)
Definition: spin.h:64
void PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
Definition: bufmgr.c:531
TBMIterateResult * tbm_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:970
#define VM_ALL_VISIBLE(r, b, v)
Definition: visibilitymap.h:32
TBMIterateResult * tbm_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1051
Relation rs_rd
Definition: relscan.h:34
TBMIterator * prefetch_iterator
Definition: execnodes.h:1590
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1597
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1157

◆ BitmapShouldInitializeSharedState()

static bool BitmapShouldInitializeSharedState ( ParallelBitmapHeapState pstate)
static

Definition at line 835 of file nodeBitmapHeapscan.c.

References BM_INITIAL, BM_INPROGRESS, ConditionVariableCancelSleep(), ConditionVariableSleep(), ParallelBitmapHeapState::cv, ParallelBitmapHeapState::mutex, SpinLockAcquire, SpinLockRelease, ParallelBitmapHeapState::state, and WAIT_EVENT_PARALLEL_BITMAP_SCAN.

Referenced by BitmapHeapNext().

836 {
838 
839  while (1)
840  {
841  SpinLockAcquire(&pstate->mutex);
842  state = pstate->state;
843  if (pstate->state == BM_INITIAL)
844  pstate->state = BM_INPROGRESS;
845  SpinLockRelease(&pstate->mutex);
846 
847  /* Exit if bitmap is done, or if we're the leader. */
848  if (state != BM_INPROGRESS)
849  break;
850 
851  /* Wait for the leader to wake us up. */
853  }
854 
856 
857  return (state == BM_INITIAL);
858 }
SharedBitmapState
Definition: execnodes.h:1521
#define SpinLockAcquire(lock)
Definition: spin.h:62
void ConditionVariableCancelSleep(void)
#define SpinLockRelease(lock)
Definition: spin.h:64
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
Definition: regguts.h:298
SharedBitmapState state
Definition: execnodes.h:1548
ConditionVariable cv
Definition: execnodes.h:1549

◆ ExecBitmapHeapEstimate()

void ExecBitmapHeapEstimate ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 868 of file nodeBitmapHeapscan.c.

References add_size(), EState::es_snapshot, EstimateSnapshotSpace(), ParallelContext::estimator, offsetof, ScanState::ps, BitmapHeapScanState::pscan_len, shm_toc_estimate_chunk, shm_toc_estimate_keys, BitmapHeapScanState::ss, and PlanState::state.

Referenced by ExecParallelEstimate().

870 {
871  EState *estate = node->ss.ps.state;
872 
874  phs_snapshot_data),
876 
878  shm_toc_estimate_keys(&pcxt->estimator, 1);
879 }
shm_toc_estimator estimator
Definition: parallel.h:41
Snapshot es_snapshot
Definition: execnodes.h:502
EState * state
Definition: execnodes.h:941
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
PlanState ps
Definition: execnodes.h:1326
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2078
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
#define offsetof(type, field)
Definition: c.h:662

◆ ExecBitmapHeapInitializeDSM()

void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 888 of file nodeBitmapHeapscan.c.

References BM_INITIAL, ConditionVariableInit(), ParallelBitmapHeapState::cv, EState::es_query_dsa, EState::es_snapshot, ParallelBitmapHeapState::mutex, ParallelBitmapHeapState::phs_snapshot_data, PlanState::plan, Plan::plan_node_id, ParallelBitmapHeapState::prefetch_iterator, ParallelBitmapHeapState::prefetch_pages, ParallelBitmapHeapState::prefetch_target, ScanState::ps, BitmapHeapScanState::pscan_len, BitmapHeapScanState::pstate, SerializeSnapshot(), shm_toc_allocate(), shm_toc_insert(), SpinLockInit, BitmapHeapScanState::ss, PlanState::state, ParallelBitmapHeapState::state, ParallelBitmapHeapState::tbmiterator, and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

890 {
891  ParallelBitmapHeapState *pstate;
892  EState *estate = node->ss.ps.state;
893  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
894 
895  /* If there's no DSA, there are no workers; initialize nothing. */
896  if (dsa == NULL)
897  return;
898 
899  pstate = shm_toc_allocate(pcxt->toc, node->pscan_len);
900 
901  pstate->tbmiterator = 0;
902  pstate->prefetch_iterator = 0;
903 
904  /* Initialize the mutex */
905  SpinLockInit(&pstate->mutex);
906  pstate->prefetch_pages = 0;
907  pstate->prefetch_target = 0;
908  pstate->state = BM_INITIAL;
909 
910  ConditionVariableInit(&pstate->cv);
912 
913  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
914  node->pstate = pstate;
915 }
struct dsa_area * es_query_dsa
Definition: execnodes.h:583
#define SpinLockInit(lock)
Definition: spin.h:60
int plan_node_id
Definition: plannodes.h:141
Snapshot es_snapshot
Definition: execnodes.h:502
EState * state
Definition: execnodes.h:941
PlanState ps
Definition: execnodes.h:1326
void ConditionVariableInit(ConditionVariable *cv)
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1598
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2102
dsa_pointer tbmiterator
Definition: execnodes.h:1543
Plan * plan
Definition: execnodes.h:939
dsa_pointer prefetch_iterator
Definition: execnodes.h:1544
SharedBitmapState state
Definition: execnodes.h:1548
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1550
Definition: dsa.c:354
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
ConditionVariable cv
Definition: execnodes.h:1549
shm_toc * toc
Definition: parallel.h:44

◆ ExecBitmapHeapInitializeWorker()

void ExecBitmapHeapInitializeWorker ( BitmapHeapScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 953 of file nodeBitmapHeapscan.c.

References Assert, EState::es_query_dsa, ParallelBitmapHeapState::phs_snapshot_data, PlanState::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, RestoreSnapshot(), shm_toc_lookup(), BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, PlanState::state, table_scan_update_snapshot(), and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

955 {
956  ParallelBitmapHeapState *pstate;
957  Snapshot snapshot;
958 
959  Assert(node->ss.ps.state->es_query_dsa != NULL);
960 
961  pstate = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
962  node->pstate = pstate;
963 
964  snapshot = RestoreSnapshot(pstate->phs_snapshot_data);
966 }
void table_scan_update_snapshot(TableScanDesc scan, Snapshot snapshot)
Definition: tableam.c:110
struct dsa_area * es_query_dsa
Definition: execnodes.h:583
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2161
int plan_node_id
Definition: plannodes.h:141
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1328
EState * state
Definition: execnodes.h:941
PlanState ps
Definition: execnodes.h:1326
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1598
Plan * plan
Definition: execnodes.h:939
#define Assert(condition)
Definition: c.h:739
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1550
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

◆ ExecBitmapHeapReInitializeDSM()

void ExecBitmapHeapReInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 924 of file nodeBitmapHeapscan.c.

References BM_INITIAL, DsaPointerIsValid, EState::es_query_dsa, InvalidDsaPointer, ParallelBitmapHeapState::prefetch_iterator, ScanState::ps, BitmapHeapScanState::pstate, BitmapHeapScanState::ss, PlanState::state, ParallelBitmapHeapState::state, tbm_free_shared_area(), and ParallelBitmapHeapState::tbmiterator.

Referenced by ExecParallelReInitializeDSM().

926 {
927  ParallelBitmapHeapState *pstate = node->pstate;
928  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
929 
930  /* If there's no DSA, there are no workers; do nothing. */
931  if (dsa == NULL)
932  return;
933 
934  pstate->state = BM_INITIAL;
935 
936  if (DsaPointerIsValid(pstate->tbmiterator))
937  tbm_free_shared_area(dsa, pstate->tbmiterator);
938 
941 
942  pstate->tbmiterator = InvalidDsaPointer;
944 }
struct dsa_area * es_query_dsa
Definition: execnodes.h:583
#define InvalidDsaPointer
Definition: dsa.h:78
EState * state
Definition: execnodes.h:941
PlanState ps
Definition: execnodes.h:1326
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1598
dsa_pointer tbmiterator
Definition: execnodes.h:1543
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:340
dsa_pointer prefetch_iterator
Definition: execnodes.h:1544
SharedBitmapState state
Definition: execnodes.h:1548
#define DsaPointerIsValid(x)
Definition: dsa.h:81
Definition: dsa.c:354

◆ ExecBitmapHeapScan()

static TupleTableSlot* ExecBitmapHeapScan ( PlanState pstate)
static

Definition at line 588 of file nodeBitmapHeapscan.c.

References BitmapHeapNext(), BitmapHeapRecheck(), castNode, ExecScan(), and BitmapHeapScanState::ss.

Referenced by ExecInitBitmapHeapScan().

589 {
591 
592  return ExecScan(&node->ss,
595 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:158
static TupleTableSlot * BitmapHeapNext(BitmapHeapScanState *node)
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:426
static bool BitmapHeapRecheck(BitmapHeapScanState *node, TupleTableSlot *slot)
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:425

◆ ExecEndBitmapHeapScan()

void ExecEndBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 649 of file nodeBitmapHeapscan.c.

References ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), InvalidBuffer, outerPlanState, BitmapHeapScanState::prefetch_iterator, ScanState::ps, PlanState::ps_ResultTupleSlot, BitmapHeapScanState::pvmbuffer, ReleaseBuffer(), BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, ScanState::ss_ScanTupleSlot, table_endscan(), BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_end_shared_iterate(), tbm_free(), BitmapHeapScanState::tbmiterator, and BitmapHeapScanState::vmbuffer.

Referenced by ExecEndNode().

650 {
651  TableScanDesc scanDesc;
652 
653  /*
654  * extract information from the node
655  */
656  scanDesc = node->ss.ss_currentScanDesc;
657 
658  /*
659  * Free the exprcontext
660  */
661  ExecFreeExprContext(&node->ss.ps);
662 
663  /*
664  * clear out tuple table slots
665  */
666  if (node->ss.ps.ps_ResultTupleSlot)
669 
670  /*
671  * close down subplans
672  */
674 
675  /*
676  * release bitmaps and buffers if any
677  */
678  if (node->tbmiterator)
680  if (node->prefetch_iterator)
682  if (node->tbm)
683  tbm_free(node->tbm);
684  if (node->shared_tbmiterator)
686  if (node->shared_prefetch_iterator)
688  if (node->vmbuffer != InvalidBuffer)
689  ReleaseBuffer(node->vmbuffer);
690  if (node->pvmbuffer != InvalidBuffer)
691  ReleaseBuffer(node->pvmbuffer);
692 
693  /*
694  * close heap scan
695  */
696  table_endscan(scanDesc);
697 }
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1145
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:537
TIDBitmap * tbm
Definition: execnodes.h:1581
#define InvalidBuffer
Definition: buf.h:25
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1328
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1329
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3365
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:614
PlanState ps
Definition: execnodes.h:1326
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:977
#define outerPlanState(node)
Definition: execnodes.h:1033
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:321
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1596
TBMIterator * tbmiterator
Definition: execnodes.h:1582
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:831
TBMIterator * prefetch_iterator
Definition: execnodes.h:1590
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1597
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1157

◆ ExecInitBitmapHeapScan()

BitmapHeapScanState* ExecInitBitmapHeapScan ( BitmapHeapScan node,
EState estate,
int  eflags 
)

Definition at line 706 of file nodeBitmapHeapscan.c.

References Assert, BitmapHeapScan::bitmapqualorig, BitmapHeapScanState::can_skip_fetch, ComputeIoConcurrency(), effective_io_concurrency, EState::es_snapshot, BitmapHeapScanState::exact_pages, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecBitmapHeapScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, get_tablespace_io_concurrency(), BitmapHeapScanState::initialized, InvalidBuffer, IsMVCCSnapshot, BitmapHeapScanState::lossy_pages, makeNode, NIL, outerPlan, outerPlanState, Scan::plan, PlanState::plan, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::prefetch_maximum, BitmapHeapScanState::prefetch_pages, BitmapHeapScanState::prefetch_target, ScanState::ps, BitmapHeapScanState::pscan_len, BitmapHeapScanState::pstate, BitmapHeapScanState::pvmbuffer, Plan::qual, PlanState::qual, RelationData::rd_rel, RelationGetDescr, BitmapHeapScanState::return_empty_tuples, rint(), BitmapHeapScan::scan, Scan::scanrelid, BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, PlanState::state, table_beginscan_bm(), table_slot_callbacks(), target_prefetch_pages, Plan::targetlist, BitmapHeapScanState::tbm, BitmapHeapScanState::tbmiterator, BitmapHeapScanState::tbmres, and BitmapHeapScanState::vmbuffer.

Referenced by ExecInitNode().

707 {
708  BitmapHeapScanState *scanstate;
709  Relation currentRelation;
710  int io_concurrency;
711 
712  /* check for unsupported flags */
713  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
714 
715  /*
716  * Assert caller didn't ask for an unsafe snapshot --- see comments at
717  * head of file.
718  */
720 
721  /*
722  * create state structure
723  */
724  scanstate = makeNode(BitmapHeapScanState);
725  scanstate->ss.ps.plan = (Plan *) node;
726  scanstate->ss.ps.state = estate;
727  scanstate->ss.ps.ExecProcNode = ExecBitmapHeapScan;
728 
729  scanstate->tbm = NULL;
730  scanstate->tbmiterator = NULL;
731  scanstate->tbmres = NULL;
732  scanstate->return_empty_tuples = 0;
733  scanstate->vmbuffer = InvalidBuffer;
734  scanstate->pvmbuffer = InvalidBuffer;
735  scanstate->exact_pages = 0;
736  scanstate->lossy_pages = 0;
737  scanstate->prefetch_iterator = NULL;
738  scanstate->prefetch_pages = 0;
739  scanstate->prefetch_target = 0;
740  /* may be updated below */
742  scanstate->pscan_len = 0;
743  scanstate->initialized = false;
744  scanstate->shared_tbmiterator = NULL;
745  scanstate->shared_prefetch_iterator = NULL;
746  scanstate->pstate = NULL;
747 
748  /*
749  * We can potentially skip fetching heap pages if we do not need any
750  * columns of the table, either for checking non-indexable quals or for
751  * returning data. This test is a bit simplistic, as it checks the
752  * stronger condition that there's no qual or return tlist at all. But in
753  * most cases it's probably not worth working harder than that.
754  */
755  scanstate->can_skip_fetch = (node->scan.plan.qual == NIL &&
756  node->scan.plan.targetlist == NIL);
757 
758  /*
759  * Miscellaneous initialization
760  *
761  * create expression context for node
762  */
763  ExecAssignExprContext(estate, &scanstate->ss.ps);
764 
765  /*
766  * open the scan relation
767  */
768  currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
769 
770  /*
771  * initialize child nodes
772  */
773  outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
774 
775  /*
776  * get the scan type from the relation descriptor.
777  */
778  ExecInitScanTupleSlot(estate, &scanstate->ss,
779  RelationGetDescr(currentRelation),
780  table_slot_callbacks(currentRelation));
781 
782  /*
783  * Initialize result type and projection.
784  */
785  ExecInitResultTypeTL(&scanstate->ss.ps);
786  ExecAssignScanProjectionInfo(&scanstate->ss);
787 
788  /*
789  * initialize child expressions
790  */
791  scanstate->ss.ps.qual =
792  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
793  scanstate->bitmapqualorig =
794  ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
795 
796  /*
797  * Determine the maximum for prefetch_target. If the tablespace has a
798  * specific IO concurrency set, use that to compute the corresponding
799  * maximum value; otherwise, we already initialized to the value computed
800  * by the GUC machinery.
801  */
802  io_concurrency =
803  get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
804  if (io_concurrency != effective_io_concurrency)
805  {
806  double maximum;
807 
808  if (ComputeIoConcurrency(io_concurrency, &maximum))
809  scanstate->prefetch_maximum = rint(maximum);
810  }
811 
812  scanstate->ss.ss_currentRelation = currentRelation;
813 
814  scanstate->ss.ss_currentScanDesc = table_beginscan_bm(currentRelation,
815  estate->es_snapshot,
816  0,
817  NULL);
818 
819  /*
820  * all done.
821  */
822  return scanstate;
823 }
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:143
int target_prefetch_pages
Definition: bufmgr.c:130
Plan plan
Definition: plannodes.h:344
ExprState * bitmapqualorig
Definition: execnodes.h:1580
Index scanrelid
Definition: plannodes.h:345
#define RelationGetDescr(relation)
Definition: rel.h:448
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:44
TIDBitmap * tbm
Definition: execnodes.h:1581
#define InvalidBuffer
Definition: buf.h:25
int get_tablespace_io_concurrency(Oid spcid)
Definition: spccache.c:215
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1328
Snapshot es_snapshot
Definition: execnodes.h:502
Relation ss_currentRelation
Definition: execnodes.h:1327
EState * state
Definition: execnodes.h:941
Form_pg_class rd_rel
Definition: rel.h:83
int effective_io_concurrency
Definition: bufmgr.c:113
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:207
bool ComputeIoConcurrency(int io_concurrency, double *target)
Definition: bufmgr.c:469
PlanState ps
Definition: execnodes.h:1326
static TupleTableSlot * ExecBitmapHeapScan(PlanState *pstate)
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:272
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1598
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:693
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1033
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1781
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1725
double rint(double x)
Definition: rint.c:21
List * bitmapqualorig
Definition: plannodes.h:479
TBMIterateResult * tbmres
Definition: execnodes.h:1583
#define outerPlan(node)
Definition: plannodes.h:172
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:945
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:97
Plan * plan
Definition: execnodes.h:939
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
#define EXEC_FLAG_MARK
Definition: executor.h:59
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:444
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1596
TBMIterator * tbmiterator
Definition: execnodes.h:1582
List * targetlist
Definition: plannodes.h:142
ExprState * qual
Definition: execnodes.h:960
TBMIterator * prefetch_iterator
Definition: execnodes.h:1590
static TableScanDesc table_beginscan_bm(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:781
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:138
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1597

◆ ExecReScanBitmapHeapScan()

void ExecReScanBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 602 of file nodeBitmapHeapscan.c.

References PlanState::chgParam, ExecReScan(), ExecScanReScan(), BitmapHeapScanState::initialized, InvalidBuffer, outerPlan, outerPlanState, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::pvmbuffer, ReleaseBuffer(), BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, table_rescan(), BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_end_shared_iterate(), tbm_free(), BitmapHeapScanState::tbmiterator, BitmapHeapScanState::tbmres, and BitmapHeapScanState::vmbuffer.

Referenced by ExecReScan().

603 {
605 
606  /* rescan to release any page pin */
607  table_rescan(node->ss.ss_currentScanDesc, NULL);
608 
609  /* release bitmaps and buffers if any */
610  if (node->tbmiterator)
612  if (node->prefetch_iterator)
614  if (node->shared_tbmiterator)
616  if (node->shared_prefetch_iterator)
618  if (node->tbm)
619  tbm_free(node->tbm);
620  if (node->vmbuffer != InvalidBuffer)
621  ReleaseBuffer(node->vmbuffer);
622  if (node->pvmbuffer != InvalidBuffer)
623  ReleaseBuffer(node->pvmbuffer);
624  node->tbm = NULL;
625  node->tbmiterator = NULL;
626  node->tbmres = NULL;
627  node->prefetch_iterator = NULL;
628  node->initialized = false;
629  node->shared_tbmiterator = NULL;
630  node->shared_prefetch_iterator = NULL;
631  node->vmbuffer = InvalidBuffer;
632  node->pvmbuffer = InvalidBuffer;
633 
634  ExecScanReScan(&node->ss);
635 
636  /*
637  * if chgParam of subnode is not null then plan will be re-scanned by
638  * first ExecProcNode.
639  */
640  if (outerPlan->chgParam == NULL)
641  ExecReScan(outerPlan);
642 }
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1145
TIDBitmap * tbm
Definition: execnodes.h:1581
void ExecReScan(PlanState *node)
Definition: execAmi.c:75
#define InvalidBuffer
Definition: buf.h:25
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1328
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3365
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:840
#define outerPlanState(node)
Definition: execnodes.h:1033
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:321
TBMIterateResult * tbmres
Definition: execnodes.h:1583
Bitmapset * chgParam
Definition: execnodes.h:971
#define outerPlan(node)
Definition: plannodes.h:172
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1596
TBMIterator * tbmiterator
Definition: execnodes.h:1582
TBMIterator * prefetch_iterator
Definition: execnodes.h:1590
void ExecScanReScan(ScanState *node)
Definition: execScan.c:299
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1597
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1157