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 construct expression parsing by PostgreSQL

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

Share

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

< 3; 调用栈 (gdb) bt #0 ExecBuildProjectionInfo (targetList=0x1cc7550, econtext=0x1c8f408, slot=0x1c8f710, parent=0x1c8f1f0, inputDesc=0x7f8386bb6ab8) at execExpr.c:355 #1 0x00000000006e60d5 in ExecAssignProjectionInfo (planstate=0x1c8f1f0, inputDesc=0x7f8386bb6ab8) at execUtils.c:468 #2 0x00000000006e613c in ExecConditionalAssignProjectionInfo (planstate=0x1c8f1f0, inputDesc=0x7f8386bb6ab8, varno=1) at execUtils.c:493 #3 0x00000000006e23f5 in ExecAssignScanProjectionInfo (node=0x1c8f1f0) at execScan.c:240 #4 0x0000000000700afc in ExecInitIndexScan (node=0x1ba8a18, estate=0x1c8efd8, eflags=16) at nodeIndexscan.c:962 #5 0x00000000006e00cc in ExecInitNode (node=0x1ba8a18, estate=0x1c8efd8, eflags=16) at execProcnode.c:217 #6 0x00000000006d6abe in InitPlan (queryDesc=0x1c94aa8, eflags=16) at execMain.c:1046 #7 0x00000000006d58ad in standard_ExecutorStart (queryDesc=0x1c94aa8, eflags=16) at execMain.c:265 #8 0x00000000006d5649 in ExecutorStart (queryDesc=0x1c94aa8, eflags=0) at execMain.c:147 #9 0x00000000008c18d6 in PortalStart (portal=0x1c15608, params=0x0, eflags=0, snapshot=0x0) at pquery.c:520 #10 0x00000000008bbe1b in exec_simple_query (query_string=0x1ba6d78 "select 1+id,c2 from t_expr where id < 3;") at postgres.c:1106 #11 0x00000000008c0191 in PostgresMain (argc=1, argv=0x1bd4cb8, dbname=0x1bd4b20 "testdb", username=0x1ba3a98 "xdb") at postgres.c:4182 #12 0x000000000081e06c in BackendRun (port=0x1bc8ae0) at postmaster.c:4361 #13 0x000000000081d7df in BackendStartup (port=0x1bc8ae0) at postmaster.c:4033 #14 0x0000000000819bd9 in ServerLoop () at postmaster.c:1706 #15 0x000000000081948f in PostmasterMain (argc=1, argv=0x1ba1a50) at postmaster.c:1379 #16 0x0000000000742931 in main (argc=1, argv=0x1ba1a50) at main.c:228 执行跟踪,进入函数ExecBuildProjectionInfo (gdb) b ExecBuildProjectionInfo Breakpoint 1 at 0x6c5377: file execExpr.c, line 355. (gdb) c Continuing. Breakpoint 1, ExecBuildProjectionInfo (targetList=0x1c93498, econtext=0x1c883a8, slot=0x1c887c8, parent=0x1c88190, inputDesc=0x1c884a0) at execExpr.c:355 355 ProjectionInfo *projInfo = makeNode(ProjectionInfo); (gdb) 1.初始化 (gdb) n 357 ExprEvalStep scratch = {0}; (gdb) 360 projInfo->

Pi_exprContext = econtext

(gdb)

362projInfo- > pi_state.tag.type = T_ExprState

(gdb)

363 state = & projInfo- > pi_state

(gdb)

364 state- > expr = (Expr *) targetList

(gdb)

365 state- > parent = parent

(gdb)

366 state- > ext_params = NULL

(gdb)

368 state- > resultslot = slot

(gdb)

View related variables

(gdb) p * state

$1 = {tag = {type = T_ExprState}, flags = 0'\ 000mm, resnull = false, resvalue = 0, resultslot = 0x1c8f710, steps = 0x0

Evalfunc = 0x0, expr = 0x1cc7550, evalfunc_private = 0x0, steps_len = 0, steps_alloc = 0, parent = 0x1c8f1f0

Ext_params = 0x0, innermost_caseval = 0x0, innermost_casenull = 0x0, innermost_domainval = 0x0

Innermost_domainnull = 0x0}

Target list

(gdb) p targetList

$2 = (List *) 0x1cc7550

(gdb) p * targetList

$3 = {type = T_List, length = 2, head = 0x1cc7528, tail = 0x1cc75e0}

The first element is 1+id and the second element is c2

(gdb) p * (TargetEntry *) targetList- > head- > data.ptr_value

$7 = {xpr = {type = T_TargetEntry}, expr = 0x1c9a930, resno = 1, resname = 0xbcf498 "? column?", ressortgroupref = 0

Resorigtbl = 0, resorigcol = 0, resjunk = false}

(gdb) p * (OpExpr *) ((TargetEntry *) targetList- > head- > data.ptr_value)-> expr

$9 = {xpr = {type = T_OpExpr}, opno = 551, opfuncid = 177, opresulttype = 23, opretset = false, opcollid = 0

Inputcollid = 0, args = 0x1c9a878, location = 8}

(gdb) p * (Node *) targetList- > head- > next- > data.ptr_value

$10 = {type = T_TargetEntry}

(gdb) p * (TargetEntry *) targetList- > head- > next- > data.ptr_value

$11 = {xpr = {type = T_TargetEntry}, expr = 0x1c9aa40, resno = 2, resname = 0x1ba7a40 "c2", ressortgroupref = 0

Resorigtbl = 237600, resorigcol = 2, resjunk = false}

two。 Insert EEOP_*_FETCHSOME step (call ExecInitExprSlots) if necessary

(gdb)

371ExecInitExprSlots (state, (Node *) targetList)

The first step, opcode = 3, is EEOP_SCAN_FETCHSOME

(gdb) n

374foreach (lc, targetList)

(gdb) p * state

$13 = {tag = {type = T_ExprState}, flags = 0'\ 000mm, resnull = false, resvalue = 0, resultslot = 0x1c8f710

Steps = 0x1c8f868, evalfunc = 0x0, expr = 0x1cc7550, evalfunc_private = 0x0, steps_len = 1, steps_alloc = 16

Parent = 0x1c8f1f0, ext_params = 0x0, innermost_caseval = 0x0, innermost_casenull = 0x0, innermost_domainval = 0x0

Innermost_domainnull = 0x0}

(gdb) p state- > steps [0]

$14 = {opcode = 3, resvalue = 0x0, resnull = 0x0, d = {fetch = {last_var = 2, known_desc = 0x0}, var = {attnum = 2

Vartype = 0}, wholerow = {var = 0x2, first = false, slow = false, tupdesc = 0x0, junkFilter = 0x0}, assign_var = {

Resultnum = 2, attnum = 0}, assign_tmp = {resultnum = 2}, constval = {value = 2, isnull = false}, func = {

Finfo = 0x2, fcinfo_data = 0x0, fn_addr = 0x0, nargs = 0}, boolexpr = {anynull = 0x2, jumpdone = 0}, qualexpr = {

Jumpdone = 2}, jump = {jumpdone = 2}, nulltest_row = {argdesc = 0x2}, param = {paramid = 2, paramtype = 0}, cparam = {

Paramfunc = 0x2, paramarg = 0x0, paramid = 0, paramtype = 0}, casetest = {value = 0x2, isnull = 0x0}

Make_readonly = {value = 0x2, isnull = 0x0}, iocoerce = {finfo_out = 0x2, fcinfo_data_out = 0x0, finfo_in = 0x0

Fcinfo_data_in = 0x0}, sqlvaluefunction = {svf = 0x2}, nextvalueexpr = {seqid = 2, seqtypid = 0}, arrayexpr = {

Elemvalues = 0x2, elemnulls = 0x0, nelems = 0, elemtype = 0, elemlength = 0, elembyval = false, elemalign = 0'\ 000'

Multidims = false}, arraycoerce = {elemexprstate = 0x2, resultelemtype = 0, amstate = 0x0}, row = {tupdesc = 0x2

Elemvalues = 0x0, elemnulls = 0x0}, rowcompare_step = {finfo = 0x2, fcinfo_data = 0x0, fn_addr = 0x0, jumpnull = 0

Jumpdone = 0}, rowcompare_final = {rctype = ROWCOMPARE_LE}, minmax = {values = 0x2, nulls = 0x0, nelems = 0

Op = IS_GREATEST, finfo = 0x0, fcinfo_data = 0x0}, fieldselect = {fieldnum = 2, resulttype = 0, argdesc = 0x0}

Fieldstore = {fstore = 0x2, argdesc = 0x0, values = 0x0, nulls = 0x0, ncolumns = 0}, arrayref_subscript = {state = 0x2

Off = 0, isupper = false, jumpdone = 0}, arrayref = {state = 0x2}, domaincheck = {

Constraintname = 0x2, checkvalue = 0x0, checknull = 0x0, resulttype = 0}

Convert_rowtype = {convert = 0x2, indesc = 0x0, outdesc = 0x0, map = 0x0, initialized = false}, scalararrayop = {

Element_type = 2, useOr = false, typlen = 0, typbyval = false, typalign = 0'\ 000mm, finfo = 0x0, fcinfo_data = 0x0

Fn_addr = 0x0}, xmlexpr = {xexpr = 0x2, named_argvalue = 0x0, named_argnull = 0x0, argvalue = 0x0, argnull = 0x0}

Aggref = {astate = 0x2}, grouping_func = {parent = 0x2, clauses = 0x0}, window_func = {wfstate = 0x2}, subplan = {

Sstate = 0x2}, alternative_subplan = {asstate = 0x2}, agg_deserialize = {aggstate = 0x2, fcinfo_data = 0x0

Jumpnull = 0}, agg_strict_input_check = {nulls = 0x2, nargs = 0, jumpnull = 0}, agg_init_trans = {aggstate = 0x2

Pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0, setoff = 0, jumpnull = 0}, agg_strict_trans_check = {

Aggstate = 0x2, setno = 0, transno = 0, setoff = 0, jumpnull = 0}, agg_trans = {aggstate = 0x2, pertrans = 0x0

Aggcontext = 0x0, setno = 0, transno = 0, setoff = 0}

(gdb)

3. Traverses the targetList, processing each column in the targetList (target column)

3.1. For "secure" Var, you only need to generate the EEOPASSIGN*_VAR step

3.2. For non-"safe" VAr, use the conventional method to handle column expressions, call the ExecInitExprRec function to process, and press the steps through ExprEvalPushStep

(gdb) n

376 TargetEntry * tle = lfirst_node (TargetEntry, lc)

(gdb)

377 Var * variable = NULL

(gdb)

378 AttrNumber attnum = 0

(gdb)

379 bool isSafeVar = false

(gdb)

389 if (tle- > expr! = NULL & &

(gdb)

390 IsA (tle- > expr, Var) &

(gdb)

389 if (tle- > expr! = NULL & &

(gdb)

415 if (isSafeVar)

(gdb) p * tle

$15 = {xpr = {type = T_TargetEntry}, expr = 0x1c9a930, resno = 1, resname = 0xbcf498 "? column?", ressortgroupref = 0

Resorigtbl = 0, resorigcol = 0, resjunk = false}

(gdb) n

452 ExecInitExprRec (tle- > expr, state

(gdb)

Enter the ExecInitExprRec,Node node as OpExpr, and perform the ExprEvalPushStep push step

(gdb) step

ExecInitExprRec (node=0x1c9a930, state=0x1c8f7d8, resv=0x1c8f7e0, resnull=0x1c8f7dd) at execExpr.c:645

645 ExprEvalStep scratch = {0}

(gdb) n

648 check_stack_depth ()

(gdb)

651 Assert (resv! = NULL & & resnull! = NULL)

(gdb)

652 scratch.resvalue = resv

(gdb)

653 scratch.resnull = resnull

(gdb)

656 switch (nodeTag (node))

(gdb)

891 OpExpr * op = (OpExpr *) node

(gdb) p * node

$16 = {type = T_OpExpr}

(gdb) n

893 ExecInitFunc & scratch, node

(gdb)

896 ExprEvalPushStep (state, & scratch)

(gdb)

897 break

(gdb)

2122}

(gdb)

ExecBuildProjectionInfo (targetList=0x1cc7550, econtext=0x1c8f408, slot=0x1c8f710, parent=0x1c8f1f0

InputDesc=0x7f8386bb6ab8) at execExpr.c:459

459 if (get_typlen (exprType ((Node *) tle- > expr)) =-1)

(gdb)

462 scratch.opcode = EEOP_ASSIGN_TMP

(gdb)

After the call to ExecInitExprRec is completed, two additional steps have been added:

1.opcode = 6, that is EEOP_SCAN_VAR

2.opcode = 18, that is EEOP_FUNCEXPR_STRICT

(gdb) p * state

$17 = {tag = {type = T_ExprState}, flags = 0'\ 000mm, resnull = false, resvalue = 0, resultslot = 0x1c8f710

Steps = 0x1c8f868, evalfunc = 0x0, expr = 0x1cc7550, evalfunc_private = 0x0, steps_len = 3, steps_alloc = 16

Parent = 0x1c8f1f0, ext_params = 0x0, innermost_caseval = 0x0, innermost_casenull = 0x0, innermost_domainval = 0x0

Innermost_domainnull = 0x0}

(gdb) p state- > steps [1]

$18 = {opcode = 6, resvalue = 0x1c8fd00, resnull = 0x1c90019, d = {fetch = {last_var = 0, known_desc = 0x0}, var = {

Attnum = 0, vartype = 23}, wholerow = {var = 0x1700000000, first = false, slow = false, tupdesc = 0x0

JunkFilter = 0x0}, assign_var = {resultnum = 0, attnum = 23}, assign_tmp = {resultnum = 0}, constval = {

Value = 98784247808, isnull = false}, func = {finfo = 0x1700000000, fcinfo_data = 0x0, fn_addr = 0x0, nargs = 0}

Boolexpr = {anynull = 0x1700000000, jumpdone = 0}, qualexpr = {jumpdone = 0}, jump = {jumpdone = 0}, nulltest_row = {

Argdesc = 0x1700000000}, param = {paramid = 0, paramtype = 23}, cparam = {paramfunc = 0x1700000000, paramarg = 0x0

Paramid = 0, paramtype = 0}, casetest = {value = 0x1700000000, isnull = 0x0}, make_readonly = {value = 0x1700000000

Isnull = 0x0}, iocoerce = {finfo_out = 0x1700000000, fcinfo_data_out = 0x0, finfo_in = 0x0, fcinfo_data_in = 0x0}

Sqlvaluefunction = {svf = 0x1700000000}, nextvalueexpr = {seqid = 0, seqtypid = 23}, arrayexpr = {

Elemvalues = 0x1700000000, elemnulls = 0x0, nelems = 0, elemtype = 0, elemlength = 0, elembyval = false

Elemalign = 0'\ 000mm, multidims = false}, arraycoerce = {elemexprstate = 0x1700000000, resultelemtype = 0

Amstate = 0x0}, row = {tupdesc = 0x1700000000, elemvalues = 0x0, elemnulls = 0x0}, rowcompare_step = {

Finfo = 0x1700000000, fcinfo_data = 0x0, fn_addr = 0x0, jumpnull = 0, jumpdone = 0}, rowcompare_final = {rctype = 0}

Minmax = {values = 0x1700000000, nulls = 0x0, nelems = 0, op = IS_GREATEST, finfo = 0x0, fcinfo_data = 0x0}

Fieldselect = {fieldnum = 0, resulttype = 23, argdesc = 0x0}, fieldstore = {fstore = 0x1700000000, argdesc = 0x0

Values = 0x0, nulls = 0x0, ncolumns = 0}, arrayref_subscript = {state = 0x1700000000, off = 0, isupper = false

Jumpdone = 0}, arrayref = {state = 0x1700000000}, domaincheck = {

Constraintname = 0x1700000000, checkvalue = 0x0, checknull = 0x0

Resulttype = 0}, convert_rowtype = {convert = 0x1700000000, indesc = 0x0, outdesc = 0x0, map = 0x0

Initialized = false}, scalararrayop = {element_type = 0, useOr = 23, typlen = 0, typbyval = false

Typalign = 0'\ 000mm, finfo = 0x0, fcinfo_data = 0x0, fn_addr = 0x0}, xmlexpr = {xexpr = 0x1700000000

Named_argvalue = 0x0, named_argnull = 0x0, argvalue = 0x0, argnull = 0x0}, aggref = {astate = 0x1700000000}

Grouping_func = {parent = 0x1700000000, clauses = 0x0}, window_func = {wfstate = 0x1700000000}, subplan = {

Sstate = 0x1700000000}, alternative_subplan = {asstate = 0x1700000000}, agg_deserialize = {aggstate = 0x1700000000

Fcinfo_data = 0x0, jumpnull = 0}, agg_strict_input_check = {nulls = 0x1700000000, nargs = 0, jumpnull = 0}

Agg_init_trans = {aggstate = 0x1700000000, pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0, setoff = 0

Jumpnull = 0}, agg_strict_trans_check = {aggstate = 0x1700000000, setno = 0, transno = 0, setoff = 0, jumpnull = 0}

-Type to continue, or q to quit

Agg_trans = {aggstate = 0x1700000000, pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0, setoff = 0}

(gdb) p state- > steps [2]

$19 = {opcode = 18, resvalue = 0x1c8f7e0, resnull = 0x1c8f7dd, d = {fetch = {last_var = 29949056, known_desc = 0x1c8fcd8}

Var = {attnum = 29949056, vartype = 0}, wholerow = {var = 0x1c8fc80, first = 216,252

Tupdesc = 0x93d60c, junkFilter = 0x2}, assign_var = {resultnum = 29949056, attnum = 0}, assign_tmp = {

Resultnum = 29949056}, constval = {value = 29949056, isnull = 29949056}, func = {finfo = 0x1c8fc80

Fcinfo_data = 0x1c8fcd8, fn_addr = 0x93d60c, nargs = 2}, boolexpr = {anynull = 0x1c8fc80

Jumpdone = 29949144}, qualexpr = {jumpdone = 29949056}, jump = {jumpdone = 29949056}, nulltest_row = {

Argdesc = 0x1c8fc80}, param = {paramid = 29949056, paramtype = 0}, cparam = {paramfunc = 0x1c8fc80

Paramarg = 0x1c8fcd8, paramid = 9688588, paramtype = 0}, casetest = {value = 0x1c8fc80, isnull = 0x1c8fcd8}

Make_readonly = {value = 0x1c8fc80, isnull = 0x1c8fcd8}, iocoerce = {finfo_out = 0x1c8fc80

Fcinfo_data_out = 0x1c8fcd8, finfo_in = 0x93d60c, fcinfo_data_in = 0x2}, sqlvaluefunction = {

Svf = 0x1c8fc80}, nextvalueexpr = {seqid = 29949056, seqtypid = 0}, arrayexpr = {elemvalues = 0x1c8fc80

Elemnulls = 0x1c8fcd8, nelems = 9688588, elemtype = 0, elemlength = 2, elembyval = false, elemalign = 0'\ 000'

Multidims = false}, arraycoerce = {elemexprstate = 0x1c8fc80, resultelemtype = 29949144

Amstate = 0x93d60c}, row = {tupdesc = 0x1c8fc80, elemvalues = 0x1c8fcd8, elemnulls = 0x93d60c}

Rowcompare_step = {finfo = 0x1c8fc80, fcinfo_data = 0x1c8fcd8, fn_addr = 0x93d60c, jumpnull = 2

Jumpdone = 0}, rowcompare_final = {rctype = 29949056}, minmax = {values = 0x1c8fc80, nulls = 0x1c8fcd8

Nelems = 9688588, op = IS_GREATEST, finfo = 0x2, fcinfo_data = 0x0}, fieldselect = {fieldnum =-896, resulttype = 0

Argdesc = 0x1c8fcd8}, fieldstore = {fstore = 0x1c8fc80, argdesc = 0x1c8fcd8, values = 0x93d60c, nulls = 0x2

Ncolumns = 0}, arrayref_subscript = {state = 0x1c8fc80, off = 29949144, isupper = false, jumpdone = 9688588}

Arrayref = {state = 0x1c8fc80}, domaincheck = {constraintname = 0x1c8fc80 "\ f stories", checkvalue = 0x1c8fcd8

Checknull = 0x93d60c, resulttype = 2}, convert_rowtype = {convert = 0x1c8fc80, indesc = 0x1c8fcd8

Outdesc = 0x93d60c, map = 0x2, initialized = false}, scalararrayop = {element_type = 29949056

UseOr = false, typlen = 0, typbyval = 216,216,374, finfo = 0x93d60c, fcinfo_data = 0x2

Fn_addr = 0x0}, xmlexpr = {xexpr = 0x1c8fc80, named_argvalue = 0x1c8fcd8, named_argnull = 0x93d60c

Argvalue = 0x2, argnull = 0x0}, aggref = {astate = 0x1c8fc80}, grouping_func = {parent = 0x1c8fc80

Clauses = 0x1c8fcd8}, window_func = {wfstate = 0x1c8fc80}, subplan = {sstate = 0x1c8fc80}, alternative_subplan = {

Asstate = 0x1c8fc80}, agg_deserialize = {aggstate = 0x1c8fc80, fcinfo_data = 0x1c8fcd8, jumpnull = 9688588}

-Type to continue, or q to quit

Agg_strict_input_check = {nulls = 0x1c8fc80, nargs = 29949144, jumpnull = 0}, agg_init_trans = {aggstate = 0x1c8fc80

Pertrans = 0x1c8fcd8, aggcontext = 0x93d60c, setno = 2, transno = 0, setoff = 0, jumpnull = 0}

Agg_strict_trans_check = {aggstate = 0x1c8fc80, setno = 29949144, transno = 0, setoff = 9688588, jumpnull = 0}

Agg_trans = {aggstate = 0x1c8fc80, pertrans = 0x1c8fcd8, aggcontext = 0x93d60c, setno = 2, transno = 0

Setoff = 0}

(gdb)

Press the number of the column of the expression, opcode = 14, that is, EEOP_ASSIGN_TMP

(gdb) n

463 scratch.d.assign_tmp.resultnum = tle- > resno-1

(gdb)

464 ExprEvalPushStep (state, & scratch)

(gdb)

(gdb)

374foreach (lc, targetList)

(gdb) p * state

$20 = {tag = {type = T_ExprState}, flags = 0'\ 000mm, resnull = false, resvalue = 0, resultslot = 0x1c8f710

Steps = 0x1c8f868, evalfunc = 0x0, expr = 0x1cc7550, evalfunc_private = 0x0, steps_len = 4, steps_alloc = 16

Parent = 0x1c8f1f0, ext_params = 0x0, innermost_caseval = 0x0, innermost_casenull = 0x0, innermost_domainval = 0x0

Innermost_domainnull = 0x0}

(gdb) p state- > steps [3]

$21 = {opcode = 14, resvalue = 0x0, resnull = 0x0, 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 = 0x0, 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 = 0x0, fcinfo_data_out = 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'\ 000'

Multidims = false}, arraycoerce = {elemexprstate = 0x0, resultelemtype = 0, amstate = 0x0}, row = {tupdesc = 0x0

Elemvalues = 0x0, elemnulls = 0x0}, rowcompare_step = {finfo = 0x0, 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 = {state = 0x0, off = 0

Isupper = false, 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'\ 000mm, finfo = 0x0, fcinfo_data = 0x0, fn_addr = 0x0}, xmlexpr = {xexpr = 0x0, named_argvalue = 0x0

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 = 0x0, 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)

Proceed to the next column, which is a "security" column, press the EEOP_ASSIGN_SCAN_VAR step

(gdb) n

376 TargetEntry * tle = lfirst_node (TargetEntry, lc)

(gdb)

377 Var * variable = NULL

(gdb) p * tle

$22 = {xpr = {type = T_TargetEntry}, expr = 0x1c9aa40, resno = 2, resname = 0x1ba7a40 "c2", ressortgroupref = 0

Resorigtbl = 237600, resorigcol = 2, resjunk = false}

(gdb) n

378 AttrNumber attnum = 0

(gdb)

379 bool isSafeVar = false

(gdb)

389 if (tle- > expr! = NULL & &

(gdb)

390 IsA (tle- > expr, Var) &

(gdb)

389 if (tle- > expr! = NULL & &

(gdb)

391 ((Var *) tle- > expr)-> varattno > 0)

(gdb)

390 IsA (tle- > expr, Var) &

(gdb)

394 variable = (Var *) tle- > expr

(gdb)

395 attnum = variable- > varattno

(gdb)

397 if (inputDesc = = NULL)

(gdb)

399 else if (attnum natts)

(gdb)

401 Form_pg_attribute attr = TupleDescAttr (inputDesc, attnum-1)

(gdb)

If (! attr- > attisdropped & & variable- > vartype = = attr- > atttypid)

(gdb)

410 isSafeVar = true

(gdb)

415 if (isSafeVar)

(gdb)

418 switch (variable- > varno)

(gdb)

434 scratch.opcode = EEOP_ASSIGN_SCAN_VAR

(gdb)

435 break

(gdb)

438 scratch.d.assign_var.attnum = attnum-1

(gdb)

439 scratch.d.assign_var.resultnum = tle- > resno-1

(gdb)

440 ExprEvalPushStep (state, & scratch)

(gdb) p * state

$23 = {tag = {type = T_ExprState}, flags = 0'\ 000mm, resnull = false, resvalue = 0, resultslot = 0x1c8f710

Steps = 0x1c8f868, evalfunc = 0x0, expr = 0x1cc7550, evalfunc_private = 0x0, steps_len = 4, steps_alloc = 16

Parent = 0x1c8f1f0, ext_params = 0x0, innermost_caseval = 0x0, innermost_casenull = 0x0, innermost_domainval = 0x0

Innermost_domainnull = 0x0}

(gdb) n

374foreach (lc, targetList)

(gdb) p * state

$24 = {tag = {type = T_ExprState}, flags = 0'\ 000mm, resnull = false, resvalue = 0, resultslot = 0x1c8f710

Steps = 0x1c8f868, evalfunc = 0x0, expr = 0x1cc7550, evalfunc_private = 0x0, steps_len = 5, steps_alloc = 16

Parent = 0x1c8f1f0, ext_params = 0x0, innermost_caseval = 0x0, innermost_casenull = 0x0, innermost_domainval = 0x0

Innermost_domainnull = 0x0}

(gdb) p state- > steps [4]

$25 = {opcode = 13, resvalue = 0x0, resnull = 0x0, d = {fetch = {last_var = 1, known_desc = 0x0}, var = {attnum = 1

Vartype = 1}, wholerow = {var = 0x100000001, first = false, slow = false, tupdesc = 0x0, junkFilter = 0x0}

Assign_var = {resultnum = 1, attnum = 1}, assign_tmp = {resultnum = 1}, constval = {value = 4294967297

Isnull = false}, func = {finfo = 0x100000001, fcinfo_data = 0x0, fn_addr = 0x0, nargs = 0}, boolexpr = {

Anynull = 0x100000001, jumpdone = 0}, qualexpr = {jumpdone = 1}, jump = {jumpdone = 1}, nulltest_row = {

Argdesc = 0x100000001}, param = {paramid = 1, paramtype = 1}, cparam = {paramfunc = 0x100000001, paramarg = 0x0

Paramid = 0, paramtype = 0}, casetest = {value = 0x100000001, isnull = 0x0}, make_readonly = {value = 0x100000001

Isnull = 0x0}, iocoerce = {finfo_out = 0x100000001, fcinfo_data_out = 0x0, finfo_in = 0x0, fcinfo_data_in = 0x0}

Sqlvaluefunction = {svf = 0x100000001}, nextvalueexpr = {seqid = 1, seqtypid = 1}, arrayexpr = {

Elemvalues = 0x100000001, elemnulls = 0x0, nelems = 0, elemtype = 0, elemlength = 0, elembyval = false

Elemalign = 0'\ 000mm, multidims = false}, arraycoerce = {elemexprstate = 0x100000001, resultelemtype = 0

Amstate = 0x0}, row = {tupdesc = 0x100000001, elemvalues = 0x0, elemnulls = 0x0}, rowcompare_step = {

Finfo = 0x100000001, fcinfo_data = 0x0, fn_addr = 0x0, jumpnull = 0, jumpdone = 0}, rowcompare_final = {

Rctype = ROWCOMPARE_LT}, minmax = {values = 0x100000001, nulls = 0x0, nelems = 0, op = IS_GREATEST, finfo = 0x0

Fcinfo_data = 0x0}, fieldselect = {fieldnum = 1, resulttype = 1, argdesc = 0x0}, fieldstore = {fstore = 0x100000001

Argdesc = 0x0, values = 0x0, nulls = 0x0, ncolumns = 0}, arrayref_subscript = {state = 0x100000001, off = 0

Isupper = false, jumpdone = 0}, arrayref = {state = 0x100000001}, domaincheck = {

Constraintname = 0x100000001, checkvalue = 0x0, checknull = 0x0, resulttype = 0}

Convert_rowtype = {convert = 0x100000001, indesc = 0x0, outdesc = 0x0, map = 0x0, initialized = false}

Scalararrayop = {element_type = 1, useOr = true, typlen = 0, typbyval = false, typalign = 0'\ 000mm, finfo = 0x0

Fcinfo_data = 0x0, fn_addr = 0x0}, xmlexpr = {xexpr = 0x100000001, named_argvalue = 0x0, named_argnull = 0x0

Argvalue = 0x0, argnull = 0x0}, aggref = {astate = 0x100000001}, grouping_func = {parent = 0x100000001

Clauses = 0x0}, window_func = {wfstate = 0x100000001}, subplan = {sstate = 0x100000001}, alternative_subplan = {

Asstate = 0x100000001}, agg_deserialize = {aggstate = 0x100000001, fcinfo_data = 0x0, jumpnull = 0}

Agg_strict_input_check = {nulls = 0x100000001, nargs = 0, jumpnull = 0}, agg_init_trans = {aggstate = 0x100000001

Pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0, setoff = 0, jumpnull = 0}, agg_strict_trans_check = {

Aggstate = 0x100000001, setno = 0, transno = 0, setoff = 0, jumpnull = 0}, agg_trans = {aggstate = 0x100000001

-Type to continue, or q to quit

Pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0, setoff = 0}}

(gdb)

4. Press in EEOP_DONE step

(gdb) n

468 scratch.opcode = EEOP_DONE

(gdb)

469 ExprEvalPushStep (state, & scratch)

(gdb)

471 ExecReadyExpr (state)

(gdb) p state- > steps [5]

$26 = {opcode = 0, resvalue = 0x0, resnull = 0x0, d = {fetch = {last_var = 1, known_desc = 0x0}, var = {attnum = 1

Vartype = 1}, wholerow = {var = 0x100000001, first = false, slow = false, tupdesc = 0x0, junkFilter = 0x0}

Assign_var = {resultnum = 1, attnum = 1}, assign_tmp = {resultnum = 1}, constval = {value = 4294967297

Isnull = false}, func = {finfo = 0x100000001, fcinfo_data = 0x0, fn_addr = 0x0, nargs = 0}, boolexpr = {

Anynull = 0x100000001, jumpdone = 0}, qualexpr = {jumpdone = 1}, jump = {jumpdone = 1}, nulltest_row = {

Argdesc = 0x100000001}, param = {paramid = 1, paramtype = 1}, cparam = {paramfunc = 0x100000001, paramarg = 0x0

Paramid = 0, paramtype = 0}, casetest = {value = 0x100000001, isnull = 0x0}, make_readonly = {value = 0x100000001

Isnull = 0x0}, iocoerce = {finfo_out = 0x100000001, fcinfo_data_out = 0x0, finfo_in = 0x0, fcinfo_data_in = 0x0}

Sqlvaluefunction = {svf = 0x100000001}, nextvalueexpr = {seqid = 1, seqtypid = 1}, arrayexpr = {

Elemvalues = 0x100000001, elemnulls = 0x0, nelems = 0, elemtype = 0, elemlength = 0, elembyval = false

Elemalign = 0'\ 000mm, multidims = false}, arraycoerce = {elemexprstate = 0x100000001, resultelemtype = 0

Amstate = 0x0}, row = {tupdesc = 0x100000001, elemvalues = 0x0, elemnulls = 0x0}, rowcompare_step = {

Finfo = 0x100000001, fcinfo_data = 0x0, fn_addr = 0x0, jumpnull = 0, jumpdone = 0}, rowcompare_final = {

Rctype = ROWCOMPARE_LT}, minmax = {values = 0x100000001, nulls = 0x0, nelems = 0, op = IS_GREATEST, finfo = 0x0

Fcinfo_data = 0x0}, fieldselect = {fieldnum = 1, resulttype = 1, argdesc = 0x0}, fieldstore = {fstore = 0x100000001

Argdesc = 0x0, values = 0x0, nulls = 0x0, ncolumns = 0}, arrayref_subscript = {state = 0x100000001, off = 0

Isupper = false, jumpdone = 0}, arrayref = {state = 0x100000001}, domaincheck = {

Constraintname = 0x100000001, checkvalue = 0x0, checknull = 0x0, resulttype = 0}

Convert_rowtype = {convert = 0x100000001, indesc = 0x0, outdesc = 0x0, map = 0x0, initialized = false}

Scalararrayop = {element_type = 1, useOr = true, typlen = 0, typbyval = false, typalign = 0'\ 000mm, finfo = 0x0

Fcinfo_data = 0x0, fn_addr = 0x0}, xmlexpr = {xexpr = 0x100000001, named_argvalue = 0x0, named_argnull = 0x0

Argvalue = 0x0, argnull = 0x0}, aggref = {astate = 0x100000001}, grouping_func = {parent = 0x100000001

Clauses = 0x0}, window_func = {wfstate = 0x100000001}, subplan = {sstate = 0x100000001}, alternative_subplan = {

Asstate = 0x100000001}, agg_deserialize = {aggstate = 0x100000001, fcinfo_data = 0x0, jumpnull = 0}

Agg_strict_input_check = {nulls = 0x100000001, nargs = 0, jumpnull = 0}, agg_init_trans = {aggstate = 0x100000001

Pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0, setoff = 0, jumpnull = 0}, agg_strict_trans_check = {

Aggstate = 0x100000001, setno = 0, transno = 0, setoff = 0, jumpnull = 0}, agg_trans = {aggstate = 0x100000001

-Type to continue, or q to quit

Pertrans = 0x0, aggcontext = 0x0, setno = 0, transno = 0, setoff = 0}}

(gdb)

End the call

(gdb) n

473 return projInfo

(gdb)

474}

(gdb)

ExecAssignProjectionInfo (planstate=0x1c8f1f0, inputDesc=0x7f8386bb6ab8) at execUtils.c:467

467 planstate- > ps_ProjInfo =

(gdb)

That's all of the article "how to build expression parsing in PostgreSQL". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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