這篇文章主要講解了“PostgreSQL中ExecProcNode和ExecProcNodeFirst函數(shù)的實現(xiàn)邏輯是什么”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“PostgreSQL中ExecProcNode和ExecProcNodeFirst函數(shù)的實現(xiàn)邏輯是什么”吧!
創(chuàng)新互聯(lián)網(wǎng)站建設提供從項目策劃、軟件開發(fā),軟件安全維護、網(wǎng)站優(yōu)化(SEO)、網(wǎng)站分析、效果評估等整套的建站服務,主營業(yè)務為成都網(wǎng)站設計、網(wǎng)站建設,成都app軟件開發(fā)以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。創(chuàng)新互聯(lián)深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
ExecProcNode/ExecProcNodeFirst函數(shù)使用的數(shù)據(jù)結(jié)構(gòu)、宏定義以及依賴的函數(shù)等。
數(shù)據(jù)結(jié)構(gòu)/宏定義
1、ExecProcNodeMtd
ExecProcNodeMtd是一個函數(shù)指針類型,指向的函數(shù)輸入?yún)?shù)是PlanState結(jié)構(gòu)體指針,輸出參數(shù)是TupleTableSlot 結(jié)構(gòu)體指針
/* ---------------- * ExecProcNodeMtd * * This is the method called by ExecProcNode to return the next tuple * from an executor node. It returns NULL, or an empty TupleTableSlot, * if no more tuples are available. * ---------------- */ typedef TupleTableSlot *(*ExecProcNodeMtd) (struct PlanState *pstate);
依賴的函數(shù)
1、check_stack_depth
//檢查stack的深度,如超出系統(tǒng)限制,則主動報錯 /* * check_stack_depth/stack_is_too_deep: check for excessively deep recursion * * This should be called someplace in any recursive routine that might possibly * recurse deep enough to overflow the stack. Most Unixen treat stack * overflow as an unrecoverable SIGSEGV, so we want to error out ourselves * before hitting the hardware limit. * * check_stack_depth() just throws an error summarily. stack_is_too_deep() * can be used by code that wants to handle the error condition itself. */ void check_stack_depth(void) { if (stack_is_too_deep()) { ereport(ERROR, (errcode(ERRCODE_STATEMENT_TOO_COMPLEX), errmsg("stack depth limit exceeded"), errhint("Increase the configuration parameter \"max_stack_depth\" (currently %dkB), " "after ensuring the platform's stack depth limit is adequate.", max_stack_depth))); } } bool stack_is_too_deep(void) { char stack_top_loc; long stack_depth; /* * Compute distance from reference point to my local variables */ stack_depth = (long) (stack_base_ptr - &stack_top_loc); /* * Take abs value, since stacks grow up on some machines, down on others */ if (stack_depth < 0) stack_depth = -stack_depth; /* * Trouble? * * The test on stack_base_ptr prevents us from erroring out if called * during process setup or in a non-backend process. Logically it should * be done first, but putting it here avoids wasting cycles during normal * cases. */ if (stack_depth > max_stack_depth_bytes && stack_base_ptr != NULL) return true; /* * On IA64 there is a separate "register" stack that requires its own * independent check. For this, we have to measure the change in the * "BSP" pointer from PostgresMain to here. Logic is just as above, * except that we know IA64's register stack grows up. * * Note we assume that the same max_stack_depth applies to both stacks. */ #if defined(__ia64__) || defined(__ia64) stack_depth = (long) (ia64_get_bsp() - register_stack_base_ptr); if (stack_depth > max_stack_depth_bytes && register_stack_base_ptr != NULL) return true; #endif /* IA64 */ return false; }
2、ExecProcNodeInstr
/* * ExecProcNode wrapper that performs instrumentation calls. By keeping * this a separate function, we avoid overhead in the normal case where * no instrumentation is wanted. */ static TupleTableSlot * ExecProcNodeInstr(PlanState *node) { TupleTableSlot *result; InstrStartNode(node->instrument); result = node->ExecProcNodeReal(node); InstrStopNode(node->instrument, TupIsNull(result) ? 0.0 : 1.0); return result; }
1、ExecProcNode
//外部調(diào)用者可通過改變node實現(xiàn)遍歷 /* ---------------------------------------------------------------- * ExecProcNode * * Execute the given node to return a(nother) tuple. * ---------------------------------------------------------------- */ #ifndef FRONTEND static inline TupleTableSlot * ExecProcNode(PlanState *node) { if (node->chgParam != NULL) /* something changed? */ ExecReScan(node); /* let ReScan handle this */ return node->ExecProcNode(node); } #endif
2、ExecProcNodeFirst
/* * ExecProcNode wrapper that performs some one-time checks, before calling * the relevant node method (possibly via an instrumentation wrapper). */ /* 輸入: node-PlanState指針 輸出: 存儲Tuple的Slot */ static TupleTableSlot * ExecProcNodeFirst(PlanState *node) { /* * Perform stack depth check during the first execution of the node. We * only do so the first time round because it turns out to not be cheap on * some common architectures (eg. x86). This relies on the assumption * that ExecProcNode calls for a given plan node will always be made at * roughly the same stack depth. */ //檢查Stack是否超深 check_stack_depth(); /* * If instrumentation is required, change the wrapper to one that just * does instrumentation. Otherwise we can dispense with all wrappers and * have ExecProcNode() directly call the relevant function from now on. */ //如果instrument(TODO) if (node->instrument) node->ExecProcNode = ExecProcNodeInstr; else node->ExecProcNode = node->ExecProcNodeReal; //執(zhí)行該Node的處理過程 return node->ExecProcNode(node); }
插入測試數(shù)據(jù):
testdb=# -- 獲取pid testdb=# select pg_backend_pid(); pg_backend_pid ---------------- 2835 (1 row) testdb=# -- 插入1行 testdb=# insert into t_insert values(14,'ExecProcNodeFirst','ExecProcNodeFirst','ExecProcNodeFirst'); (掛起)
啟動gdb分析:
[root@localhost ~]# gdb -p 2835 GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-100.el7 Copyright (C) 2013 Free Software Foundation, Inc. ... (gdb) b ExecProcNodeFirst Breakpoint 1 at 0x69a797: file execProcnode.c, line 433. (gdb) c Continuing. Breakpoint 1, ExecProcNodeFirst (node=0x2cca790) at execProcnode.c:433 433 check_stack_depth(); #查看輸入?yún)?shù) (gdb) p *node $1 = {type = T_ModifyTableState, plan = 0x2c1d028, state = 0x2cca440, ExecProcNode = 0x69a78b <ExecProcNodeFirst>, ExecProcNodeReal = 0x6c2485 <ExecModifyTable>, instrument = 0x0, worker_instrument = 0x0, qual = 0x0, lefttree = 0x0, righttree = 0x0, initPlan = 0x0, subPlan = 0x0, chgParam = 0x0, ps_ResultTupleSlot = 0x2ccb6a0, ps_ExprContext = 0x0, ps_ProjInfo = 0x0, scandesc = 0x0} #ExecProcNode 實際對應的函數(shù)是ExecProcNodeFirst #ExecProcNodeReal 實際對應的函數(shù)是ExecModifyTable(上一章節(jié)已粗略解析) (gdb) next 440 if (node->instrument) (gdb) #實際調(diào)用ExecModifyTable函數(shù)(這個函數(shù)由更高層的調(diào)用函數(shù)植入) 443 node->ExecProcNode = node->ExecProcNodeReal; (gdb) 445 return node->ExecProcNode(node); (gdb) next #第二次調(diào)用(TODO) Breakpoint 1, ExecProcNodeFirst (node=0x2ccac80) at execProcnode.c:433 433 check_stack_depth(); (gdb) next 440 if (node->instrument) (gdb) next 443 node->ExecProcNode = node->ExecProcNodeReal; (gdb) next 445 return node->ExecProcNode(node); (gdb) next 446 } (gdb) next ExecProcNode (node=0x2ccac80) at ../../../src/include/executor/executor.h:238 238 } #第二次調(diào)用的參數(shù) (gdb) p *node $2 = {type = T_ResultState, plan = 0x2cd0488, state = 0x2cca440, ExecProcNode = 0x6c5094 <ExecResult>, ExecProcNodeReal = 0x6c5094 <ExecResult>, instrument = 0x0, worker_instrument = 0x0, qual = 0x0, lefttree = 0x0, righttree = 0x0, initPlan = 0x0, subPlan = 0x0, chgParam = 0x0, ps_ResultTupleSlot = 0x2ccad90, ps_ExprContext = 0x2ccab30, ps_ProjInfo = 0x2ccabc0, scandesc = 0x0} #ExecProcNode對應的實際函數(shù)是ExecResult (gdb)
感謝各位的閱讀,以上就是“PostgreSQL中ExecProcNode和ExecProcNodeFirst函數(shù)的實現(xiàn)邏輯是什么”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對PostgreSQL中ExecProcNode和ExecProcNodeFirst函數(shù)的實現(xiàn)邏輯是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
分享文章:PostgreSQL中ExecProcNode和ExecProcNodeFirst函數(shù)的實現(xiàn)邏輯是什么
標題路徑:http://vcdvsql.cn/article30/iijsso.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、微信小程序、電子商務、網(wǎng)站設計公司、移動網(wǎng)站建設、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)