暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL 15 preview - heap pruning (碎片整理优化 Only call BufferGetBlockNumber() once)

原创 digoal 2022-01-20
398

作者

digoal

日期

2022-01-18

标签

PostgreSQL , heap pruning , 碎片整理


https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=c702d656a28386cf5f642206b495c66775afc4ea

heap pruning: Only call BufferGetBlockNumber() once.  
author  Andres Freund <andres@anarazel.de>    
Mon, 17 Jan 2022 23:31:28 +0000 (15:31 -0800)  
committer   Andres Freund <andres@anarazel.de>    
Mon, 17 Jan 2022 23:35:11 +0000 (15:35 -0800)  
commit  c702d656a28386cf5f642206b495c66775afc4ea  
tree    ef659920a7e13699815946d52a7d433ad57e2627    tree  
parent  35b2803cf29a39b1adaf55b8b376b965837e9c50    commit | diff  
heap pruning: Only call BufferGetBlockNumber() once.  
BufferGetBlockNumber() is not that cheap and obviously cannot change during  
one heap_prune_page(), so only call it once. We might be able to do better and  
pass the block number from the caller, but that'd be a larger change...  
Discussion: https://postgr.es/m/20211211045710.ljtuu4gfloh754rs@alap3.anarazel.de  

src/backend/access/heap/pruneheap.c

 242 /*  
 243  * Prune and repair fragmentation in the specified page.  
 244  *  
 245  * Caller must have pin and buffer cleanup lock on the page.  Note that we  
 246  * don't update the FSM information for page on caller's behalf.  
 247  *  
 248  * vistest is used to distinguish whether tuples are DEAD or RECENTLY_DEAD  
 249  * (see heap_prune_satisfies_vacuum and  
 250  * HeapTupleSatisfiesVacuum). old_snap_xmin / old_snap_ts need to  
 251  * either have been set by TransactionIdLimitedForOldSnapshots, or  
 252  * InvalidTransactionId/0 respectively.  
 253  *  
 254  * Sets *nnewlpdead for caller, indicating the number of items that were  
 255  * newly set LP_DEAD during prune operation.  
 256  *  
 257  * off_loc is the offset location required by the caller to use in error  
 258  * callback.  
 259  *  
 260  * Returns the number of tuples deleted from the page during this call.  
 261  */  
 262 int  
 263 heap_page_prune(Relation relation, Buffer buffer,  
 264                 GlobalVisState *vistest,  
 265                 TransactionId old_snap_xmin,  
 266                 TimestampTz old_snap_ts,  
 267                 int *nnewlpdead,  
 268                 OffsetNumber *off_loc)  
 269 {  
heap pruning: Only call BufferGetBlockNumber() once.  
[postgresql.git] / src / backend / access / heap / pruneheap.c  
diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c  
index 3201fcc52b097764c6e493c956dff7af0053e2a6..b3e2eec52fa3be702e3423df2a19875fb8be4de9 100644 (file)  
--- a/src/backend/access/heap/pruneheap.c  
+++ b/src/backend/access/heap/pruneheap.c  
@@ -269,6 +269,7 @@ heap_page_prune(Relation relation, Buffer buffer,  
 {  
    int         ndeleted = 0;  
    Page        page = BufferGetPage(buffer);  
+   BlockNumber blockno = BufferGetBlockNumber(buffer);  
    OffsetNumber offnum,  
                maxoff;  
    PruneState  prstate;  
@@ -335,7 +336,7 @@ heap_page_prune(Relation relation, Buffer buffer,  
        htup = (HeapTupleHeader) PageGetItem(page, itemid);  
        tup.t_data = htup;  
        tup.t_len = ItemIdGetLength(itemid);  
-       ItemPointerSet(&(tup.t_self), BufferGetBlockNumber(buffer), offnum);  
+       ItemPointerSet(&(tup.t_self), blockno, offnum);  
        /*  
         * Set the offset number so that we can display it along with any  

期望 PostgreSQL 增加什么功能?

PolarDB for PostgreSQL云原生分布式开源数据库

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论