Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Which operators are used to implement functions in PostgreSQL implicit type conversion

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "which operators are used in PostgreSQL implicit type conversion to achieve functions". The explanation in this article is simple and clear and easy to learn and understand. Please follow Xiaobian's train of thought to study and learn which operators are used to achieve functions in PostgreSQL implicit type conversion.

I. data structure

FuncCandidateList

This structure stores a linked list of all possible selected functions or operators retrieved.

/ * * 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. * this structure stores a linked list of all possible selected functions or operators retrieved. * each function / operator is uniquely determined by OID and parameter type. * the linked list is tailored through the type resolution rules integrated into the analyzer (but not implemented here). For more information, please see the FuncnameGetCandidates function. * / typedef struct _ FuncCandidateList {struct _ FuncCandidateList * next; / / for namespace search the number of parameters using int pathpos; / * for internal use of namespace lookup * / OID Oid oid; / * the function or operator's OID * / number of parameters int nargs; / * number of arg types returned * / variadic array int nvargs / * number of args to become variadic array * / / default number of parameters int ndargs; / * number of defaulted args * / / Parameter location index int * argnumbers; / * args' positional indexes, if named call * / / Parameter type Oid args [flex _ ARRAY_MEMBER]; / * arg types * /} * FuncCandidateList; II, source code interpretation

Func_match_argtypes

Given the list of candidate functions (correct function name / parameter number matching) and the input data type OIDs array, a linked list of candidate functions that can actually match the input data type (exactly matching or convertible) is generated, and then the number of candidate functions that meet the criteria is generated.

/ * 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. * given the list of candidate functions (the correct function name / number of parameters match) and the input data type OIDs array, * generate a linked list of candidate functions that can actually match the input data type (exact match or convertible), and then the number of qualified candidate functions * * Note that can_coerce_type will assume that UNKNOWN inputs are coercible to * anything, so candidates will not be eliminated on that basis. The can_coerce_type function assumes that the UNKNOWN input can be converted to any type. * * 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. * Note: if only a matching candidate function is found, modifying the input list structure is OK. If there is no match, the linked list remains unchanged. * / intfunc_match_argtypes (int nargs, Oid * input_typeids, FuncCandidateList raw_candidates, FuncCandidateList * candidates) / * return value * / {FuncCandidateList current_candidate;// current candidate FuncCandidateList next_candidate;// next candidate int ncandidates = 0; * candidates = NULL; for (current_candidate = raw_candidates; current_candidate! = NULL Current_candidate = next_candidate) / / traversal candidate function {next_candidate = current_candidate- > next; if (can_coerce_type (nargs, input_typeids, current_candidate- > args, COERCION_IMPLICIT)) / / matching input data type (exact match or convertible) {current_candidate- > next = * candidates * candidates = current_candidate; ncandidates++;}} return ncandidates;} / * func_match_argtypes () * /

In pg_operator, the input parameter type matches or can be converted with the parameter type of operator, and can be entered into the candidate function linked list.

Third, follow-up analysis

Test script

Create cast (integer as text) with inout as implicit;select id | |'X' from t_cast

Tracking and analysis

(gdb) cContinuing.Breakpoint 2, oper_select_candidate (nargs=2, input_typeids=0x7ffeb9cca190, candidates=0x13db8a0, operOid=0x7ffeb9cca22c) at parse_oper.c:330330 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-, next- = 0, next- = 2, = 0 Ndargs = 0, argnumbers = 0x0, args = 0x13db808} (gdb) p * candidates- > next- > next$6 = {next = 0x13db780, pathpos = 0, oid = 349, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db7d8} (gdb) p * candidates- > next- > next$7 = {next = 0x13db750, pathpos = 0, oid = 375,nargs = 2, nargs = 0, nvargs = 0, nvargs = ndargs Args = 0x13db7a8} (gdb) p * candidates- > next- > next$8 = {next = 0x13db720, pathpos = 0, oid = 1797, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db778} (gdb) p * candidates- > next- > next$9 = {next = 0x13db6f0, pathpos = 0, oid = 2779, oid = 2, nargs = 0, nargs = 0, nargs = nargs Args = 0x13db748} (gdb) p * candidates- > next- > next$10 = {next = 0x13db6c0, pathpos = 0, oid = 654, nargs = 2, nvargs = 0, ndargs = 0, argnumbers = 0x0, args = 0x13db718} (gdb) p * candidates- > next- > next$11 = {next = next, next = 0, 0x0 = 2018, 0x0 = 2, next = 0, 0x0 = 0, 0x0 = Args = 0x13db6e8} (gdb) p * candidates- > next- > nextCannot access memory at address 0x0 (gdb) n334 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- > nextCannot access memory at address 0x0 (gdb) Thank you for your reading The above is the content of "which operators are used to implement functions in PostgreSQL implicit type conversion". After the study of this article, I believe you have a deeper understanding of the problem of which operators are used in PostgreSQL implicit type conversion, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report