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

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

回到上一个层面,继续看 PortalStart的处理:

voidPortalStart(Portal portal, ParamListInfo params,            int eflags, bool use_active_snapshot){    ...    PG_TRY();    {        ...        /*         * Determine the portal execution strategy         */        portal->strategy = ChoosePortalStrategy(portal->stmts);        /*         * Fire her up according to the strategy         */        switch (portal->strategy)        {            case PORTAL_ONE_SELECT:                /* Must set snapshot before starting executor. */                if (use_active_snapshot)                    PushActiveSnapshot(GetActiveSnapshot());                else                    PushActiveSnapshot(GetTransactionSnapshot());                /*                 * 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);                /*                 * If it's a scrollable cursor, executor needs to support                 * REWIND and backwards scan, as well as whatever the caller                 * might've asked for.                 */                if (portal->cursorOptions & CURSOR_OPT_SCROLL)                    myeflags = eflags | EXEC_FLAG_REWIND | EXEC_FLAG_BACKWARD;                else                    myeflags = eflags;                /*                 * Call ExecutorStart to prepare the plan for execution                 */                ExecutorStart(queryDesc, myeflags);                /*                 * This tells PortalCleanup to shut down the executor                 */                portal->queryDesc = queryDesc;                /*                 * Remember tuple descriptor (computed by ExecutorStart)                 */                portal->tupDesc = queryDesc->tupDesc;                /*                 * Reset cursor position data to "start of query"                 */                portal->atStart = true;                portal->atEnd = false;    /* allow fetches */                portal->portalPos = 0;                portal->posOverflow = false;                PopActiveSnapshot();                break;            case PORTAL_ONE_RETURNING:            case PORTAL_ONE_MOD_WITH:                ...                break;            case PORTAL_UTIL_SELECT:                ...                break;            case PORTAL_MULTI_QUERY:                /* Need do nothing now */                portal->tupDesc = NULL;                break;        }    }    PG_CATCH();    {        ...        PG_RE_THROW();    }    PG_END_TRY();    ...}

由之前的分析可以知道,满足  case PORTAL_ONE_SELECT 的条件,下面再看

use_active_snapshot,回溯上层:

static voidexec_simple_query(const char *query_string){    ...    foreach(parsetree_item, parsetree_list)    {        ...        /*         * Set up a snapshot if parse analysis/planning will need one.         */        if (analyze_requires_snapshot(parsetree))        {            PushActiveSnapshot(GetTransactionSnapshot());            snapshot_set = true;        }        ...        PortalStart(portal, NULL, 0, snapshot_set);    }    ...}

可见,snapshot 还是要搞的。简言之,snapshot 是为了MVCC控制:

typedef struct SnapshotData{    SnapshotSatisfiesFunc satisfies;    /* tuple test function */    /*     * The remaining fields are used only for MVCC snapshots, and are normally     * just zeroes in special snapshots.  (But xmin and xmax are used     * specially by HeapTupleSatisfiesDirty.)     *     * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see     * the effects of all older XIDs except those listed in the snapshot. xmin     * is stored as an optimization to avoid needing to search the XID arrays     * for most tuples.     */    TransactionId xmin;            /* all XID < xmin are visible to me */    TransactionId xmax;            /* all XID >= xmax are invisible to me */    TransactionId *xip;            /* array of xact IDs in progress */    uint32        xcnt;            /* # of xact ids in xip[] */    /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */    int32        subxcnt;        /* # of xact ids in subxip[] */    TransactionId *subxip;        /* array of subxact IDs in progress */    bool        suboverflowed;    /* has the subxip array overflowed? */    bool        takenDuringRecovery;    /* recovery-shaped snapshot? */    bool        copied;            /* false if it's a static snapshot */    /*     * note: all ids in subxip[] are >= xmin, but we don't bother filtering     * out any that are >= xmax     */    CommandId    curcid;            /* in my xact, CID < curcid are visible */    uint32        active_count;    /* refcount on ActiveSnapshot stack */    uint32        regd_count;        /* refcount on RegisteredSnapshotList */} SnapshotData;

 

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

你可能感兴趣的文章
QuestMobile:抖音快手双巨头并进 短视频时长超越在线视频
查看>>
2019年春运首日 河北实现“空地一体”立体化救援
查看>>
蚂蚁金服mPaaS 3.0发布 助力客户智能化构建超级App生态
查看>>
Mongodb数据库误删后的恢复
查看>>
整理些PHP的学习方向资料
查看>>
关于vue开发的常见问题
查看>>
IT,互联网,科技,技术博客网站推荐
查看>>
如何实现全屏遮罩(附Vue.extend和el-message源码学习)
查看>>
你或许不知道Vue的这些小技巧
查看>>
Promise源码学习(1)
查看>>
[项目推荐] Corcel 让你在 WordPress 中使用 Laravel
查看>>
阿里:千亿交易背后的0故障发布
查看>>
Node+express+mongoose 基础笔记
查看>>
利用angular4和nodejs-express构建一个简单的网站(十)—好友模块
查看>>
极光大数据告诉你,程序员们都在"愁"些啥?
查看>>
从Hash到散列表到HashMap
查看>>
前端基础知识学习记录(三)
查看>>
原型链类原理
查看>>
我的订单
查看>>
2017文章总结
查看>>