博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PostgreSQL在何处处理 sql查询之三十二
阅读量:6452 次
发布时间:2019-06-23

本文共 4365 字,大约阅读时间需要 14 分钟。

接前面,继续观察 PortalStart,其中有:

/*                 * Create QueryDesc in portal's context; for the moment, set                 * the destination to DestNone.                 */               queryDesc = CreateQueryDesc((PlannedStmt *) linitial(portal->stmts),                                            portal->sourceText,                                            GetActiveSnapshot(),                                            InvalidSnapshot,                                            None_Receiver,                                            params,                                            0);

CreateQueryDesc 的程序:

/* * CreateQueryDesc */QueryDesc *CreateQueryDesc(PlannedStmt *plannedstmt,                const char *sourceText,                Snapshot snapshot,                Snapshot crosscheck_snapshot,                DestReceiver *dest,                ParamListInfo params,                int instrument_options){    QueryDesc  *qd = (QueryDesc *) palloc(sizeof(QueryDesc));    qd->operation = plannedstmt->commandType;    /* operation */    qd->plannedstmt = plannedstmt;        /* plan */    qd->utilitystmt = plannedstmt->utilityStmt; /* in case DECLARE CURSOR */    qd->sourceText = sourceText;    /* query text */    qd->snapshot = RegisterSnapshot(snapshot);    /* snapshot */    /* RI check snapshot */    qd->crosscheck_snapshot = RegisterSnapshot(crosscheck_snapshot);    qd->dest = dest;            /* output dest */    qd->params = params;        /* parameter values passed into query */    qd->instrument_options = instrument_options;        /* instrumentation                                                         * wanted? */    /* null these fields until set by ExecutorStart */    qd->tupDesc = NULL;    qd->estate = NULL;    qd->planstate = NULL;    qd->totaltime = NULL;    return qd;}

只是准备好了数据而已。

再分析之下的一段:

/*                 * Call ExecutorStart to prepare the plan for execution                 */                ExecutorStart(queryDesc, myeflags);

其定义为:

/* ---------------------------------------------------------------- *        ExecutorStart * *        This routine must be called at the beginning of any execution of any *        query plan * * Takes a QueryDesc previously created by CreateQueryDesc (which is separate * only because some places use QueryDescs for utility commands).  The tupDesc * field of the QueryDesc is filled in to describe the tuples that will be * returned, and the internal fields (estate and planstate) are set up. * * eflags contains flag bits as described in executor.h. * * NB: the CurrentMemoryContext when this is called will become the parent * of the per-query context used for this Executor invocation. * * We provide a function hook variable that lets loadable plugins * get control when ExecutorStart is called.  Such a plugin would * normally call standard_ExecutorStart(). * * ---------------------------------------------------------------- */voidExecutorStart(QueryDesc *queryDesc, int eflags){    if (ExecutorStart_hook)        (*ExecutorStart_hook) (queryDesc, eflags);    else        standard_ExecutorStart(queryDesc, eflags);}voidstandard_ExecutorStart(QueryDesc *queryDesc, int eflags){    ...    /*     * If non-read-only query, set the command ID to mark output tuples with     */    switch (queryDesc->operation)    {        case CMD_SELECT:            /*             * SELECT FOR UPDATE/SHARE and modifying CTEs need to mark tuples             */            if (queryDesc->plannedstmt->rowMarks != NIL ||                queryDesc->plannedstmt->hasModifyingCTE)                estate->es_output_cid = GetCurrentCommandId(true);            /*             * A SELECT without modifying CTEs can't possibly queue triggers,             * so force skip-triggers mode. This is just a marginal efficiency             * hack, since AfterTriggerBeginQuery/AfterTriggerEndQuery aren't             * all that expensive, but we might as well do it.             */            if (!queryDesc->plannedstmt->hasModifyingCTE)                eflags |= EXEC_FLAG_SKIP_TRIGGERS;            break;        case CMD_INSERT:        case CMD_DELETE:        case CMD_UPDATE:            estate->es_output_cid = GetCurrentCommandId(true);            break;        default:            elog(ERROR, "unrecognized operation code: %d",                 (int) queryDesc->operation);            break;    }    ...}

转载地址:http://ojwzo.baihongyu.com/

你可能感兴趣的文章
Servlet 技术全总结 (已完成,不定期增加内容)
查看>>
[JSOI2008]星球大战starwar BZOJ1015
查看>>
RS232、RS485、RS422、UART、SCI、SPI、IIC、USB、TCPIP、CAN、LIN
查看>>
CountDownLatch与thread-join()的区别
查看>>
linux下MySQL安装登录及操作
查看>>
二项队列
查看>>
Spark:读取文本文件存为hive表最佳实践
查看>>
Nginx
查看>>
洛谷P4069 [SDOI2016]游戏(李超线段树)
查看>>
如何做好售后管理之售后返修品管理
查看>>
centos 7 部署LDAP服务
查看>>
揭秘马云帝国内幕:马云的野心有多大
查看>>
topcoder srm 680 div1
查看>>
算法专题(1)-信息学基本解题流程!
查看>>
模拟文件系统
查看>>
使用SSH连接Windows10 Ubuntu (WSL),Pycharm
查看>>
poj2155
查看>>
CSS动画之转换模块
查看>>
swift - UITextField 的用法
查看>>
检索和关闭游标+检索游标+关闭游标
查看>>