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

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

在定义了Portal之后,需要运行:PortalStart,它主要的任务是明确执行策略,然后再执行 ExecutorStart:

代码太长,进行缩略:

voidPortalStart(Portal portal, ParamListInfo params,            int eflags, bool use_active_snapshot){    ...    PG_TRY();    {        ActivePortal = portal;        CurrentResourceOwner = portal->resowner;        PortalContext = PortalGetHeapMemory(portal);        oldContext = MemoryContextSwitchTo(PortalGetHeapMemory(portal));        /* Must remember portal param list, if any */        portal->portalParams = params;        /*         * Determine the portal execution strategy         */        portal->strategy = ChoosePortalStrategy(portal->stmts);        /*         * Fire her up according to the strategy         */        switch (portal->strategy)        {            case PORTAL_ONE_SELECT:          ...break;            case PORTAL_ONE_RETURNING:            case PORTAL_ONE_MOD_WITH:          ...break;            case PORTAL_UTIL_SELECT:          ...break;            case PORTAL_MULTI_QUERY:          ...break;        }    }    PG_CATCH();    {     ...        PG_RE_THROW();    }    PG_END_TRY();    MemoryContextSwitchTo(oldContext);    ActivePortal = saveActivePortal;    CurrentResourceOwner = saveResourceOwner;    PortalContext = savePortalContext;    portal->status = PORTAL_READY;}

我们发送如 select * from tab01; 这样的查询时,得到的Strategy是: PORTAL_ONE_SELECT

在得知Strategy 为  PORTAL_ONE_SELECT 之后,作了哪些事情呢:

1 case PORTAL_ONE_SELECT: 2                 /* Must set snapshot before starting executor. */ 3                 if (use_active_snapshot) 4                     PushActiveSnapshot(GetActiveSnapshot()); 5                 else 6                     PushActiveSnapshot(GetTransactionSnapshot()); 7  8                 /* 9                  * Create QueryDesc in portal's context; for the moment, set10                  * the destination to DestNone.11                  */12                 queryDesc = CreateQueryDesc((PlannedStmt *) linitial(portal->stmts),13                                             portal->sourceText,14                                             GetActiveSnapshot(),15                                             InvalidSnapshot,16                                             None_Receiver,17                                             params,18                                             0);19 20                 /*21                  * If it's a scrollable cursor, executor needs to support22                  * REWIND and backwards scan, as well as whatever the caller23                  * might've asked for.24                  */25                 if (portal->cursorOptions & CURSOR_OPT_SCROLL)26                     myeflags = eflags | EXEC_FLAG_REWIND | EXEC_FLAG_BACKWARD;27                 else28                     myeflags = eflags;29 30                 /*31                  * Call ExecutorStart to prepare the plan for execution32                  */33                 ExecutorStart(queryDesc, myeflags);34 35                 /*36                  * This tells PortalCleanup to shut down the executor37                  */38                 portal->queryDesc = queryDesc;39 40                 /*41                  * Remember tuple descriptor (computed by ExecutorStart)42                  */43                 portal->tupDesc = queryDesc->tupDesc;44 45                 /*46                  * Reset cursor position data to "start of query"47                  */48                 portal->atStart = true;49                 portal->atEnd = false;    /* allow fetches */50                 portal->portalPos = 0;51                 portal->posOverflow = false;52 53                 PopActiveSnapshot();54                 break;

对于 select * from tab01; 这样的查询, myeflags 为0。这里很重要的,就是执行了 ExecutorStart。

这样,为执行做好了准备。

转载于:https://www.cnblogs.com/gaojian/archive/2013/05/22/3092622.html

你可能感兴趣的文章
Zabbix 3.0编译安装
查看>>
json介绍及简单示例
查看>>
h.264 率失真优化
查看>>
【转】拓扑排序入门
查看>>
Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别
查看>>
How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7
查看>>
搭建LNAMP环境(三)- 源码安装Apache2.4
查看>>
linux --> fork()详解
查看>>
Spring注解 开发
查看>>
#!/bin/bash(转)
查看>>
BZOJ4589 Hard Nim(博弈+FWT)
查看>>
hdu 2473 Junk-Mail Filter 并查集删点,模板题
查看>>
【Maps】【搜狗】
查看>>
Linux命令详解-whatis
查看>>
分组求和
查看>>
eclipse 忽略 target 设置
查看>>
Reptile:requests代理IP
查看>>
HTML5应用缓存与Web Workers
查看>>
【并行计算-CUDA开发】英伟达硬件解码器分析
查看>>
Axure原型制作规范
查看>>