前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Postgresql源码(78)plpgsql中调用call proc()时的参数传递和赋值(pl参数)

Postgresql源码(78)plpgsql中调用call proc()时的参数传递和赋值(pl参数)

作者头像
mingjie
发布2022-09-26 21:53:28
1.1K0
发布2022-09-26 21:53:28
举报
文章被收录于专栏:Postgresql源码分析

《Postgresql源码(77)plpgsql中参数传递和赋值(pl参数)》 《Postgresql源码(78)plpgsql中调用call proc()时的参数传递和赋值(pl参数)》

总结

  • 调用者在exec_stmt_call中拼接ParamListInfo传给SPI去执行call xxxx命令。
  • ParamListInfo记录了PL的一些回调函数,在SPI会走到:ExecuteCallStmt
  • ExecuteCallStmt核心流程两步:undefined 1. 拼参数列表:会拿到所有入参 - 假设第一个入参是Param类型,会回调PL的plpgsql_param_fetch函数,从PL的Datums中拿变量的值赋值给fcinfo->args0 - 假设第二个入参是Const类型常量,则会直接在执行器内赋值给fcinfo->args[1] 1. 走FunctionCallInvoke进入plpgsql_exec_functions开始执行被调用函数。

实验用例

代码语言:javascript
复制
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
代码语言:javascript
复制
(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}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-09-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 总结
  • 实验用例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档