Postgresql源码(78)plpgsql中调用call proc()时的参数传递和赋值(pl参数)
postgresql源码 参数 调用 赋值 call PL 参数传递
2023-06-13 09:11:07 时间
《Postgresql源码(77)plpgsql中参数传递和赋值(pl参数)》 《Postgresql源码(78)plpgsql中调用call proc()时的参数传递和赋值(pl参数)》
总结
- 调用者在exec_stmt_call中拼接ParamListInfo传给SPI去执行call xxxx命令。
- ParamListInfo记录了PL的一些回调函数,在SPI会走到:ExecuteCallStmt
- ExecuteCallStmt核心流程两步:
- 拼参数列表:会拿到所有入参
- 假设第一个入参是Param类型,会回调PL的plpgsql_param_fetch函数,从PL的Datums中拿变量的值赋值给fcinfo->args[0]
- 假设第二个入参是Const类型常量,则会直接在执行器内赋值给
fcinfo->args[1]
- 走FunctionCallInvoke进入plpgsql_exec_functions开始执行被调用函数。
实验用例
create or replace procedure p1(p_a in int, p_b in int, p_c out int)
language plpgsql
as $$
begin
p_c := 30000;
raise notice '% % %', p_a, p_b, p_c;
end;
$$;
do $$
declare
a1 int;
a3 int;
begin
a1 := 10;
call p1(a1, 20, a3);
raise notice 'a3: %', a3;
end;
$$;
进入exec_stmt_call时
-
a1
:有值,value = 10,isnull = false,freeval = false -
a3
:无值,value = 0, isnull = true, freeval = false
(gdb) p *(PLpgSQL_var*)estate->datums[0]
$9 = {dtype = PLPGSQL_DTYPE_VAR, dno = 0, refname = 0x17107c0 "found", lineno = 0,
isconst = false, notnull = false, default_val = 0x0, datatype = 0x17106b0,
cursor_explicit_expr = 0x0, cursor_explicit_argrow = 0, cursor_options = 0,
value = 0, isnull = false, freeval = false, promise = PLPGSQL_PROMISE_NONE}
(gdb) p *(PLpgSQL_var*)estate->datums[1]
$10 = {dtype = PLPGSQL_DTYPE_VAR, dno = 1, refname = 0x1711518 "a1", lineno = 3,
isconst = false, notnull = false, default_val = 0x0, datatype = 0x1711408,
cursor_explicit_expr = 0x0, cursor_explicit_argrow = 0, cursor_options = 0,
value = 10, isnull = false, freeval = false, promise = PLPGSQL_PROMISE_NONE}
(gdb) p *(PLpgSQL_var*)estate->datums[2]
$11 = {dtype = PLPGSQL_DTYPE_VAR, dno = 2, refname = 0x1711e20 "a3", lineno = 4,
isconst = false, notnull = false, default_val = 0x0, datatype = 0x1711d10,
cursor_explicit_expr = 0x0, cursor_explicit_argrow = 0, cursor_options = 0,
value = 0, isnull = true, freeval = false, promise = PLPGSQL_PROMISE_NONE}
(gdb) p *expr
$13 = {query = 0x1712178 "call p1(a1, 20, a3)", parseMode = RAW_PARSE_DEFAULT,
plan = 0x0, paramnos = 0x0, func = 0x0, ns = 0x1711e40, expr_simple_expr = 0x0,
expr_simple_type = 0, expr_simple_typmod = 0, expr_simple_mutable = false,
target_param = -1, expr_rw_param = 0x0, expr_simple_plansource = 0x0,
expr_simple_plan = 0x0, expr_simple_plan_lxid = 0, expr_simple_state = 0x0,
expr_simple_in_use = false, expr_simple_lxid = 0}
相关文章
- Postgresql源码(75)notify与listen执行流程分析
- Postgresql源码(79)plpgsql中多层调用时参数传递关键点分析(pl参数)
- Postgresql源码(68)virtualxid锁的原理和应用场景
- Postgresql源码(83)执行器的结果接收系统——DestReceiver
- Postgresql源码(101)深入分析clog组提交(clog group updates)
- POSTGRESQL lightweight lock 轻量级锁是什么 ?
- Postgresql源码(94)SPI模块拆解分析二:SPI内存生命周期分析
- Postgresql源码(97)returns setof函数分析(oracle管道函数pipelined)
- PostgreSQL 2022 调查结果发布:全球排名第四的背后是开源的力量
- PostgreSQL出现死锁该如何解决
- 详解postgresql无序uuid性能测试及对数据库的影响
- 教你Linux 如何定时备份postgresql 数据库
- postgresql 数据库基础 之 索引 hash的使用介绍
- Postgresql的pl/pgql使用操作–将多条执行语句作为一个事务
- PostgreSQL中的OID和XID 说明
- Windows PostgreSQL 安装图文教程
- PostgreSQL 2B000: dependent_privilege_descriptors_still_exist 报错 故障修复 远程处理
- PostgreSQL 39004: null_value_not_allowed 报错 故障修复 远程处理
- PostgreSQL更新和删除详解数据库
- PostgreSQL体系基本概念详解数据库
- 索引索引PostgreSQL数组:极大提高查询性能.(postgresql数组)
- 比较PostgreSQL与Oracle的异同(postgresql和oracle)
- 快速学会PostgreSQL中导入SQL文件(postgresql导入sql文件)
- 请聆听:Postgresql发音(postgresql发音)
- 份使用PostgreSQL实现高效的热备份(postgresql热备)
- 基于Zabbix的PostgreSQL数据库监控(zabbix监控postgresql)
- 初探PostgreSQL:走上NoSQL学习之路(postgresql学习)
- PostgreSQL论坛:聚焦数据库技术分享与交流!(postgresql论坛)
- 管理Postgresql版本管理:实现更加高效的工作(postgresql版本)
- 新手快速登录Postgresql数据库(登录postgresql)
- 管理PostgreSQL:优化内存管理提升数据库性能(postgresql内存)