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

How to use PostgreSQL's ExprEvalStep

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

< 3; 设置断点,跟踪 (gdb) b ExecInitFuncBreakpoint 1 at 0x6c8c33: file execExpr.c, line 2160.(gdb) cContinuing.Breakpoint 1, ExecInitFunc (scratch=0x7ffd862de730, node=0x2e675d8, args=0x2e67520, funcid=177, inputcollid=0, state=0x2f228c0) at execExpr.c:21602160 int nargs = list_length(args);(gdb) bt#0 ExecInitFunc (scratch=0x7ffd862de730, node=0x2e675d8, args=0x2e67520, funcid=177, inputcollid=0, state=0x2f228c0) at execExpr.c:2160#1 0x00000000006c6200 in ExecInitExprRec (node=0x2e675d8, state=0x2f228c0, resv=0x2f228c8, resnull=0x2f228c5) at execExpr.c:893#2 0x00000000006c55bc in ExecBuildProjectionInfo (targetList=0x2f2a348, econtext=0x2f223a8, slot=0x2f22820, parent=0x2f22190, inputDesc=0x7ff79b051ab8) at execExpr.c:452#3 0x00000000006e60d5 in ExecAssignProjectionInfo (planstate=0x2f22190, inputDesc=0x7ff79b051ab8) at execUtils.c:468#4 0x00000000006e613c in ExecConditionalAssignProjectionInfo (planstate=0x2f22190, inputDesc=0x7ff79b051ab8, varno=1) at execUtils.c:493#5 0x00000000006e23f5 in ExecAssignScanProjectionInfo (node=0x2f22190) at execScan.c:240#6 0x0000000000700afc in ExecInitIndexScan (node=0x2e425f0, estate=0x2f21f78, eflags=16) at nodeIndexscan.c:962#7 0x00000000006e00cc in ExecInitNode (node=0x2e425f0, estate=0x2f21f78, eflags=16) at execProcnode.c:217#8 0x00000000006d6abe in InitPlan (queryDesc=0x2e65688, eflags=16) at execMain.c:1046#9 0x00000000006d58ad in standard_ExecutorStart (queryDesc=0x2e65688, eflags=16) at execMain.c:265#10 0x00000000006d5649 in ExecutorStart (queryDesc=0x2e65688, eflags=0) at execMain.c:147#11 0x00000000008c18d6 in PortalStart (portal=0x2eaf608, params=0x0, eflags=0, snapshot=0x0) at pquery.c:520#12 0x00000000008bbe1b in exec_simple_query (query_string=0x2e40d78 "select 1+id,c2 from t_expr where id < 3;") at postgres.c:1106#13 0x00000000008c0191 in PostgresMain (argc=1, argv=0x2e6ecb8, dbname=0x2e6eb20 "testdb", username=0x2e3da98 "xdb") at postgres.c:4182#14 0x000000000081e06c in BackendRun (port=0x2e62ae0) at postmaster.c:4361#15 0x000000000081d7df in BackendStartup (port=0x2e62ae0) at postmaster.c:4033#16 0x0000000000819bd9 in ServerLoop () at postmaster.c:1706#17 0x000000000081948f in PostmasterMain (argc=1, argv=0x2e3ba50) at postmaster.c:1379#18 0x0000000000742931 in main (argc=1, argv=0x2e3ba50) at main.c:228(gdb) 输入参数 (gdb) p *scratch -->

Step $1 = {opcode = 0, resvalue = 0x2f228c8, resnull = 0x2f228c5, d = {fetch = {last_var = 0, known_desc = 0x0}, var = {attnum = 0, vartype = 0}, wholerow = {var = 0x0, first = false, slow = false, tupdesc = 0x0, junkFilter = 0x0}, assign_var = {resultnum = 0, attnum = 0}, assign_tmp = {resultnum = 0}, constval = {value = 0, isnull = false}, func = {finfo = 0x0, fcinfo_data = fcinfo_data Fn_addr = 0x0, nargs = 0}, boolexpr = {anynull = 0x0, jumpdone = 0}, qualexpr = {jumpdone = 0}, jump = {jumpdone = 0}, nulltest_row = {argdesc = 0x0}, param = {paramid = 0, paramtype = 0}, cparam = {paramfunc = 0x0, paramarg = 0x0, paramid = 0, paramtype = 0}, casetest = {value = 0x0, isnull = 0x0}, make_readonly = {value = 0x0, isnull = 0x0}, iocoerce = {finfo_out = finfo_out, 0x0 = 0x0 Finfo_in = 0x0, fcinfo_data_in = 0x0}, sqlvaluefunction = {svf = 0x0}, nextvalueexpr = {seqid = 0, seqtypid = 0}, arrayexpr = {elemvalues = 0x0, elemnulls = 0x0, nelems = 0, elemtype = 0, elemlength = 0, elembyval = false, elemalign = 0'\ 000mm, multidims = false}, arraycoerce = {elemexprstate = 0x0, resultelemtype = 0, amstate = 0x0}, row = {tupdesc = 0x0, elemvalues = 0x0, elemnulls = 0x0}, 0x0 = {0x0 = rowcompare_step Fcinfo_data = 0x0, fn_addr = 0x0, jumpnull = 0, jumpdone = 0}, rowcompare_final = {rctype = 0}, minmax = {values = 0x0, nulls = 0x0, nelems = 0, op = IS_GREATEST, finfo = 0x0, fcinfo_data = 0x0}, fieldselect = {fieldnum = 0, resulttype = 0, argdesc = 0x0}, fieldstore = {fstore = 0x0, argdesc = 0x0, values = 0x0, nulls = 0x0, ncolumns = 0}, arrayref_subscript = {arrayref_subscript = state, state = 0, state = 0x0 Jumpdone = 0}, arrayref = {state = 0x0}, domaincheck = {constraintname = 0x0, checkvalue = 0x0, checknull = 0x0, resulttype = 0}, convert_rowtype = {convert = 0x0, indesc = 0x0, outdesc = 0x0, map = 0x0, initialized = false}, scalararrayop = {element_type = 0, useOr = false, typlen = 0, typbyval = false, typalign = 0'\ 000, finfo = 0x0, fcinfo_data = 0x0, fn_addr = fn_addr}, 0x0 = {0x0 = xmlexpr, xmlexpr = xmlexpr Named_argnull = 0x0, argvalue = 0x0, argnull = 0x0}, aggref = {astate = 0x0}, grouping_func = {parent = 0x0, clauses = 0x0}, window_func = {wfstate = 0x0}, subplan = {sstate = 0x0}, alternative_subplan = {asstate = 0x0}, agg_deserialize = {aggstate = 0x0, fcinfo_data = 0x0, jumpnull = 0}, agg_strict_input_check = {nulls = 0x0, nargs = 0, jumpnull = 0}, agg_init_trans = {aggstate = aggstate Pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0, setoff = 0, jumpnull = 0}, agg_strict_trans_check = {aggstate = 0x0, setno = 0, transno = 0, setoff = 0, jumpnull = 0}, agg_trans = {aggstate = 0x0, pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0 Setoff = 0}} # (gdb) p * node$2 = {type = T_OpExpr} (gdb) p * (OpExpr *) node-> OpExpr node $3 = {xpr = {type = T_OpExpr}, opno = 551, opfuncid = 177, opresulttype = 23, opretset = false, opcollid = 0, inputcollid = 0, args = 0x2e67520 Location = 8} testdb=#\ xExpanded display is on.testdb=# select * from pg_proc where oid=177 System proc- [RECORD 1]-- +-proname | int4plpronamespace | 11proowner | 10prolang | 12procost | 1prorows | 0provariadic | 0protransform |-prokind | fprosecdef | fproleakproof | fproisstrict | tproretset | fprovolatile | iproparallel | spronargs | 2pronargdefaults | 0prorettype | 23proargtypes | 23 23proallargtypes | proargmodes | | proargnames | proargdefaults | protrftypes | prosrc | int4plprobin | proconfig | proacl | # # (gdb) p * args$4 = {type = T_List | Length = 2, head = 0x2e674f8, tail = 0x2e675b0} # # (gdb) p * state-> ExprState$5 = {tag = {type = T_ExprState}, flags = 0'\ 000mm, resnull = false, resvalue = 0, resultslot = 0x2f22820, steps = 0x2f229b0, evalfunc = 0x0, expr = 0x2f2a348, evalfunc_private = 0x0, steps_len = 1, steps_alloc = 16, parent = 0x2f22190 Ext_params = 0x0, innermost_caseval = 0x0, innermost_casenull = 0x0, innermost_domainval = 0x0, innermost_domainnull = 0x0}

1. Check the permissions of the calling function

(gdb) n2168 aclresult = pg_proc_aclcheck (funcid, GetUserId (), ACL_EXECUTE); (gdb) 2169 if (aclresult! = ACLCHECK_OK) (gdb) 2171 InvokeFunctionExecuteHook (funcid); (gdb)

two。 Check whether nargs is legal

(gdb) 2179 if (nargs > FUNC_MAX_ARGS) (gdb)

3. Assign the function to retrieve data and parameter space for the call

(gdb) 2188 scratch- > d.func.finfo = palloc0 (sizeof (FmgrInfo)); (gdb) 2189 scratch- > d.func.fcinfo_data = palloc0 (sizeof (FunctionCallInfoData)); (gdb)

4. Configure major fmgr retrieval information

(gdb) 2194 fmgr_info (funcid, flinfo); (gdb) 2195 fmgr_info_set_expr ((Node *) node, flinfo) (gdb) (gdb) p * flinfo$6 = {fn_addr = 0x93d60c, fn_oid = 177, fn_nargs = 2, fn_strict = true, fn_retset = false, fn_stats = 2'\ 002, fn_extra = 0x0, fn_mcxt = 0x2f21e60, fn_expr = 0x2e675d8} (gdb) p * node$7 = {type = T_OpExpr} (gdb) p * (OpExpr *) node$8 = {xpr = {type = T_OpExpr}, opno = 551, opfuncid = 177, opresulttype = 23, opretset = false, opcollid = 0, inputcollid = 0 Args = 0x2e67520, location = 8} (gdb)

5. Initialize function call parameter structure

(gdb) 2198 InitFunctionCallInfoData (* fcinfo, flinfo, (gdb) n2202 scratch- > d.func.fn_addr = flinfo- > fn_addr; (gdb) 2203 scratch- > d.func.nargs = nargs; (gdb) 2206 if (flinfo- > fn_retset) (gdb) 2215 argno = 0 (gdb) 2216 foreach (lc, args) (gdb) p nargs$9 = 2 (gdb) p flinfo- > fn_addr$10 = (PGFunction) 0x93d60c (gdb) p * fcinfo$11 = {flinfo = 0x2f226b0, context = 0x0, resultinfo = 0x0, fncollation = 0, isnull = false, nargs = 2, arg = {0}, argnull = {false} (gdb) p scratch- > d.func$12 = {finfo = 0x2f226b0, fcinfo_data = 0x2f22dc8, fn_addr = 0x93d60c, nargs = 2} (nargs)

6. The loop parsing parameter args is directly stored in the fcinfo structure.

The first parameter, which is constant 1

(gdb) n2218 Expr * arg = (Expr *) lfirst (lc) (gdb) 2220 if (IsA (arg, Const)) (gdb) p * arg$13 = {type = T_Const} (gdb) p * (Const *) arg$14 = {xpr = {type = T_Const}, consttype = 23, consttypmod =-1, constcollid = 0, constlen = 4, constvalue = 1, constisnull = false, constbyval = true, location = 7} (gdb) n2226 Const * con = (Const *) arg (gdb) 2228 fcinfo- > arg [argno] = con- > constvalue; (gdb) 2229 fcinfo- > argnull [argno] = con- > constisnull; (gdb) 2236 argno++; (gdb)

The second parameter, Var, recursively calls ExecInitExprRec parsing

(gdb) 2216 foreach (lc, args) (gdb) 2218 Expr * arg = (Expr *) lfirst (lc) (gdb) 2220 if (IsA (arg, Const)) (gdb) 2233 ExecInitExprRec (arg, state, (gdb) p * arg$15 = {type = T_Var} (gdb) p * (Var *) arg$16 = {xpr = {type = T_Var}, varno = 1, varattno = 1, vartype = 23, vartypmod =-1, varcollid = 0, varlevelsup = 0, varnoold = 1, varoattno = 1, location = 9} (gdb) n2236 argno++ (gdb) (gdb) n2216 foreach (lc, args) (gdb)

7. Insert the corresponding opcode according to the strictness and statistical level of the function

2240 if (pgstat_track_functions fn_stats) (gdb) n2242 if (flinfo- > fn_strict & & nargs > 0) (gdb) 2243 scratch- > opcode = EEOP_FUNCEXPR_STRICT; (gdb) p pgstat_track_functions$17 = 0 (gdb) p flinfo- > fn_stats$18 = 2'\ 002'(gdb) n

Complete the call

2254} (gdb) ExecInitExprRec (node=0x2e675d8, state=0x2f228c0, resv=0x2f228c8, resnull=0x2f228c5) at execExpr.c:896896 ExprEvalPushStep (state, & scratch); (gdb) "how to use PostgreSQL's ExprEvalStep" ends here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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