這篇文章主要講解了“PostgreSQL隱式類型轉(zhuǎn)換中使用哪些操作符實(shí)現(xiàn)函數(shù)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“PostgreSQL隱式類型轉(zhuǎn)換中使用哪些操作符實(shí)現(xiàn)函數(shù)”吧!
創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的昌邑網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
FuncCandidateList
該結(jié)構(gòu)體存儲(chǔ)檢索得到的所有可能選中的函數(shù)或操作符鏈表.
/* * This structure holds a list of possible functions or operators * found by namespace lookup. Each function/operator is identified * by OID and by argument types; the list must be pruned by type * resolution rules that are embodied in the parser, not here. * See FuncnameGetCandidates's comments for more info. * 該結(jié)構(gòu)體存儲(chǔ)檢索得到的所有可能選中的函數(shù)或操作符鏈表. * 每一個(gè)函數(shù)/操作符通過OID和參數(shù)類型唯一確定, * 通過集成到分析器中的type resolution rules來確定裁剪該鏈表(但不是在這里實(shí)現(xiàn)) * 詳細(xì)可參考FuncnameGetCandidates函數(shù). */ typedef struct _FuncCandidateList { struct _FuncCandidateList *next; //用于namespace檢索內(nèi)部使用 int pathpos; /* for internal use of namespace lookup */ //OID Oid oid; /* the function or operator's OID */ //參數(shù)個(gè)數(shù) int nargs; /* number of arg types returned */ //variadic array的參數(shù)個(gè)數(shù) int nvargs; /* number of args to become variadic array */ //默認(rèn)參數(shù)個(gè)數(shù) int ndargs; /* number of defaulted args */ //參數(shù)位置索引 int *argnumbers; /* args' positional indexes, if named call */ //參數(shù)類型 Oid args[FLEXIBLE_ARRAY_MEMBER]; /* arg types */ } *FuncCandidateList;
func_match_argtypes
給定候選函數(shù)列表(正確的函數(shù)名稱/參數(shù)個(gè)數(shù)匹配)和輸入數(shù)據(jù)類型OIDs數(shù)組,生成實(shí)際可匹配輸入數(shù)據(jù)類型(完全匹配或可轉(zhuǎn)換)的候選函數(shù)鏈表,然后符合條件的候選函數(shù)個(gè)數(shù).
/* func_match_argtypes() * * Given a list of candidate functions (having the right name and number * of arguments) and an array of input datatype OIDs, produce a shortlist of * those candidates that actually accept the input datatypes (either exactly * or by coercion), and return the number of such candidates. * 給定候選函數(shù)列表(正確的函數(shù)名稱/參數(shù)個(gè)數(shù)匹配)和輸入數(shù)據(jù)類型OIDs數(shù)組, * 生成實(shí)際可匹配輸入數(shù)據(jù)類型(完全匹配或可轉(zhuǎn)換)的候選函數(shù)鏈表,然后符合條件的候選函數(shù)個(gè)數(shù) * * Note that can_coerce_type will assume that UNKNOWN inputs are coercible to * anything, so candidates will not be eliminated on that basis. * can_coerce_type函數(shù)假定UNKNOWN輸入可轉(zhuǎn)換為任意類型. * * NB: okay to modify input list structure, as long as we find at least * one match. If no match at all, the list must remain unmodified. * 注意:如果只是找到一個(gè)匹配的候選函數(shù),修改輸入鏈表結(jié)構(gòu)是OK的.如無匹配,則鏈表保持不變. */ int func_match_argtypes(int nargs, Oid *input_typeids, FuncCandidateList raw_candidates, FuncCandidateList *candidates) /* return value */ { FuncCandidateList current_candidate;//當(dāng)前候選 FuncCandidateList next_candidate;//下一候選 int ncandidates = 0; *candidates = NULL; for (current_candidate = raw_candidates; current_candidate != NULL; current_candidate = next_candidate)//遍歷候選函數(shù) { next_candidate = current_candidate->next; if (can_coerce_type(nargs, input_typeids, current_candidate->args, COERCION_IMPLICIT))//可匹配輸入數(shù)據(jù)類型(完全匹配或可轉(zhuǎn)換) { current_candidate->next = *candidates; *candidates = current_candidate; ncandidates++; } } return ncandidates; } /* func_match_argtypes() */
在pg_operator中,輸入?yún)?shù)類型與operator的參數(shù)類型匹配或可轉(zhuǎn)換,可進(jìn)入候選函數(shù)鏈表.
測(cè)試腳本
create cast(integer as text) with inout as implicit; select id||'X' from t_cast;
跟蹤分析
(gdb) c Continuing. Breakpoint 2, oper_select_candidate (nargs=2, input_typeids=0x7ffeb9cca190, candidates=0x13db8a0, operOid=0x7ffeb9cca22c) at parse_oper.c:330 330 ncandidates = func_match_argtypes(nargs, input_typeids, (gdb) p *candidates $1 = {next = 0x13db870, pathpos = 0, oid = 3284, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db8c8} (gdb) p *candidates->next $2 = {next = 0x13db840, pathpos = 0, oid = 3681, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db898} (gdb) p *candidates->next->next $3 = {next = 0x13db810, pathpos = 0, oid = 3633, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db868} (gdb) p *candidates->next->next->next $4 = {next = 0x13db7e0, pathpos = 0, oid = 2780, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db838} (gdb) p *candidates->next->next->next->next $5 = {next = 0x13db7b0, pathpos = 0, oid = 374, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db808} (gdb) p *candidates->next->next->next->next->next $6 = {next = 0x13db780, pathpos = 0, oid = 349, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db7d8} (gdb) p *candidates->next->next->next->next->next->next $7 = {next = 0x13db750, pathpos = 0, oid = 375, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db7a8} (gdb) p *candidates->next->next->next->next->next->next->next $8 = {next = 0x13db720, pathpos = 0, oid = 1797, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db778} (gdb) p *candidates->next->next->next->next->next->next->next->next $9 = {next = 0x13db6f0, pathpos = 0, oid = 2779, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db748} (gdb) p *candidates->next->next->next->next->next->next->next->next->next $10 = {next = 0x13db6c0, pathpos = 0, oid = 654, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db718} (gdb) p *candidates->next->next->next->next->next->next->next->next->next->next $11 = {next = 0x0, pathpos = 0, oid = 2018, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db6e8} (gdb) p *candidates->next->next->next->next->next->next->next->next->next->next->next Cannot access memory at address 0x0 (gdb) n 334 if (ncandidates == 0) (gdb) 339 if (ncandidates == 1) (gdb) 349 candidates = func_select_candidate(nargs, input_typeids, candidates); (gdb) p ncandidates $12 = 2 (gdb) p *candidates $13 = {next = 0x13db810, pathpos = 0, oid = 374, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db808} (gdb) p *candidates->next $14 = {next = 0x0, pathpos = 0, oid = 2780, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db838} (gdb) p *candidates->next->next Cannot access memory at address 0x0 (gdb)
感謝各位的閱讀,以上就是“PostgreSQL隱式類型轉(zhuǎn)換中使用哪些操作符實(shí)現(xiàn)函數(shù)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)PostgreSQL隱式類型轉(zhuǎn)換中使用哪些操作符實(shí)現(xiàn)函數(shù)這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!