postgresql源码学习(53)—— vacuum②-lazy vacuum之heap_vacuum_rel函数




/*
 * heap_vacuum_rel - Vacuum a single heap relation.
 *
 * Parameters:
 *        onerel: relation to vacuum
 *        vacuum_full: true for full VACUUM, false for lazy VACUUM
 *        do_toast: true to process the TOAST table, if any
 *        vacuum_stat: if not NULL, don't update statistics here
 *
 * Returns: the number of indexes updated.
 *
 * NOTE: if do_toast is true, then the caller should be holding an exclusive
 * lock on the relation, whereas if do_toast is false, the caller had better
 * be holding at least a Share lock on the relation to prevent other
 * backends from deleting the visible tuples out from under us.
 *
 * NOTE: this routine does not start or commit a transaction.
 */
int
heap_vacuum_rel(Relation onerel, bool vacuum_full, bool do_toast,
                VacuumStmt *vacuum_stat)
{
    int            num_index_scans = 0;
    PGRUsage    ru0;
 
    pg_rusage_init(&ru0);
 
    /* Open all indexes of the relation */
    vacuum_set_xid_limits(onerel, vacuum_full, &OldestXmin, &FreezeLimit,
                          &MultiXactCutoff, &ProcArrayOldestXmin);
    vacuum_delay_point();
 
    /*
     * Scan the relation, processing all live tuples (removing dead ones). If
     * it's a toast table, however, we don't need to process toast live
     * tuples for this.
     */
    if (!do_toast)
        num_index_scans += heap_vacuum_scan(onerel, vacuum_full, vacuum_stat);
 
    /* Open the toast relation and process it too if necessary */
    if (do_toast)
    {
        Relation    toastrel;
 
        /*
         * Even if we didn't find any indexes, we need to open the toast
         * relation to check for toast chains.
         */
        toastrel = table_open(toast_relation_id, AccessShareLock);
 
        num_index_scans += toast_vacuum_rel(toastrel, vacuum_full,
                                            vacuum_stat);
        table_close(toastrel, AccessShareLock);
    }
 
    /*
     * Done with indexes.  Now truncate off any space at the end of the heap
     * that we can.
     */
    heap_truncate(onerel);
 
    /* Update the shared free space counter */
    VacuumStmt::vacuum_stat->num_index_scans += num_index_scans;
    VacuumStmt::vacuum_stat->num_pages = RelationGetNumberOfBlocks(onerel);
    VacuumStmt::vacuum_stat->old_live_count = -1; /* not valid */
    VacuumStmt::vacuum_stat->new_live_count = -1; /* not valid */
    VacuumStmt::vacuum_stat->is_wraparound = false;
    VacuumStmt::vacuum_stat->is_full_analyze = false;
 
    /*
     * Update the relation's pg_class entry to show the new size.
     *
     * Note:

评论已关闭

推荐阅读

Vue中使用mind-map实现在线思维导图
2024年08月04日
VUE
Web前端最全Vue实现免密登录跳转的方式_vue怎么样不登录返回首页,最强技术实现
2024年08月04日
VUE
vue3 项目搭建教程(基于create-vue,vite,Vite + Vue)
2024年08月04日
VUE
Vue-颜色选择器实现方案——>Vue-Color( 实战*1+ Demo*7)
2024年08月04日
VUE
Vue项目卡顿慢加载?这些优化技巧告诉你!_vue数据多渲染卡顿
2024年08月04日
VUE
vue中的keep-alive详解与应用场景
2024年08月04日
VUE
Vue、React实现excel导出功能(三种实现方式保姆级讲解)
2024年08月04日
vue-office/docx插件实现docx文件预览
2024年08月04日
VUE
java调用js文件的两种方法(支持V8引擎)
2024年08月04日
JavaScript:解决计算精度问题/mathjs/bignumber.js/big.js/decimal.js
2024年08月04日
两周从爬虫小白变大神 _yjs_js_security_passport
2024年08月04日
JS笔记(对象、函数、数组)
2024年08月04日
Markdown.js:强大的纯JavaScript Markdown解析器
2024年08月04日
Vue项目:js模拟点击a标签下载文件并重命名,URL文件地址下载方法、请求接口下载文件方法总结。
2024年08月04日
vue 父组件怎么获取子组件里面的data数据
2024年08月04日
VUE
个人开发实现AI套壳网站快速搭建(Vue+elementUI+SpringBoot)
2024年08月04日
el-table 表格封装并改造实现单元格可编辑
2024年08月04日
none
nodejs环境下创建vue项目、SSH密钥登陆!!!
2024年08月04日
vue+quill+element-ui实现视频、图片上传及缩放保姆级教程,轻松使用富文本
2024年08月04日
【three.js】22. Imported Models导入模型
2024年08月04日