开发者社区> 嗯哼9925> 正文

PostgreSQL在何处处理 sql查询之三十八

简介:
+关注继续查看

这里又遇到了函数指针:

executor.h头文件中,定义了 ExecScanAccessMtd 指针,或者定义了一个ExecScanAccessMtd 函数原型的指针

/*
 * prototypes from functions in execScan.c
 */
typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node);

之后,在NodeSeqScan.c处有一个实现:

复制代码
/* ----------------------------------------------------------------
 *        SeqNext
 *
 *        This is a workhorse for ExecSeqScan
 * ----------------------------------------------------------------
 */
static TupleTableSlot *
SeqNext(SeqScanState *node)
{
    HeapTuple    tuple;
    HeapScanDesc scandesc;
    EState       *estate;
    ScanDirection direction;
    TupleTableSlot *slot;

    /*
     * get information from the estate and scan state
     */
    scandesc = node->ss_currentScanDesc;
    estate = node->ps.state;
    direction = estate->es_direction;
    slot = node->ss_ScanTupleSlot;

    /*
     * get the next tuple from the table
     */
    tuple = heap_getnext(scandesc, direction);

    /*
     * save the tuple and the buffer returned to us by the access methods in
     * our scan tuple slot and return the slot.  Note: we pass 'false' because
     * tuples returned by heap_getnext() are pointers onto disk pages and were
     * not created with palloc() and so should not be pfree()'d.  Note also
     * that ExecStoreTuple will increment the refcount of the buffer; the
     * refcount will not be dropped until the tuple table slot is cleared.
     */
    if (tuple)
        ExecStoreTuple(tuple,    /* tuple to store */
                       slot,    /* slot to store in */
                       scandesc->rs_cbuf,        /* buffer associated with this
                                                 * tuple */
                       false);    /* don't pfree this pointer */
    else
        ExecClearTuple(slot);

    return slot;
}
复制代码

之后,在下列方法中, 把函数指针当作参数进行传递:

复制代码
TupleTableSlot *
ExecScan(ScanState *node,
         ExecScanAccessMtd accessMtd,    /* function returning a tuple */
         ExecScanRecheckMtd recheckMtd)
{
   ...
}
复制代码

调用:

复制代码
TupleTableSlot *
ExecSeqScan(SeqScanState *node)
{
    return ExecScan((ScanState *) node,
                    (ExecScanAccessMtd) SeqNext,
                    (ExecScanRecheckMtd) SeqRecheck);
}
复制代码







版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
软件测试|SQL指定查询条件,WHERE的使用
软件测试|SQL指定查询条件,WHERE的使用
16 0
JPA的EntityManager来实现SQL或者HQL语句查询
JPA的EntityManager来实现SQL或者HQL语句查询
13 0
《阿里云认证的解析与实战-数据仓库ACP认证》——云原生数据仓库AnalyticDB PostgreSQL版功能演示(上)——五、执行SQL查询
《阿里云认证的解析与实战-数据仓库ACP认证》——云原生数据仓库AnalyticDB PostgreSQL版功能演示(上)——五、执行SQL查询
17 0
提高sql查询性能-使用instr函数替换like
提高sql查询性能-使用instr函数替换like
19 0
【Python】单表多功能查询的SQL封装
【Python】单表多功能查询的SQL封装
17 0
1 SQL快速入门、查询(SqlServer)[郝斌SqlServer完整版]
系统数据库:master、model、msdb、tempdb【我们自定义数据库的管理维护运行都需要系统库支持】
18 0
Django model层之执行原始SQL查询
Django model层之执行原始SQL查询
28 0
【大数据开发运维解决方案】Oracle Sql基础查询
空字符串在oracle中常常相当于null,为什么不说空字符串等价于null呢,看案例: 可以看到,本身deptno是number类型的,而‘’字符串本身是varchar类型,这与null可以是任何类型不同,所以也就不等价。
55 0
Zp
Oracle给sql查询字段的结果后加上%
Oracle给sql查询字段的结果后加上%
210 0
+关注
嗯哼9925
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
第十二届 BigData NoSQL Meetup — 基于hbase的New sql落地实践
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
相关实验场景
更多
相关镜像