Skip to content

Instantly share code, notes, and snippets.

@ringerc
Created June 9, 2013 09:33
Show Gist options
  • Save ringerc/5742942 to your computer and use it in GitHub Desktop.
Save ringerc/5742942 to your computer and use it in GitHub Desktop.
Backtrace of execution of simple PL/PgSQL array access
craig=> DO
$$
BEGIN
PERFORM (ARRAY[1])[1];
END;
$$ LANGUAGE plpgsql;
with a breakpoint set at ExecEvalArrayRef results in:
(gdb) bt
#0 ExecEvalArrayRef (astate=0x1979ac0, econtext=0x19798d0, isNull=0x1979d38 "", isDone=0x1979e50) at execQual.c:265
#1 0x0000000000589e5d in ExecTargetList (isDone=0x7fff038f90fc, itemIsDone=0x1979e50, isnull=0x1979d38 "", values=0x1979d20, econtext=0x19798d0, targetlist=0x1979e20)
at execQual.c:5221
#2 ExecProject (projInfo=<optimized out>, isDone=isDone@entry=0x7fff038f90fc) at execQual.c:5436
#3 0x000000000059b0aa in ExecResult (node=node@entry=0x19797c0) at nodeResult.c:155
#4 0x0000000000582f28 in ExecProcNode (node=node@entry=0x19797c0) at execProcnode.c:372
#5 0x0000000000580780 in ExecutePlan (dest=0xb28c60 <spi_printtupDR>, direction=<optimized out>, numberTuples=0, sendTuples=1 '\001', operation=CMD_SELECT,
planstate=0x19797c0, estate=0x19796b0) at execMain.c:1395
#6 standard_ExecutorRun (queryDesc=0x1976270, direction=<optimized out>, count=0) at execMain.c:303
#7 0x00000000005a4151 in _SPI_pquery (tcount=0, fire_triggers=1 '\001', queryDesc=<optimized out>) at spi.c:2291
#8 _SPI_execute_plan (plan=plan@entry=0x1897870, paramLI=paramLI@entry=0x0, snapshot=snapshot@entry=0x0, crosscheck_snapshot=crosscheck_snapshot@entry=0x0,
read_only=read_only@entry=0 '\000', fire_triggers=fire_triggers@entry=1 '\001', tcount=tcount@entry=0) at spi.c:2085
#9 0x00000000005a454d in SPI_execute_plan_with_paramlist (plan=0x1897870, params=params@entry=0x0, read_only=0 '\000', tcount=tcount@entry=0) at spi.c:423
#10 0x00007f86c7b32755 in exec_run_select (estate=estate@entry=0x7fff038f9600, expr=0x1970ca8, maxtuples=maxtuples@entry=0, portalP=portalP@entry=0x0) at pl_exec.c:4649
#11 0x00007f86c7b36709 in exec_stmt_perform (stmt=0x1970d68, estate=0x7fff038f9600) at pl_exec.c:1419
#12 exec_stmt (stmt=0x1970d68, estate=0x7fff038f9600) at pl_exec.c:1295
#13 exec_stmts (estate=0x7fff038f9600, stmts=<optimized out>) at pl_exec.c:1254
#14 0x00007f86c7b3886c in exec_stmt_block (estate=estate@entry=0x7fff038f9600, block=0x1970dd8) at pl_exec.c:1192
#15 0x00007f86c7b392b1 in plpgsql_exec_function (func=func@entry=0x196e808, fcinfo=fcinfo@entry=0x7fff038f9710) at pl_exec.c:329
#16 0x00007f86c7b2de5d in plpgsql_inline_handler (fcinfo=<optimized out>) at pl_handler.c:189
#17 0x0000000000721779 in OidFunctionCall1Coll (functionId=<optimized out>, collation=0, arg1=25779872) at fmgr.c:1599
#18 0x00000000006582a7 in PortalRunUtility (portal=0x1893e90, utilityStmt=0x1921c70, isTopLevel=1 '\001', dest=0x1921fa0, completionTag=0x7fff038fa300 "") at pquery.c:1185
#19 0x0000000000658f15 in PortalRunMulti (portal=portal@entry=0x1893e90, isTopLevel=isTopLevel@entry=1 '\001', dest=dest@entry=0x1921fa0, altdest=altdest@entry=0x1921fa0,
completionTag=completionTag@entry=0x7fff038fa300 "") at pquery.c:1316
#20 0x0000000000659ad2 in PortalRun (portal=portal@entry=0x1893e90, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=1 '\001', dest=dest@entry=0x1921fa0,
altdest=altdest@entry=0x1921fa0, completionTag=completionTag@entry=0x7fff038fa300 "") at pquery.c:814
#21 0x0000000000655c27 in exec_simple_query (query_string=0x1921090 "DO\n$$\nBEGIN\n PERFORM (ARRAY[1])[1];\nEND;\n$$ LANGUAGE plpgsql;") at postgres.c:1046
#22 PostgresMain (argc=<optimized out>, argv=argv@entry=0x18991d0, dbname=0x1979d38 "", username=<optimized out>) at postgres.c:3959
#23 0x0000000000615d36 in BackendRun (port=0x1899e80) at postmaster.c:3614
#24 BackendStartup (port=0x1899e80) at postmaster.c:3304
#25 ServerLoop () at postmaster.c:1367
Of this, frames 17-22 are part of the regular execution of most queries.
Frames 13-16 are PL/PgSQL's setup and entry into the top level function.
Frame 1 through 12 are execution of the array lookup `PERFORM` query by PL/PgSQL, including the SPI calls, executor, etc.
Frame 0 is the array lookup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment