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

« back to all changes in this revision

Viewing changes to src/backend/access/heap/heapam.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 *
10
10
 * IDENTIFICATION
11
 
 *        $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.275 2009/05/12 16:43:32 tgl Exp $
 
11
 *        $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.277 2009/06/11 14:48:53 momjian Exp $
12
12
 *
13
13
 *
14
14
 * INTERFACE ROUTINES
69
69
 
70
70
 
71
71
/* GUC variable */
72
 
bool    synchronize_seqscans = true;
 
72
bool            synchronize_seqscans = true;
73
73
 
74
74
 
75
75
static HeapScanDesc heap_beginscan_internal(Relation relation,
93
93
 * ----------------
94
94
 */
95
95
static void
96
 
initscan(HeapScanDesc scan, ScanKey key)
 
96
initscan(HeapScanDesc scan, ScanKey key, bool is_rescan)
97
97
{
98
98
        bool            allow_strat;
99
99
        bool            allow_sync;
116
116
         * strategy and enable synchronized scanning (see syncscan.c).  Although
117
117
         * the thresholds for these features could be different, we make them the
118
118
         * same so that there are only two behaviors to tune rather than four.
119
 
         * (However, some callers need to be able to disable one or both of
120
 
         * these behaviors, independently of the size of the table; also there
121
 
         * is a GUC variable that can disable synchronized scanning.)
 
119
         * (However, some callers need to be able to disable one or both of these
 
120
         * behaviors, independently of the size of the table; also there is a GUC
 
121
         * variable that can disable synchronized scanning.)
122
122
         *
123
123
         * During a rescan, don't make a new strategy object if we don't have to.
124
124
         */
143
143
                scan->rs_strategy = NULL;
144
144
        }
145
145
 
146
 
        if (allow_sync && synchronize_seqscans)
 
146
        if (is_rescan)
 
147
        {
 
148
                /*
 
149
                 * If rescan, keep the previous startblock setting so that rewinding a
 
150
                 * cursor doesn't generate surprising results.  Reset the syncscan
 
151
                 * setting, though.
 
152
                 */
 
153
                scan->rs_syncscan = (allow_sync && synchronize_seqscans);
 
154
        }
 
155
        else if (allow_sync && synchronize_seqscans)
147
156
        {
148
157
                scan->rs_syncscan = true;
149
158
                scan->rs_startblock = ss_get_location(scan->rs_rd, scan->rs_nblocks);
1218
1227
        else
1219
1228
                scan->rs_key = NULL;
1220
1229
 
1221
 
        initscan(scan, key);
 
1230
        initscan(scan, key, false);
1222
1231
 
1223
1232
        return scan;
1224
1233
}
1240
1249
        /*
1241
1250
         * reinitialize scan descriptor
1242
1251
         */
1243
 
        initscan(scan, key);
 
1252
        initscan(scan, key, true);
1244
1253
}
1245
1254
 
1246
1255
/* ----------------
1784
1793
FreeBulkInsertState(BulkInsertState bistate)
1785
1794
{
1786
1795
        if (bistate->current_buf != InvalidBuffer)
1787
 
                ReleaseBuffer(bistate->current_buf);            
 
1796
                ReleaseBuffer(bistate->current_buf);
1788
1797
        FreeAccessStrategy(bistate->strategy);
1789
1798
        pfree(bistate);
1790
1799
}
1968
1977
 
1969
1978
        /* Clear the bit in the visibility map if necessary */
1970
1979
        if (all_visible_cleared)
1971
 
                visibilitymap_clear(relation, 
 
1980
                visibilitymap_clear(relation,
1972
1981
                                                        ItemPointerGetBlockNumber(&(heaptup->t_self)));
1973
1982
 
1974
1983
        /*
3428
3437
        LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
3429
3438
 
3430
3439
        /*
3431
 
         * Don't update the visibility map here. Locking a tuple doesn't
3432
 
         * change visibility info.
 
3440
         * Don't update the visibility map here. Locking a tuple doesn't change
 
3441
         * visibility info.
3433
3442
         */
3434
3443
 
3435
3444
        /*
4106
4115
                                                        nowunused, nunused,
4107
4116
                                                        clean_move);
4108
4117
 
4109
 
        freespace = PageGetHeapFreeSpace(page); /* needed to update FSM below */
 
4118
        freespace = PageGetHeapFreeSpace(page);         /* needed to update FSM below */
4110
4119
 
4111
4120
        /*
4112
 
         * Note: we don't worry about updating the page's prunability hints.
4113
 
         * At worst this will cause an extra prune cycle to occur soon.
 
4121
         * Note: we don't worry about updating the page's prunability hints. At
 
4122
         * worst this will cause an extra prune cycle to occur soon.
4114
4123
         */
4115
4124
 
4116
4125
        PageSetLSN(page, lsn);
4208
4217
        OffsetNumber offnum;
4209
4218
        ItemId          lp = NULL;
4210
4219
        HeapTupleHeader htup;
4211
 
        BlockNumber     blkno;
 
4220
        BlockNumber blkno;
4212
4221
 
4213
4222
        blkno = ItemPointerGetBlockNumber(&(xlrec->target.tid));
4214
4223
 
4215
4224
        /*
4216
 
         * The visibility map always needs to be updated, even if the heap page
4217
 
         * is already up-to-date.
 
4225
         * The visibility map always needs to be updated, even if the heap page is
 
4226
         * already up-to-date.
4218
4227
         */
4219
4228
        if (xlrec->all_visible_cleared)
4220
4229
        {
4221
 
                Relation reln = CreateFakeRelcacheEntry(xlrec->target.node);
 
4230
                Relation        reln = CreateFakeRelcacheEntry(xlrec->target.node);
 
4231
 
4222
4232
                visibilitymap_clear(reln, blkno);
4223
4233
                FreeFakeRelcacheEntry(reln);
4224
4234
        }
4285
4295
        xl_heap_header xlhdr;
4286
4296
        uint32          newlen;
4287
4297
        Size            freespace;
4288
 
        BlockNumber     blkno;
 
4298
        BlockNumber blkno;
4289
4299
 
4290
4300
        blkno = ItemPointerGetBlockNumber(&(xlrec->target.tid));
4291
4301
 
4292
4302
        /*
4293
 
         * The visibility map always needs to be updated, even if the heap page
4294
 
         * is already up-to-date.
 
4303
         * The visibility map always needs to be updated, even if the heap page is
 
4304
         * already up-to-date.
4295
4305
         */
4296
4306
        if (xlrec->all_visible_cleared)
4297
4307
        {
4298
 
                Relation reln = CreateFakeRelcacheEntry(xlrec->target.node);
 
4308
                Relation        reln = CreateFakeRelcacheEntry(xlrec->target.node);
 
4309
 
4299
4310
                visibilitymap_clear(reln, blkno);
4300
4311
                FreeFakeRelcacheEntry(reln);
4301
4312
        }
4352
4363
        if (offnum == InvalidOffsetNumber)
4353
4364
                elog(PANIC, "heap_insert_redo: failed to add tuple");
4354
4365
 
4355
 
        freespace = PageGetHeapFreeSpace(page); /* needed to update FSM below */
 
4366
        freespace = PageGetHeapFreeSpace(page);         /* needed to update FSM below */
4356
4367
 
4357
4368
        PageSetLSN(page, lsn);
4358
4369
        PageSetTLI(page, ThisTimeLineID);
4365
4376
 
4366
4377
        /*
4367
4378
         * If the page is running low on free space, update the FSM as well.
4368
 
         * Arbitrarily, our definition of "low" is less than 20%. We can't do
4369
 
         * much better than that without knowing the fill-factor for the table.
 
4379
         * Arbitrarily, our definition of "low" is less than 20%. We can't do much
 
4380
         * better than that without knowing the fill-factor for the table.
4370
4381
         *
4371
4382
         * XXX: We don't get here if the page was restored from full page image.
4372
4383
         * We don't bother to update the FSM in that case, it doesn't need to be
4401
4412
        Size            freespace;
4402
4413
 
4403
4414
        /*
4404
 
         * The visibility map always needs to be updated, even if the heap page
4405
 
         * is already up-to-date.
 
4415
         * The visibility map always needs to be updated, even if the heap page is
 
4416
         * already up-to-date.
4406
4417
         */
4407
4418
        if (xlrec->all_visible_cleared)
4408
4419
        {
4409
 
                Relation reln = CreateFakeRelcacheEntry(xlrec->target.node);
 
4420
                Relation        reln = CreateFakeRelcacheEntry(xlrec->target.node);
 
4421
 
4410
4422
                visibilitymap_clear(reln,
4411
4423
                                                        ItemPointerGetBlockNumber(&xlrec->target.tid));
4412
4424
                FreeFakeRelcacheEntry(reln);
4495
4507
newt:;
4496
4508
 
4497
4509
        /*
4498
 
         * The visibility map always needs to be updated, even if the heap page
4499
 
         * is already up-to-date.
 
4510
         * The visibility map always needs to be updated, even if the heap page is
 
4511
         * already up-to-date.
4500
4512
         */
4501
4513
        if (xlrec->new_all_visible_cleared)
4502
4514
        {
4503
 
                Relation reln = CreateFakeRelcacheEntry(xlrec->target.node);
 
4515
                Relation        reln = CreateFakeRelcacheEntry(xlrec->target.node);
 
4516
 
4504
4517
                visibilitymap_clear(reln, ItemPointerGetBlockNumber(&xlrec->newtid));
4505
4518
                FreeFakeRelcacheEntry(reln);
4506
4519
        }
4586
4599
        if (xlrec->new_all_visible_cleared)
4587
4600
                PageClearAllVisible(page);
4588
4601
 
4589
 
        freespace = PageGetHeapFreeSpace(page); /* needed to update FSM below */
 
4602
        freespace = PageGetHeapFreeSpace(page);         /* needed to update FSM below */
4590
4603
 
4591
4604
        PageSetLSN(page, lsn);
4592
4605
        PageSetTLI(page, ThisTimeLineID);
4595
4608
 
4596
4609
        /*
4597
4610
         * If the page is running low on free space, update the FSM as well.
4598
 
         * Arbitrarily, our definition of "low" is less than 20%. We can't do
4599
 
         * much better than that without knowing the fill-factor for the table.
 
4611
         * Arbitrarily, our definition of "low" is less than 20%. We can't do much
 
4612
         * better than that without knowing the fill-factor for the table.
4600
4613
         *
4601
4614
         * However, don't update the FSM on HOT updates, because after crash
4602
4615
         * recovery, either the old or the new tuple will certainly be dead and
4610
4623
         */
4611
4624
        if (!hot_update && freespace < BLCKSZ / 5)
4612
4625
                XLogRecordPageWithFreeSpace(xlrec->target.node,
4613
 
                                        ItemPointerGetBlockNumber(&(xlrec->newtid)), freespace);
 
4626
                                         ItemPointerGetBlockNumber(&(xlrec->newtid)), freespace);
4614
4627
}
4615
4628
 
4616
4629
static void