PostgreSQL在何处处理 sql查询之三
2013-05-22 10:30
483 查看
前面已经说过,在 exec_simple_query中,完成sql文的执行。
具体地说,是要构造portal,然后运行 PortalStart , PortalRun...
下面就先看看 portal如何构造:
在 exec_simple_query中,有这么一段:
具体的CreatePortal,是如何作的(portalmem.c):
由于调用 CreatePortal 的时候,传递name是空值,所以 portal = GetPortalByName(name); 返回NULL。
通过 MemoryContextAllocZero 建立一个初始的portal,然后再赋予各种值,最后压入哈希表中。此时name依然为空。
具体地说,是要构造portal,然后运行 PortalStart , PortalRun...
下面就先看看 portal如何构造:
在 exec_simple_query中,有这么一段:
/* * Create unnamed portal to run the query or queries in. If there * already is one, silently drop it. */ portal = CreatePortal("", true, true); /* Don't display the portal in pg_cursors */ portal->visible = false;
具体的CreatePortal,是如何作的(portalmem.c):
/* * CreatePortal * Returns a new portal given a name. * * allowDup: if true, automatically drop any pre-existing portal of the * same name (if false, an error is raised). * * dupSilent: if true, don't even emit a WARNING. */ Portal CreatePortal(const char *name, bool allowDup, bool dupSilent) { Portal portal; AssertArg(PointerIsValid(name)); portal = GetPortalByName(name); if (PortalIsValid(portal)) { if (!allowDup) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_CURSOR), errmsg("cursor \"%s\" already exists", name))); if (!dupSilent) ereport(WARNING, (errcode(ERRCODE_DUPLICATE_CURSOR), errmsg("closing existing cursor \"%s\"", name))); PortalDrop(portal, false); } /* make new portal structure */ portal = (Portal) MemoryContextAllocZero(PortalMemory, sizeof *portal); /* initialize portal heap context; typically it won't store much */ portal->heap = AllocSetContextCreate(PortalMemory, "PortalHeapMemory", ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE); /* create a resource owner for the portal */ portal->resowner = ResourceOwnerCreate(CurTransactionResourceOwner, "Portal"); /* initialize portal fields that don't start off zero */ portal->status = PORTAL_NEW; portal->cleanup = PortalCleanup; portal->createSubid = GetCurrentSubTransactionId(); portal->strategy = PORTAL_MULTI_QUERY; portal->cursorOptions = CURSOR_OPT_NO_SCROLL; portal->atStart = true; portal->atEnd = true; /* disallow fetches until query is set */ portal->visible = true; portal->creation_time = GetCurrentStatementStartTimestamp(); /* put portal in table (sets portal->name) */ PortalHashTableInsert(portal, name); return portal; }
由于调用 CreatePortal 的时候,传递name是空值,所以 portal = GetPortalByName(name); 返回NULL。
通过 MemoryContextAllocZero 建立一个初始的portal,然后再赋予各种值,最后压入哈希表中。此时name依然为空。
相关文章推荐
- PostgreSQL在何处处理 sql查询之四
- PostgreSQL在何处处理 sql查询之四十九
- PostgreSQL在何处处理 sql查询之五十八
- PostgreSQL在何处处理 sql查询之十七
- PostgreSQL在何处处理 sql查询之二十二
- PostgreSQL在何处处理 sql查询之二十三
- PostgreSQL在何处处理 sql查询之三十七
- PostgreSQL在何处处理 sql查询之六十六
- PostgreSQL在何处处理 sql查询之七
- PostgreSQL在何处处理 sql查询之二十七
- PostgreSQL在何处处理 sql查询之二十九
- PostgreSQL在何处处理 sql查询之二十
- PostgreSQL在何处处理 sql查询之二十一
- PostgreSQL在何处处理 sql查询之四十八
- PostgreSQL在何处处理 sql查询之十九
- PostgreSQL在何处处理 sql查询之三十四
- PostgreSQL在何处处理 sql查询之五十
- PostgreSQL在何处处理 sql查询之六十三
- PostgreSQL在何处处理 sql查询之九
- PostgreSQL在何处处理 sql查询之十四