Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e0c9301

Browse files
committed
Install infrastructure for shared-memory free space map. Doesn't actually
do anything yet, but it has the necessary connections to initialization and so forth. Make some gestures towards allowing number of blocks in a relation to be BlockNumber, ie, unsigned int, rather than signed int. (I doubt I got all the places that are sloppy about it, yet.) On the way, replace the hardwired NLOCKS_PER_XACT fudge factor with a GUC variable.
1 parent b559382 commit e0c9301

File tree

26 files changed

+572
-316
lines changed

26 files changed

+572
-316
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.69 2001/06/23 00:03:10 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.70 2001/06/27 23:31:37 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1131,6 +1131,42 @@ dynamic_library_path = '/usr/local/lib:/home/my_project/lib:$libdir:$libdir/cont
11311131
</listitem>
11321132
</varlistentry>
11331133

1134+
<varlistentry>
1135+
<term>MAX_FSM_RELATIONS (<type>integer</type>)</term>
1136+
<listitem>
1137+
<para>
1138+
Sets the maximum number of relations (tables) for which free space
1139+
will be tracked in the shared free-space map.
1140+
The default is 100. This option can only be set at server start.
1141+
</para>
1142+
</listitem>
1143+
</varlistentry>
1144+
1145+
<varlistentry>
1146+
<term>MAX_FSM_PAGES (<type>integer</type>)</term>
1147+
<listitem>
1148+
<para>
1149+
Sets the maximum number of disk pages for which free space
1150+
will be tracked in the shared free-space map.
1151+
The default is 10000. This option can only be set at server start.
1152+
</para>
1153+
</listitem>
1154+
</varlistentry>
1155+
1156+
<varlistentry>
1157+
<term>MAX_LOCKS_PER_XACT (<type>integer</type>)</term>
1158+
<listitem>
1159+
<para>
1160+
The shared lock table is sized on the assumption that at most
1161+
max_locks_per_xact * max_connections distinct objects will need
1162+
to be locked at any one time. The default, 64, has historically
1163+
proven sufficient, but you might need to raise this value if you
1164+
have clients that touch many different tables in a single transaction.
1165+
This option can only be set at server start.
1166+
</para>
1167+
</listitem>
1168+
</varlistentry>
1169+
11341170
<varlistentry>
11351171
<term>PORT (<type>integer</type>)</term>
11361172
<listitem>

src/backend/access/hash/hashpage.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashpage.c,v 1.30 2001/03/07 21:20:26 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashpage.c,v 1.31 2001/06/27 23:31:37 tgl Exp $
1212
*
1313
* NOTES
1414
* Postgres hash pages look like ordinary relation pages. The opaque
@@ -70,18 +70,15 @@ _hash_metapinit(Relation rel)
7070
int nbuckets;
7171
uint32 nelem; /* number elements */
7272
uint32 lg2nelem; /* _hash_log2(nelem) */
73-
uint32 nblocks;
7473
uint16 i;
7574

7675
/* can't be sharing this with anyone, now... */
7776
if (USELOCKING)
7877
LockRelation(rel, AccessExclusiveLock);
7978

80-
if ((nblocks = RelationGetNumberOfBlocks(rel)) != 0)
81-
{
79+
if (RelationGetNumberOfBlocks(rel) != 0)
8280
elog(ERROR, "Cannot initialize non-empty hash table %s",
8381
RelationGetRelationName(rel));
84-
}
8582

8683
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_WRITE);
8784
pg = BufferGetPage(metabuf);

src/backend/access/heap/heapam.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.119 2001/06/22 19:16:20 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.120 2001/06/27 23:31:38 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -121,8 +121,8 @@ heapgettup(Relation relation,
121121
{
122122
ItemId lpp;
123123
Page dp;
124-
int page;
125-
int pages;
124+
BlockNumber page;
125+
BlockNumber pages;
126126
int lines;
127127
OffsetNumber lineoff;
128128
int linesleft;
@@ -172,7 +172,7 @@ heapgettup(Relation relation,
172172
/*
173173
* return null immediately if relation is empty
174174
*/
175-
if (!(pages = relation->rd_nblocks))
175+
if ((pages = relation->rd_nblocks) == 0)
176176
{
177177
if (BufferIsValid(*buffer))
178178
ReleaseBuffer(*buffer);
@@ -233,15 +233,8 @@ heapgettup(Relation relation,
233233
{
234234
page = ItemPointerGetBlockNumber(tid); /* current page */
235235
}
236-
if (page < 0)
237-
{
238-
if (BufferIsValid(*buffer))
239-
ReleaseBuffer(*buffer);
240-
*buffer = InvalidBuffer;
241-
tuple->t_datamcxt = NULL;
242-
tuple->t_data = NULL;
243-
return;
244-
}
236+
237+
Assert(page < pages);
245238

246239
*buffer = ReleaseAndReadBuffer(*buffer,
247240
relation,
@@ -283,15 +276,7 @@ heapgettup(Relation relation,
283276
OffsetNumberNext(ItemPointerGetOffsetNumber(tid));
284277
}
285278

286-
if (page >= pages)
287-
{
288-
if (BufferIsValid(*buffer))
289-
ReleaseBuffer(*buffer);
290-
*buffer = InvalidBuffer;
291-
tuple->t_datamcxt = NULL;
292-
tuple->t_data = NULL;
293-
return;
294-
}
279+
Assert(page < pages);
295280

296281
*buffer = ReleaseAndReadBuffer(*buffer,
297282
relation,
@@ -369,12 +354,11 @@ heapgettup(Relation relation,
369354
* and it's time to move to the next.
370355
*/
371356
LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
372-
page = (dir < 0) ? (page - 1) : (page + 1);
373357

374358
/*
375359
* return NULL if we've exhausted all the pages
376360
*/
377-
if (page < 0 || page >= pages)
361+
if ((dir < 0) ? (page == 0) : (page+1 >= pages))
378362
{
379363
if (BufferIsValid(*buffer))
380364
ReleaseBuffer(*buffer);
@@ -384,6 +368,10 @@ heapgettup(Relation relation,
384368
return;
385369
}
386370

371+
page = (dir < 0) ? (page - 1) : (page + 1);
372+
373+
Assert(page < pages);
374+
387375
*buffer = ReleaseAndReadBuffer(*buffer,
388376
relation,
389377
page,

src/backend/access/heap/hio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Id: hio.c,v 1.39 2001/05/16 22:35:12 tgl Exp $
11+
* $Id: hio.c,v 1.40 2001/06/27 23:31:38 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -147,7 +147,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
147147
*/
148148
relation->rd_nblocks = RelationGetNumberOfBlocks(relation);
149149

150-
if ((BlockNumber) relation->rd_nblocks > oldnblocks)
150+
if (relation->rd_nblocks > oldnblocks)
151151
{
152152
/*
153153
* Someone else has indeed extended the relation recently.

src/backend/access/nbtree/nbtpage.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.51 2001/03/22 03:59:14 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.52 2001/06/27 23:31:38 tgl Exp $
1313
*
1414
* NOTES
1515
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -55,19 +55,16 @@ _bt_metapinit(Relation rel)
5555
{
5656
Buffer buf;
5757
Page pg;
58-
int nblocks;
5958
BTMetaPageData metad;
6059
BTPageOpaque op;
6160

6261
/* can't be sharing this with anyone, now... */
6362
if (USELOCKING)
6463
LockRelation(rel, AccessExclusiveLock);
6564

66-
if ((nblocks = RelationGetNumberOfBlocks(rel)) != 0)
67-
{
65+
if (RelationGetNumberOfBlocks(rel) != 0)
6866
elog(ERROR, "Cannot initialize non-empty btree %s",
6967
RelationGetRelationName(rel));
70-
}
7168

7269
buf = ReadBuffer(rel, P_NEW);
7370
pg = BufferGetPage(buf);

src/backend/catalog/heap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.168 2001/06/18 16:13:21 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.169 2001/06/27 23:31:38 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1089,6 +1089,7 @@ RelationTruncateIndexes(Oid heapId)
10891089
/* Now truncate the actual data and set blocks to zero */
10901090
smgrtruncate(DEFAULT_SMGR, currentIndex, 0);
10911091
currentIndex->rd_nblocks = 0;
1092+
currentIndex->rd_targblock = InvalidBlockNumber;
10921093

10931094
/* Initialize the index and rebuild */
10941095
InitIndexStrategy(indexInfo->ii_NumIndexAttrs,
@@ -1143,9 +1144,9 @@ heap_truncate(char *relname)
11431144
DropRelationBuffers(rel);
11441145

11451146
/* Now truncate the actual data and set blocks to zero */
1146-
11471147
smgrtruncate(DEFAULT_SMGR, rel, 0);
11481148
rel->rd_nblocks = 0;
1149+
rel->rd_targblock = InvalidBlockNumber;
11491150

11501151
/* If this relation has indexes, truncate the indexes too */
11511152
RelationTruncateIndexes(rid);

src/backend/catalog/index.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.154 2001/06/12 05:55:49 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.155 2001/06/27 23:31:38 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1456,7 +1456,7 @@ UpdateStats(Oid relid, double reltuples)
14561456
Relation pg_class;
14571457
HeapTuple tuple;
14581458
HeapTuple newtup;
1459-
long relpages;
1459+
BlockNumber relpages;
14601460
int i;
14611461
Form_pg_class rd_rel;
14621462
Relation idescs[Num_pg_class_indices];
@@ -1558,15 +1558,15 @@ UpdateStats(Oid relid, double reltuples)
15581558
reltuples = 1000;
15591559
}
15601560
else
1561-
reltuples = relpages * NTUPLES_PER_PAGE(whichRel->rd_rel->relnatts);
1561+
reltuples = (double) relpages * NTUPLES_PER_PAGE(whichRel->rd_rel->relnatts);
15621562
}
15631563

15641564
/*
15651565
* We shouldn't have to do this, but we do... Modify the reldesc in
15661566
* place with the new values so that the cache contains the latest
15671567
* copy.
15681568
*/
1569-
whichRel->rd_rel->relpages = relpages;
1569+
whichRel->rd_rel->relpages = (int32) relpages;
15701570
whichRel->rd_rel->reltuples = reltuples;
15711571

15721572
/*
@@ -1581,7 +1581,7 @@ UpdateStats(Oid relid, double reltuples)
15811581
*/
15821582
rd_rel = (Form_pg_class) GETSTRUCT(tuple);
15831583
LockBuffer(pg_class_scan->rs_cbuf, BUFFER_LOCK_EXCLUSIVE);
1584-
rd_rel->relpages = relpages;
1584+
rd_rel->relpages = (int32) relpages;
15851585
rd_rel->reltuples = reltuples;
15861586
LockBuffer(pg_class_scan->rs_cbuf, BUFFER_LOCK_UNLOCK);
15871587
WriteNoReleaseBuffer(pg_class_scan->rs_cbuf);
@@ -1600,7 +1600,7 @@ UpdateStats(Oid relid, double reltuples)
16001600
}
16011601

16021602
replace[Anum_pg_class_relpages - 1] = 'r';
1603-
values[Anum_pg_class_relpages - 1] = Int32GetDatum(relpages);
1603+
values[Anum_pg_class_relpages - 1] = Int32GetDatum((int32) relpages);
16041604
replace[Anum_pg_class_reltuples - 1] = 'r';
16051605
values[Anum_pg_class_reltuples - 1] = Float4GetDatum((float4) reltuples);
16061606
newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace);
@@ -1962,6 +1962,7 @@ reindex_index(Oid indexId, bool force, bool inplace)
19621962
/* Now truncate the actual data and set blocks to zero */
19631963
smgrtruncate(DEFAULT_SMGR, iRel, 0);
19641964
iRel->rd_nblocks = 0;
1965+
iRel->rd_targblock = InvalidBlockNumber;
19651966
}
19661967

19671968
/* Initialize the index and rebuild */

0 commit comments

Comments
 (0)