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

Commita255557

Browse files
Optimise btree delete processing when no active backends.
Clarify comments, downgrade a message to DEBUG and remove somedebug counters. Direct from ideas by Heikki Linnakangas.
1 parent781ec6b commita255557

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.66 2010/04/19 17:54:48 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.67 2010/04/22 08:04:24 sriggs Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -578,9 +578,17 @@ btree_xlog_delete_get_latestRemovedXid(XLogRecord *record)
578578
OffsetNumberhoffnum;
579579
TransactionIdlatestRemovedXid=InvalidTransactionId;
580580
TransactionIdhtupxid=InvalidTransactionId;
581-
intnum_unused=0,num_redirect=0,num_dead=0;
582581
inti;
583582

583+
/*
584+
* If there's nothing running on the standby we don't need to derive
585+
* a full latestRemovedXid value, so use a fast path out of here.
586+
* That returns InvalidTransactionId, and so will conflict with
587+
* users, but since we just worked out that's zero people, its OK.
588+
*/
589+
if (CountDBBackends(InvalidOid)==0)
590+
returnlatestRemovedXid;
591+
584592
/*
585593
* Get index page
586594
*/
@@ -629,7 +637,6 @@ btree_xlog_delete_get_latestRemovedXid(XLogRecord *record)
629637
*/
630638
while (ItemIdIsRedirected(hitemid))
631639
{
632-
num_redirect++;
633640
hoffnum=ItemIdGetRedirect(hitemid);
634641
hitemid=PageGetItemId(hpage,hoffnum);
635642
CHECK_FOR_INTERRUPTS();
@@ -662,25 +669,23 @@ btree_xlog_delete_get_latestRemovedXid(XLogRecord *record)
662669
* marked on LP_NORMAL items. So we just ignore this item and move
663670
* onto the next, for the purposes of calculating latestRemovedxids.
664671
*/
665-
num_dead++;
666672
}
667673
else
668-
{
669674
Assert(!ItemIdIsUsed(hitemid));
670-
num_unused++;
671-
}
672675

673676
UnlockReleaseBuffer(hbuffer);
674677
}
675678

676679
UnlockReleaseBuffer(ibuffer);
677680

678-
Assert(num_unused==0);
679-
680681
/*
681682
* Note that if all heap tuples were LP_DEAD then we will be
682-
* returning InvalidTransactionId here. This seems very unlikely
683-
* in practice.
683+
* returning InvalidTransactionId here. That can happen if we are
684+
* re-replaying this record type, though that will be before the
685+
* consistency point and will not cause problems. It should
686+
* happen very rarely after the consistency point, though note
687+
* that we can't tell the difference between this and the fast
688+
* path exit above. May need to change that in future.
684689
*/
685690
returnlatestRemovedXid;
686691
}
@@ -963,13 +968,6 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
963968
TransactionIdlatestRemovedXid=btree_xlog_delete_get_latestRemovedXid(record);
964969
xl_btree_delete*xlrec= (xl_btree_delete*)XLogRecGetData(record);
965970

966-
/*
967-
* XXX Currently we put everybody on death row, because
968-
* currently _bt_delitems() supplies InvalidTransactionId.
969-
* This can be fairly painful, so providing a better value
970-
* here is worth some thought and possibly some effort to
971-
* improve.
972-
*/
973971
ResolveRecoveryConflictWithSnapshot(latestRemovedXid,xlrec->node);
974972
}
975973
break;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.65 2010/04/21 19:08:14 sriggs Exp $
40+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.66 2010/04/2208:04:25 sriggs Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -1839,7 +1839,8 @@ CountDBBackends(Oid databaseid)
18391839

18401840
if (proc->pid==0)
18411841
continue;/* do not count prepared xacts */
1842-
if (proc->databaseId==databaseid)
1842+
if (!OidIsValid(databaseid)||
1843+
proc->databaseId==databaseid)
18431844
count++;
18441845
}
18451846

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/storage/ipc/standby.c,v 1.17 2010/04/21 19:08:14 sriggs Exp $
14+
* $PostgreSQL: pgsql/src/backend/storage/ipc/standby.c,v 1.18 2010/04/2208:04:25 sriggs Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -248,15 +248,15 @@ ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, RelFileNode
248248

249249
/*
250250
* If we get passed InvalidTransactionId then we are a little surprised,
251-
* but it is theoretically possible, so spit out aLOG message, but not
251+
* but it is theoretically possible, so spit out aDEBUG1 message, but not
252252
* one that needs translating.
253253
*
254254
* We grab latestCompletedXid instead because this is the very latest
255255
* value it could ever be.
256256
*/
257257
if (!TransactionIdIsValid(latestRemovedXid))
258258
{
259-
elog(LOG,"InvalidlatestRemovedXid reported, usinglatestCompletedXid instead");
259+
elog(DEBUG1,"InvalidlatestremovexXid reported, usinglatestcompletedxid instead");
260260

261261
LWLockAcquire(ProcArrayLock,LW_SHARED);
262262
latestRemovedXid=ShmemVariableCache->latestCompletedXid;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp