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

Commite85a01d

Browse files
committed
Clean up the representation of special snapshots by including a "method
pointer" in every Snapshot struct. This allows removal of the case-by-casetests in HeapTupleSatisfiesVisibility, which should make it a bit faster(I didn't try any performance tests though). More importantly, we are nolonger violating portable C practices by assuming that small integers aredistinct from all pointer values, and HeapTupleSatisfiesDirty no longerhas a non-reentrant API involving side-effects on a global variable.There were a couple of places calling HeapTupleSatisfiesXXX routinesdirectly rather than through the HeapTupleSatisfiesVisibility macro.Since these places had to be changed anyway, I chose to make them gothrough the macro for uniformity.Along the way I renamed HeapTupleSatisfiesSnapshot to HeapTupleSatisfiesMVCCto emphasize that it's only used with MVCC-type snapshots. I was sorelytempted to rename HeapTupleSatisfiesVisibility to HeapTupleSatisfiesSnapshot,but forebore for the moment to avoid confusion and reduce the likelihood thatthis patch breaks some of the pending patches. Might want to reconsiderdoing that later.
1 parent75c6519 commite85a01d

File tree

10 files changed

+148
-121
lines changed

10 files changed

+148
-121
lines changed

‎contrib/pgstattuple/pgstattuple.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.25 2006/10/04 00:29:46 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.26 2007/03/25 19:45:13 tgl Exp $
33
*
44
* Copyright (c) 2001,2002Tatsuo Ishii
55
*
@@ -256,10 +256,10 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
256256
/* scan the relation */
257257
while ((tuple=heap_getnext(scan,ForwardScanDirection))!=NULL)
258258
{
259-
/* must hold a buffer lock to callHeapTupleSatisfiesNow */
259+
/* must hold a buffer lock to callHeapTupleSatisfiesVisibility */
260260
LockBuffer(scan->rs_cbuf,BUFFER_LOCK_SHARE);
261261

262-
if (HeapTupleSatisfiesNow(tuple->t_data,scan->rs_cbuf))
262+
if (HeapTupleSatisfiesVisibility(tuple,SnapshotNow,scan->rs_cbuf))
263263
{
264264
stat.tuple_len+=tuple->t_len;
265265
stat.tuple_count++;

‎src/backend/access/heap/heapam.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.228 2007/02/09 03:35:33 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.229 2007/03/25 19:45:13 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1706,7 +1706,7 @@ heap_delete(Relation relation, ItemPointer tid,
17061706
if (crosscheck!=InvalidSnapshot&&result==HeapTupleMayBeUpdated)
17071707
{
17081708
/* Perform additional check for serializable RI updates */
1709-
if (!HeapTupleSatisfiesSnapshot(tp.t_data,crosscheck,buffer))
1709+
if (!HeapTupleSatisfiesVisibility(&tp,crosscheck,buffer))
17101710
result=HeapTupleUpdated;
17111711
}
17121712

@@ -2025,7 +2025,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
20252025
if (crosscheck!=InvalidSnapshot&&result==HeapTupleMayBeUpdated)
20262026
{
20272027
/* Perform additional check for serializable RI updates */
2028-
if (!HeapTupleSatisfiesSnapshot(oldtup.t_data,crosscheck,buffer))
2028+
if (!HeapTupleSatisfiesVisibility(&oldtup,crosscheck,buffer))
20292029
result=HeapTupleUpdated;
20302030
}
20312031

‎src/backend/access/nbtree/nbtinsert.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.154 2007/03/05 14:13:12 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.155 2007/03/25 19:45:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -176,11 +176,14 @@ _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel,
176176
{
177177
TupleDescitupdesc=RelationGetDescr(rel);
178178
intnatts=rel->rd_rel->relnatts;
179+
SnapshotDataSnapshotDirty;
179180
OffsetNumbermaxoff;
180181
Pagepage;
181182
BTPageOpaqueopaque;
182183
Buffernbuf=InvalidBuffer;
183184

185+
InitDirtySnapshot(SnapshotDirty);
186+
184187
page=BufferGetPage(buf);
185188
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
186189
maxoff=PageGetMaxOffsetNumber(page);
@@ -232,13 +235,13 @@ _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel,
232235
/* okay, we gotta fetch the heap tuple ... */
233236
curitup= (IndexTuple)PageGetItem(page,curitemid);
234237
htup.t_self=curitup->t_tid;
235-
if (heap_fetch(heapRel,SnapshotDirty,&htup,&hbuffer,
238+
if (heap_fetch(heapRel,&SnapshotDirty,&htup,&hbuffer,
236239
true,NULL))
237240
{
238241
/* it is a duplicate */
239242
TransactionIdxwait=
240-
(TransactionIdIsValid(SnapshotDirty->xmin)) ?
241-
SnapshotDirty->xmin :SnapshotDirty->xmax;
243+
(TransactionIdIsValid(SnapshotDirty.xmin)) ?
244+
SnapshotDirty.xmin :SnapshotDirty.xmax;
242245

243246
ReleaseBuffer(hbuffer);
244247

‎src/backend/catalog/catalog.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.69 2007/01/05 22:19:24 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.70 2007/03/2519:45:14 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -361,10 +361,13 @@ Oid
361361
GetNewOidWithIndex(Relationrelation,Relationindexrel)
362362
{
363363
OidnewOid;
364+
SnapshotDataSnapshotDirty;
364365
IndexScanDescscan;
365366
ScanKeyDatakey;
366367
boolcollides;
367368

369+
InitDirtySnapshot(SnapshotDirty);
370+
368371
/* Generate new OIDs until we find one not in the table */
369372
do
370373
{
@@ -377,7 +380,7 @@ GetNewOidWithIndex(Relation relation, Relation indexrel)
377380

378381
/* see notes above about using SnapshotDirty */
379382
scan=index_beginscan(relation,indexrel,
380-
SnapshotDirty,1,&key);
383+
&SnapshotDirty,1,&key);
381384

382385
collides=HeapTupleIsValid(index_getnext(scan,ForwardScanDirection));
383386

‎src/backend/catalog/index.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.280 2007/03/03 20:08:41 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.281 2007/03/25 19:45:14 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1828,10 +1828,11 @@ validate_index_heapscan(Relation heapRelation,
18281828
*/
18291829
if (indexInfo->ii_Unique)
18301830
{
1831-
/* musthold abufferlockto callHeapTupleSatisfiesNow */
1831+
/* mustlockbuffer to callHeapTupleSatisfiesVisibility */
18321832
LockBuffer(scan->rs_cbuf,BUFFER_LOCK_SHARE);
18331833

1834-
if (HeapTupleSatisfiesNow(heapTuple->t_data,scan->rs_cbuf))
1834+
if (HeapTupleSatisfiesVisibility(heapTuple,SnapshotNow,
1835+
scan->rs_cbuf))
18351836
check_unique= true;
18361837
else
18371838
check_unique= false;

‎src/backend/executor/execMain.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.290 2007/03/06 02:06:13 momjian Exp $
29+
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.291 2007/03/25 19:45:14 tgl Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -1893,6 +1893,7 @@ EvalPlanQual(EState *estate, Index rti,
18931893
Relationrelation;
18941894
HeapTupleDatatuple;
18951895
HeapTuplecopyTuple=NULL;
1896+
SnapshotDataSnapshotDirty;
18961897
boolendNode;
18971898

18981899
Assert(rti!=0);
@@ -1925,12 +1926,13 @@ EvalPlanQual(EState *estate, Index rti,
19251926
*
19261927
* Loop here to deal with updated or busy tuples
19271928
*/
1929+
InitDirtySnapshot(SnapshotDirty);
19281930
tuple.t_self=*tid;
19291931
for (;;)
19301932
{
19311933
Bufferbuffer;
19321934

1933-
if (heap_fetch(relation,SnapshotDirty,&tuple,&buffer, true,NULL))
1935+
if (heap_fetch(relation,&SnapshotDirty,&tuple,&buffer, true,NULL))
19341936
{
19351937
/*
19361938
* If xmin isn't what we're expecting, the slot must have been
@@ -1948,17 +1950,17 @@ EvalPlanQual(EState *estate, Index rti,
19481950
}
19491951

19501952
/* otherwise xmin should not be dirty... */
1951-
if (TransactionIdIsValid(SnapshotDirty->xmin))
1953+
if (TransactionIdIsValid(SnapshotDirty.xmin))
19521954
elog(ERROR,"t_xmin is uncommitted in tuple to be updated");
19531955

19541956
/*
19551957
* If tuple is being updated by other transaction then we have to
19561958
* wait for its commit/abort.
19571959
*/
1958-
if (TransactionIdIsValid(SnapshotDirty->xmax))
1960+
if (TransactionIdIsValid(SnapshotDirty.xmax))
19591961
{
19601962
ReleaseBuffer(buffer);
1961-
XactLockTableWait(SnapshotDirty->xmax);
1963+
XactLockTableWait(SnapshotDirty.xmax);
19621964
continue;/* loop back to repeat heap_fetch */
19631965
}
19641966

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
*
2525
* IDENTIFICATION
26-
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.22 2007/03/23 03:16:39 momjian Exp $
26+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.23 2007/03/25 19:45:14 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -484,7 +484,7 @@ GetOldestXmin(bool allDbs, bool ignoreVacuum)
484484
* limited cache area for subxact XIDs, full information may not be
485485
* available. If we find any overflowed subxid arrays, we have to mark
486486
* the snapshot's subxid data as overflowed, and extra work will need to
487-
* be done to determine what's running (seeXidInSnapshot() in tqual.c).
487+
* be done to determine what's running (seeXidInMVCCSnapshot() in tqual.c).
488488
*
489489
* We also update the following backend-global variables:
490490
*TransactionXmin: the oldest xmin of any snapshot in use in the

‎src/backend/utils/adt/ri_triggers.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1717
*
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.92 2007/03/15 23:12:06 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.93 2007/03/25 19:45:14 tgl Exp $
1919
*
2020
* ----------
2121
*/
@@ -277,19 +277,19 @@ RI_FKey_check(PG_FUNCTION_ARGS)
277277
* We should not even consider checking the row if it is no longer valid,
278278
* since it was either deleted (so the deferred check should be skipped)
279279
* or updated (in which case only the latest version of the row should be
280-
* checked). Test its livenesswith HeapTupleSatisfiesItself.
280+
* checked). Test its livenessaccording to SnapshotSelf.
281281
*
282282
* NOTE: The normal coding rule is that one must acquire the buffer
283-
* content lock to callHeapTupleSatisfiesFOO.We can skip that here
284-
* because we know that AfterTriggerExecute just fetched the tuple
283+
* content lock to callHeapTupleSatisfiesVisibility.We can skip that
284+
*herebecause we know that AfterTriggerExecute just fetched the tuple
285285
* successfully, so there cannot be a VACUUM compaction in progress on the
286286
* page (either heap_fetch would have waited for the VACUUM, or the
287287
* VACUUM's LockBufferForCleanup would be waiting for us to drop pin).
288288
* And since this is a row inserted by our open transaction, no one else
289289
* can be entitled to change its xmin/xmax.
290290
*/
291291
Assert(new_row_buf!=InvalidBuffer);
292-
if (!HeapTupleSatisfiesItself(new_row->t_data,new_row_buf))
292+
if (!HeapTupleSatisfiesVisibility(new_row,SnapshotSelf,new_row_buf))
293293
returnPointerGetDatum(NULL);
294294

295295
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp