Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitacd1536

Browse files
committed
Up to now, SerializableSnapshot and QuerySnapshot are malloc'ed and
free'd for every transaction or statement, respectively. This patchputs these data structures into static memory, thus saving a few CPUcycles and two malloc calls per transaction or (in isolation levelREAD COMMITTED) per query.Manfred Koizar
1 parent752a4da commitacd1536

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

‎src/backend/storage/ipc/sinval.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.55 2003/05/27 17:49:46 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.56 2003/06/12 01:42:19 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -305,9 +305,8 @@ GetOldestXmin(bool allDbs)
305305
*----------
306306
*/
307307
Snapshot
308-
GetSnapshotData(boolserializable)
308+
GetSnapshotData(Snapshotsnapshot,boolserializable)
309309
{
310-
Snapshotsnapshot= (Snapshot)malloc(sizeof(SnapshotData));
311310
SISeg*segP=shmInvalBuffer;
312311
ProcState*stateP=segP->procState;
313312
TransactionIdxmin;
@@ -316,18 +315,29 @@ GetSnapshotData(bool serializable)
316315
intindex;
317316
intcount=0;
318317

319-
if (snapshot==NULL)
320-
elog(ERROR,"Memory exhausted in GetSnapshotData");
318+
Assert(snapshot!=NULL);
321319

322320
/*
323321
* Allocating space for MaxBackends xids is usually overkill;
324322
* lastBackend would be sufficient. But it seems better to do the
325323
* malloc while not holding the lock, so we can't look at lastBackend.
324+
*
325+
* if (snapshot->xip != NULL)
326+
* no need to free and reallocate xip;
327+
*
328+
* We can reuse the old xip array, because MaxBackends does not change
329+
* at runtime.
326330
*/
327-
snapshot->xip= (TransactionId*)
328-
malloc(MaxBackends*sizeof(TransactionId));
329331
if (snapshot->xip==NULL)
330-
elog(ERROR,"Memory exhausted in GetSnapshotData");
332+
{
333+
/*
334+
* First call for this snapshot
335+
*/
336+
snapshot->xip= (TransactionId*)
337+
malloc(MaxBackends*sizeof(TransactionId));
338+
if (snapshot->xip==NULL)
339+
elog(ERROR,"Memory exhausted in GetSnapshotData");
340+
}
331341

332342
globalxmin=xmin=GetCurrentTransactionId();
333343

‎src/backend/utils/time/tqual.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Portions Copyright (c) 1994, Regents of the University of California
1717
*
1818
* IDENTIFICATION
19-
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.62 2003/02/23 23:20:52 tgl Exp $
19+
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.63 2003/06/12 01:42:20 momjian Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -30,6 +30,8 @@
3030
staticSnapshotDataSnapshotDirtyData;
3131
SnapshotSnapshotDirty=&SnapshotDirtyData;
3232

33+
staticSnapshotDataQuerySnapshotData;
34+
staticSnapshotDataSerializableSnapshotData;
3335
SnapshotQuerySnapshot=NULL;
3436
SnapshotSerializableSnapshot=NULL;
3537

@@ -941,23 +943,16 @@ SetQuerySnapshot(void)
941943
/* 1st call in xaction? */
942944
if (SerializableSnapshot==NULL)
943945
{
944-
SerializableSnapshot=GetSnapshotData(true);
946+
SerializableSnapshot=GetSnapshotData(&SerializableSnapshotData,true);
945947
QuerySnapshot=SerializableSnapshot;
946948
Assert(QuerySnapshot!=NULL);
947949
return;
948950
}
949951

950-
if (QuerySnapshot!=SerializableSnapshot)
951-
{
952-
free(QuerySnapshot->xip);
953-
free(QuerySnapshot);
954-
QuerySnapshot=NULL;
955-
}
956-
957952
if (XactIsoLevel==XACT_SERIALIZABLE)
958953
QuerySnapshot=SerializableSnapshot;
959954
else
960-
QuerySnapshot=GetSnapshotData(false);
955+
QuerySnapshot=GetSnapshotData(&QuerySnapshotData,false);
961956

962957
Assert(QuerySnapshot!=NULL);
963958
}
@@ -1003,19 +998,11 @@ CopyQuerySnapshot(void)
1003998
void
1004999
FreeXactSnapshot(void)
10051000
{
1006-
if (QuerySnapshot!=NULL&&QuerySnapshot!=SerializableSnapshot)
1007-
{
1008-
free(QuerySnapshot->xip);
1009-
free(QuerySnapshot);
1010-
}
1011-
1001+
/*
1002+
* We do not free(QuerySnapshot->xip);
1003+
* or free(SerializableSnapshot->xip);
1004+
* they will be reused soon
1005+
*/
10121006
QuerySnapshot=NULL;
1013-
1014-
if (SerializableSnapshot!=NULL)
1015-
{
1016-
free(SerializableSnapshot->xip);
1017-
free(SerializableSnapshot);
1018-
}
1019-
10201007
SerializableSnapshot=NULL;
10211008
}

‎src/include/utils/tqual.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: tqual.h,v 1.44 2003/02/23 23:20:52 tgl Exp $
11+
* $Id: tqual.h,v 1.45 2003/06/12 01:42:21 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -113,7 +113,7 @@ extern int HeapTupleSatisfiesUpdate(HeapTuple tuple,
113113
externHTSV_ResultHeapTupleSatisfiesVacuum(HeapTupleHeadertuple,
114114
TransactionIdOldestXmin);
115115

116-
externSnapshotGetSnapshotData(boolserializable);
116+
externSnapshotGetSnapshotData(Snapshotsnapshot,boolserializable);
117117
externvoidSetQuerySnapshot(void);
118118
externSnapshotCopyQuerySnapshot(void);
119119
externvoidFreeXactSnapshot(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp