~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/backend/executor/nodeBitmapHeapscan.c

Tags: upstream-8.4.0
ImportĀ upstreamĀ versionĀ 8.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 *
22
22
 *
23
23
 * IDENTIFICATION
24
 
 *        $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.34 2009/01/12 16:00:41 tgl Exp $
 
24
 *        $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.35 2009/06/11 14:48:57 momjian Exp $
25
25
 *
26
26
 *-------------------------------------------------------------------------
27
27
 */
114
114
        }
115
115
 
116
116
        /*
117
 
         * If we haven't yet performed the underlying index scan, do it, and
118
 
         * begin the iteration over the bitmap.
 
117
         * If we haven't yet performed the underlying index scan, do it, and begin
 
118
         * the iteration over the bitmap.
119
119
         *
120
120
         * For prefetching, we use *two* iterators, one for the pages we are
121
121
         * actually scanning and another that runs ahead of the first for
122
 
         * prefetching.  node->prefetch_pages tracks exactly how many pages
123
 
         * ahead the prefetch iterator is.  Also, node->prefetch_target tracks
124
 
         * the desired prefetch distance, which starts small and increases up
125
 
         * to the GUC-controlled maximum, target_prefetch_pages.  This is to
126
 
         * avoid doing a lot of prefetching in a scan that stops after a few
127
 
         * tuples because of a LIMIT.
 
122
         * prefetching.  node->prefetch_pages tracks exactly how many pages ahead
 
123
         * the prefetch iterator is.  Also, node->prefetch_target tracks the
 
124
         * desired prefetch distance, which starts small and increases up to the
 
125
         * GUC-controlled maximum, target_prefetch_pages.  This is to avoid doing
 
126
         * a lot of prefetching in a scan that stops after a few tuples because of
 
127
         * a LIMIT.
128
128
         */
129
129
        if (tbm == NULL)
130
130
        {
144
144
                        node->prefetch_pages = 0;
145
145
                        node->prefetch_target = -1;
146
146
                }
147
 
#endif /* USE_PREFETCH */
 
147
#endif   /* USE_PREFETCH */
148
148
        }
149
149
 
150
150
        for (;;)
178
178
                                if (tbmpre == NULL || tbmpre->blockno != tbmres->blockno)
179
179
                                        elog(ERROR, "prefetch and main iterators are out of sync");
180
180
                        }
181
 
#endif /* USE_PREFETCH */
 
181
#endif   /* USE_PREFETCH */
182
182
 
183
183
                        /*
184
184
                         * Ignore any claimed entries past what we think is the end of the
203
203
                        scan->rs_cindex = 0;
204
204
 
205
205
#ifdef USE_PREFETCH
 
206
 
206
207
                        /*
207
 
                         * Increase prefetch target if it's not yet at the max.  Note
208
 
                         * that we will increase it to zero after fetching the very
209
 
                         * first page/tuple, then to one after the second tuple is
210
 
                         * fetched, then it doubles as later pages are fetched.
 
208
                         * Increase prefetch target if it's not yet at the max.  Note that
 
209
                         * we will increase it to zero after fetching the very first
 
210
                         * page/tuple, then to one after the second tuple is fetched, then
 
211
                         * it doubles as later pages are fetched.
211
212
                         */
212
213
                        if (node->prefetch_target >= target_prefetch_pages)
213
 
                                /* don't increase any further */ ;
 
214
                                 /* don't increase any further */ ;
214
215
                        else if (node->prefetch_target >= target_prefetch_pages / 2)
215
216
                                node->prefetch_target = target_prefetch_pages;
216
217
                        else if (node->prefetch_target > 0)
217
218
                                node->prefetch_target *= 2;
218
219
                        else
219
220
                                node->prefetch_target++;
220
 
#endif /* USE_PREFETCH */
 
221
#endif   /* USE_PREFETCH */
221
222
                }
222
223
                else
223
224
                {
227
228
                        scan->rs_cindex++;
228
229
 
229
230
#ifdef USE_PREFETCH
 
231
 
230
232
                        /*
231
233
                         * Try to prefetch at least a few pages even before we get to the
232
234
                         * second page if we don't stop reading after the first tuple.
233
235
                         */
234
236
                        if (node->prefetch_target < target_prefetch_pages)
235
237
                                node->prefetch_target++;
236
 
#endif /* USE_PREFETCH */
 
238
#endif   /* USE_PREFETCH */
237
239
                }
238
240
 
239
241
                /*
246
248
                }
247
249
 
248
250
#ifdef USE_PREFETCH
 
251
 
249
252
                /*
250
 
                 * We issue prefetch requests *after* fetching the current page
251
 
                 * to try to avoid having prefetching interfere with the main I/O.
252
 
                 * Also, this should happen only when we have determined there is
253
 
                 * still something to do on the current page, else we may uselessly
254
 
                 * prefetch the same page we are just about to request for real.
 
253
                 * We issue prefetch requests *after* fetching the current page to try
 
254
                 * to avoid having prefetching interfere with the main I/O. Also, this
 
255
                 * should happen only when we have determined there is still something
 
256
                 * to do on the current page, else we may uselessly prefetch the same
 
257
                 * page we are just about to request for real.
255
258
                 */
256
259
                if (prefetch_iterator)
257
260
                {
270
273
                                PrefetchBuffer(scan->rs_rd, MAIN_FORKNUM, tbmpre->blockno);
271
274
                        }
272
275
                }
273
 
#endif /* USE_PREFETCH */
 
276
#endif   /* USE_PREFETCH */
274
277
 
275
278
                /*
276
279
                 * Okay to fetch the tuple