当前位置:   article > 正文

Postgresql源码(113)表达式JIT计算简单分析_postgresql的jit

postgresql的jit

相关
《Postgresql源码(85)查询执行——表达式解析器分析(select 1+1如何执行)》
《Postgresql源码(113)表达式JIT计算简单分析》

1 普通表达式计算

普通表达式计算发生在优化器preprocess_expression中,会先把能算出来的函数都计算一遍,把值添加到plan中。

#0  ExecInterpExpr (state=0x16188b8, econtext=0x1618df8, isnull=0x7ffcbbb1b6af) at execExprInterp.c:508
#1  0x000000000072b06f in ExecInterpExprStillValid (state=0x16188b8, econtext=0x1618df8, isNull=0x7ffcbbb1b6af) at execExprInterp.c:1870
#2  0x00000000008abc53 in ExecEvalExprSwitchContext (state=0x16188b8, econtext=0x1618df8, isNull=0x7ffcbbb1b6af) at ../../../../src/include/executor/executor.h:355
#3  0x00000000008b33d5 in evaluate_expr (expr=0x15524d8, result_type=23, result_typmod=-1, result_collation=0) at clauses.c:4902
#4  0x00000000008b26f8 in evaluate_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args=0x1552438, funcvariadic=false,
    func_tuple=0x7f8ed3ebc3f8, context=0x7ffcbbb1ccb0) at clauses.c:4409
#5  0x00000000008b1a47 in simplify_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args_p=0x7ffcbbb1b8c8, funcvariadic=false,
    process_args=true, allow_non_const=true, context=0x7ffcbbb1ccb0) at clauses.c:3997
#6  0x00000000008af028 in eval_const_expressions_mutator (node=0x1521488, context=0x7ffcbbb1ccb0) at clauses.c:2551
#7  0x00000000007e7ed9 in expression_tree_mutator_impl (node=0x15214d8, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffcbbb1ccb0) at nodeFuncs.c:3298
#8  0x00000000008b13ec in eval_const_expressions_mutator (node=0x15214d8, context=0x7ffcbbb1ccb0) at clauses.c:3616
#9  0x00000000007e82e4 in expression_tree_mutator_impl (node=0x1521528, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffcbbb1ccb0) at nodeFuncs.c:3384
#10 0x00000000008b13ec in eval_const_expressions_mutator (node=0x1521528, context=0x7ffcbbb1ccb0) at clauses.c:3616
#11 0x00000000008ae720 in eval_const_expressions (root=0x1521648, node=0x1521528) at clauses.c:2183
#12 0x0000000000885d2a in preprocess_expression (root=0x1521648, expr=0x1521528, kind=1) at planner.c:1144
#13 0x0000000000885173 in subquery_planner (glob=0x1520e08, parse=0x1520f18, parent_root=0x0, hasRecursion=false, tuple_fraction=0) at planner.c:811
#14 0x0000000000884293 in standard_planner (parse=0x1520f18, query_string=0x151fe78 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at planner.c:413
#15 0x000000000088403a in planner (parse=0x1520f18, query_string=0x151fe78 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at planner.c:281
#16 0x00000000009b5ec0 in pg_plan_query (querytree=0x1520f18, query_string=0x151fe78 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at postgres.c:904
#17 0x00000000009b600c in pg_plan_queries (querytrees=0x15215f8, query_string=0x151fe78 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at postgres.c:996
#18 0x00000000009b638c in exec_simple_query (query_string=0x151fe78 "select 1000+abs(-10000)+100;") at postgres.c:1193
#19 0x00000000009bab95 in PostgresMain (dbname=0x15572f8 "postgres", username=0x151bad8 "mingjie") at postgres.c:4637
#20 0x00000000008f1d6d in BackendRun (port=0x154db80) at postmaster.c:4464
#21 0x00000000008f1706 in BackendStartup (port=0x154db80) at postmaster.c:4192
#22 0x00000000008edfd1 in ServerLoop () at postmaster.c:1782
#23 0x00000000008ed9a1 in PostmasterMain (argc=1, argv=0x1519a80) at postmaster.c:1466
#24 0x00000000007b8201 in main (argc=1, argv=0x1519a80) at main.c:198
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

1.1 计算select 1000+abs(-10000)+100;

select 1000+abs(-10000)+100;
  • 1

Query Tree
在这里插入图片描述
优化器处理:ExecInterpExpr过程
在这里插入图片描述

1.1.1 第一步计算abs(-10000)

ExecInterpExpr

(gdb) p	*state
$6 = {type = T_ExprState, 
  flags = 6 '\006', 
  resnull = false, resvalue = 0, resultslot = 0x0, 
  steps = 0x16189e8,
  evalfunc = 0x7288a3 <ExecInterpExpr>, 
  expr = 0x15522f8,                                 → 指向上面FuncExpr
  evalfunc_private = 0x7288a3 <ExecInterpExpr>,	
  steps_len = 2, 
  steps_alloc = 16, 
  parent = 0x0, 
  ext_params = 0x0, 
  innermost_caseval = 0x0, 
  innermost_casenull = 0x0,
  innermost_domainval =	0x0, 
  innermost_domainnull = 0x0}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

先看第0步,跳转到哪
第一步:EEOP_FUNCEXPR_STRICT
第二步:EEOP_DONE

(gdb) p/x state->steps[0]->opcode
$23 = 0x72914f
(gdb) p/x state->steps[1]->opcode
$30 = 0x72893a

(gdb) p reverse_dispatch_table
$24 = {
...
{opcode = 0x72893a <ExecInterpExpr+151>, op = EEOP_DONE},
{opcode = 0x72914f <ExecInterpExpr+2220>, op = EEOP_FUNCEXPR_STRICT}
...
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

当前分支所需数据

(gdb) p state->steps[0]->d.func
$14 = {finfo = 0x1618948, fcinfo_data = 0x1618998, fn_addr = 0xa51c5d <int4abs>, nargs = 1}
  • 1
  • 2

进入分支干活,计算abs(-10000)结果

		EEO_CASE(EEOP_FUNCEXPR_STRICT)
		{
			FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
			NullableDatum *args = fcinfo->args;
			int			nargs = op->d.func.nargs;
			Datum		d;

			/* strict function, so check for NULL args */
			for (int argno = 0; argno < nargs; argno++)
			{
				if (args[argno].isnull)
				{
					*op->resnull = true;
					goto strictfail;
				}
			}
			fcinfo->isnull = false;
			d = op->d.func.fn_addr(fcinfo);  // 用函数地址调用函数拿到结果
			*op->resvalue = d;
			*op->resnull = fcinfo->isnull;

	strictfail:
			EEO_NEXT();
		}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

(下面内存可参考《Postgresql源码(85)查询执行——表达式解析器分析(select 1+1如何执行)》
在回忆一下表达式计算ExecInterpExpr函数的过程,核心就是这个op也就是step,这个ExprEvalStep结构体在执行ExecInterpExpr时作为核心结构体中的数据传入,具体在ExprState→steps中保存,这是一个数据,每一个元素代表一次计算,由ExprEvalStep结构记录当前计算的内存:

在这里插入图片描述

1.1.2 第二步计算1000+10000

同上,注意上面第一步和现在的steps_len都是2,也就是都做一次计算。

就是说每次计算都是由eval_const_expressions_mutator遍历树时,发现function节点后,发生的。

(gdb) p *state
$31 = {type = T_ExprState, 
  flags = 6 '\006', 
  resnull = false, 
  resvalue = 0, 
  resultslot = 0x0, 
  steps = 0x16189e8, 
  evalfunc = 0x7288a3 <ExecInterpExpr>, 
  expr = 0x1552398,                 // FuncExpr->args = {Const{1000}, Const{10000}}
  evalfunc_private = 0x7288a3 <ExecInterpExpr>, 
  steps_len = 2, 
  steps_alloc = 16, 
  parent = 0x0, 
  ext_params = 0x0, 
  innermost_caseval = 0x0, 
  innermost_casenull = 0x0,
  innermost_domainval = 0x0, 
  innermost_domainnull = 0x0}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

1.1.3 第三步计算11000+100

同上

2 JIT表达式计算

2.1 计算select 1000+abs(-10000)+100;

第一次进入jit堆栈jit_compile_expr,state→expr = (FuncExpr)表示abs(-10000)

因为不是parent表达式,不再继续计算

#0  jit_compile_expr (state=0x1deae18) at jit.c:180
#1  0x000000000071fa6b in ExecReadyExpr (state=0x1deae18) at execExpr.c:874
#2  0x000000000071e60b in ExecInitExpr (node=0x1dfabb8, parent=0x0) at execExpr.c:152
#3  0x00000000008b3395 in evaluate_expr (expr=0x1dfabb8, result_type=23, result_typmod=-1, result_collation=0) at clauses.c:4892
#4  0x00000000008b26f8 in evaluate_function (funcid=1397, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args=0x1dfab68, funcvariadic=false, func_tuple=0x7fd9588871a8, context=0x7ffdd8867f20) at clauses.c:4409
#5  0x00000000008b1a47 in simplify_function (funcid=1397, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args_p=0x7ffdd8865960, funcvariadic=false, process_args=true, allow_non_const=true, context=0x7ffdd8867f20) at clauses.c:3997
#6  0x00000000008aee93 in eval_const_expressions_mutator (node=0x1cf92e8, context=0x7ffdd8867f20) at clauses.c:2503
#7  0x00000000007e82e4 in expression_tree_mutator_impl (node=0x1cf9338, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3384
#8  0x00000000008b1a05 in simplify_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args_p=0x7ffdd8866248, funcvariadic=false, process_args=true, allow_non_const=true, context=0x7ffdd8867f20) at clauses.c:3988
#9  0x00000000008af028 in eval_const_expressions_mutator (node=0x1cf9388, context=0x7ffdd8867f20) at clauses.c:2551
#10 0x00000000007e82e4 in expression_tree_mutator_impl (node=0x1cf9428, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3384
#11 0x00000000008b1a05 in simplify_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args_p=0x7ffdd8866b38, funcvariadic=false, process_args=true, allow_non_const=true, context=0x7ffdd8867f20) at clauses.c:3988
#12 0x00000000008af028 in eval_const_expressions_mutator (node=0x1cf9478, context=0x7ffdd8867f20) at clauses.c:2551
#13 0x00000000007e7ed9 in expression_tree_mutator_impl (node=0x1cf94c8, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3298
#14 0x00000000008b13ec in eval_const_expressions_mutator (node=0x1cf94c8, context=0x7ffdd8867f20) at clauses.c:3616
#15 0x00000000007e82e4 in expression_tree_mutator_impl (node=0x1cf9518, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3384
#16 0x00000000008b13ec in eval_const_expressions_mutator (node=0x1cf9518, context=0x7ffdd8867f20) at clauses.c:3616
#17 0x00000000008ae720 in eval_const_expressions (root=0x1cf9638, node=0x1cf9518) at clauses.c:2183
#18 0x0000000000885d2a in preprocess_expression (root=0x1cf9638, expr=0x1cf9518, kind=1) at planner.c:1144
#19 0x0000000000885173 in subquery_planner (glob=0x1cf8df8, parse=0x1cf8f08, parent_root=0x0, hasRecursion=false, tuple_fraction=0) at planner.c:811
#20 0x0000000000884293 in standard_planner (parse=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at planner.c:413
#21 0x000000000088403a in planner (parse=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at planner.c:281
#22 0x00000000009b5ec0 in pg_plan_query (querytree=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at postgres.c:904
#23 0x00000000009b600c in pg_plan_queries (querytrees=0x1cf95e8, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at postgres.c:996
#24 0x00000000009b638c in exec_simple_query (query_string=0x1cf7e68 "select 1000+abs(-10000)+100;") at postgres.c:1193
#25 0x00000000009bab95 in PostgresMain (dbname=0x1d2f2e8 "postgres", username=0x1cf3ac8 "mingjie") at postgres.c:4637
#26 0x00000000008f1d6d in BackendRun (port=0x1d25b70) at postmaster.c:4464
#27 0x00000000008f1706 in BackendStartup (port=0x1d25b70) at postmaster.c:4192
#28 0x00000000008edfd1 in ServerLoop () at postmaster.c:1782
#29 0x00000000008ed9a1 in PostmasterMain (argc=1, argv=0x1cf1a70) at postmaster.c:1466
#30 0x00000000007b8201 in main (argc=1, argv=0x1cf1a70) at main.c:198
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
第二次进入jit堆栈jit_compile_expr,state→expr = (FuncExpr)表示1000+10000

因为不是parent表达式,不再继续计算。

#0  jit_compile_expr (state=0x1deae18) at jit.c:165
#1  0x000000000071fa6b in ExecReadyExpr (state=0x1deae18) at execExpr.c:874
#2  0x000000000071e60b in ExecInitExpr (node=0x1dfac58, parent=0x0) at execExpr.c:152
#3  0x00000000008b3395 in evaluate_expr (expr=0x1dfac58, result_type=23, result_typmod=-1, result_collation=0) at clauses.c:4892
#4  0x00000000008b26f8 in evaluate_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args=0x1dfaac8, funcvariadic=false, func_tuple=0x7fd9588876b8, context=0x7ffdd8867f20) at clauses.c:4409
#5  0x00000000008b1a47 in simplify_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args_p=0x7ffdd8866248, funcvariadic=false, process_args=true, allow_non_const=true, context=0x7ffdd8867f20) at clauses.c:3997
#6  0x00000000008af028 in eval_const_expressions_mutator (node=0x1cf9388, context=0x7ffdd8867f20) at clauses.c:2551
#7  0x00000000007e82e4 in expression_tree_mutator_impl (node=0x1cf9428, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3384
#8  0x00000000008b1a05 in simplify_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args_p=0x7ffdd8866b38, funcvariadic=false, process_args=true, allow_non_const=true, context=0x7ffdd8867f20) at clauses.c:3988
#9  0x00000000008af028 in eval_const_expressions_mutator (node=0x1cf9478, context=0x7ffdd8867f20) at clauses.c:2551
#10 0x00000000007e7ed9 in expression_tree_mutator_impl (node=0x1cf94c8, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3298
#11 0x00000000008b13ec in eval_const_expressions_mutator (node=0x1cf94c8, context=0x7ffdd8867f20) at clauses.c:3616
#12 0x00000000007e82e4 in expression_tree_mutator_impl (node=0x1cf9518, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3384
#13 0x00000000008b13ec in eval_const_expressions_mutator (node=0x1cf9518, context=0x7ffdd8867f20) at clauses.c:3616
#14 0x00000000008ae720 in eval_const_expressions (root=0x1cf9638, node=0x1cf9518) at clauses.c:2183
#15 0x0000000000885d2a in preprocess_expression (root=0x1cf9638, expr=0x1cf9518, kind=1) at planner.c:1144
#16 0x0000000000885173 in subquery_planner (glob=0x1cf8df8, parse=0x1cf8f08, parent_root=0x0, hasRecursion=false, tuple_fraction=0) at planner.c:811
#17 0x0000000000884293 in standard_planner (parse=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at planner.c:413
#18 0x000000000088403a in planner (parse=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at planner.c:281
#19 0x00000000009b5ec0 in pg_plan_query (querytree=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at postgres.c:904
#20 0x00000000009b600c in pg_plan_queries (querytrees=0x1cf95e8, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at postgres.c:996
#21 0x00000000009b638c in exec_simple_query (query_string=0x1cf7e68 "select 1000+abs(-10000)+100;") at postgres.c:1193
#22 0x00000000009bab95 in PostgresMain (dbname=0x1d2f2e8 "postgres", username=0x1cf3ac8 "mingjie") at postgres.c:4637
#23 0x00000000008f1d6d in BackendRun (port=0x1d25b70) at postmaster.c:4464
#24 0x00000000008f1706 in BackendStartup (port=0x1d25b70) at postmaster.c:4192
#25 0x00000000008edfd1 in ServerLoop () at postmaster.c:1782
#26 0x00000000008ed9a1 in PostmasterMain (argc=1, argv=0x1cf1a70) at postmaster.c:1466
#27 0x00000000007b8201 in main (argc=1, argv=0x1cf1a70) at main.c:198
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
第三次进入jit堆栈jit_compile_expr,state→expr = (FuncExpr)表示11000+100

因为不是parent表达式,不再继续计算。

#0  jit_compile_expr (state=0x1deae18) at jit.c:165
#1  0x000000000071fa6b in ExecReadyExpr (state=0x1deae18) at execExpr.c:874
#2  0x000000000071e60b in ExecInitExpr (node=0x1dfad98, parent=0x0) at execExpr.c:152
#3  0x00000000008b3395 in evaluate_expr (expr=0x1dfad98, result_type=23, result_typmod=-1, result_collation=0) at clauses.c:4892
#4  0x00000000008b26f8 in evaluate_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args=0x1dfacf8, funcvariadic=false, func_tuple=0x7fd9588876b8, context=0x7ffdd8867f20) at clauses.c:4409
#5  0x00000000008b1a47 in simplify_function (funcid=177, result_type=23, result_typmod=-1, result_collid=0, input_collid=0, args_p=0x7ffdd8866b38, funcvariadic=false, process_args=true, allow_non_const=true, context=0x7ffdd8867f20) at clauses.c:3997
#6  0x00000000008af028 in eval_const_expressions_mutator (node=0x1cf9478, context=0x7ffdd8867f20) at clauses.c:2551
#7  0x00000000007e7ed9 in expression_tree_mutator_impl (node=0x1cf94c8, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3298
#8  0x00000000008b13ec in eval_const_expressions_mutator (node=0x1cf94c8, context=0x7ffdd8867f20) at clauses.c:3616
#9  0x00000000007e82e4 in expression_tree_mutator_impl (node=0x1cf9518, mutator=0x8ae95b <eval_const_expressions_mutator>, context=0x7ffdd8867f20) at nodeFuncs.c:3384
#10 0x00000000008b13ec in eval_const_expressions_mutator (node=0x1cf9518, context=0x7ffdd8867f20) at clauses.c:3616
#11 0x00000000008ae720 in eval_const_expressions (root=0x1cf9638, node=0x1cf9518) at clauses.c:2183
#12 0x0000000000885d2a in preprocess_expression (root=0x1cf9638, expr=0x1cf9518, kind=1) at planner.c:1144
#13 0x0000000000885173 in subquery_planner (glob=0x1cf8df8, parse=0x1cf8f08, parent_root=0x0, hasRecursion=false, tuple_fraction=0) at planner.c:811
#14 0x0000000000884293 in standard_planner (parse=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at planner.c:413
#15 0x000000000088403a in planner (parse=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at planner.c:281
#16 0x00000000009b5ec0 in pg_plan_query (querytree=0x1cf8f08, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at postgres.c:904
#17 0x00000000009b600c in pg_plan_queries (querytrees=0x1cf95e8, query_string=0x1cf7e68 "select 1000+abs(-10000)+100;", cursorOptions=2048, boundParams=0x0) at postgres.c:996
#18 0x00000000009b638c in exec_simple_query (query_string=0x1cf7e68 "select 1000+abs(-10000)+100;") at postgres.c:1193
#19 0x00000000009bab95 in PostgresMain (dbname=0x1d2f2e8 "postgres", username=0x1cf3ac8 "mingjie") at postgres.c:4637
#20 0x00000000008f1d6d in BackendRun (port=0x1d25b70) at postmaster.c:4464
#21 0x00000000008f1706 in BackendStartup (port=0x1d25b70) at postmaster.c:4192
#22 0x00000000008edfd1 in ServerLoop () at postmaster.c:1782
#23 0x00000000008ed9a1 in PostmasterMain (argc=1, argv=0x1cf1a70) at postmaster.c:1466
#24 0x00000000007b8201 in main (argc=1, argv=0x1cf1a70) at main.c:198
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
第四次进入jit堆栈jit_compile_expr,state→expr = (List)记录TargetEntry

TargetEntry的expr记录结果11100

{ xpr = {type = T_TargetEntry}, 
  expr = Const{constvalue = 11100} ,
  resno = 1, 
  resname = 0xcbfb88 "?column?", 
  ressortgroupref = 0, 
  resorigtbl = 0, 
  resorigcol = 0, 
  resjunk = false}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

进入jit_compile_expr→llvm_compile_expr开始编译表达式

#0  llvm_compile_expr (state=0x1deb218) at llvmjit_expr.c:80
#1  0x0000000000bd3698 in jit_compile_expr (state=0x1deb218) at jit.c:177
#2  0x000000000071fa6b in ExecReadyExpr (state=0x1deb218) at execExpr.c:874
#3  0x000000000071eecb in ExecBuildProjectionInfo (targetList=0x1dfb890, econtext=0x1deaf40, slot=0x1deb130, parent=0x1deae30, inputDesc=0x0) at execExpr.c:479
#4  0x0000000000749d1b in ExecAssignProjectionInfo (planstate=0x1deae30, inputDesc=0x0) at execUtils.c:547
#5  0x00000000007827d0 in ExecInitResult (node=0x1dfb7b0, estate=0x1deac08, eflags=32) at nodeResult.c:221
#6  0x00000000007403d1 in ExecInitNode (node=0x1dfb7b0, estate=0x1deac08, eflags=32) at execProcnode.c:167
#7  0x0000000000735daf in InitPlan (queryDesc=0x1d1fb98, eflags=32) at execMain.c:968
#8  0x0000000000734c85 in standard_ExecutorStart (queryDesc=0x1d1fb98, eflags=32) at execMain.c:266
#9  0x00000000007349fa in ExecutorStart (queryDesc=0x1d1fb98, eflags=0) at execMain.c:145
#10 0x00000000009bc3dc in PortalStart (portal=0x1da1368, params=0x0, eflags=0, snapshot=0x0) at pquery.c:517
#11 0x00000000009b6419 in exec_simple_query (query_string=0x1cf7e68 "select 1000+abs(-10000)+100;") at postgres.c:1235
#12 0x00000000009bab95 in PostgresMain (dbname=0x1d2f2e8 "postgres", username=0x1cf3ac8 "mingjie") at postgres.c:4637
#13 0x00000000008f1d6d in BackendRun (port=0x1d25b70) at postmaster.c:4464
#14 0x00000000008f1706 in BackendStartup (port=0x1d25b70) at postmaster.c:4192
#15 0x00000000008edfd1 in ServerLoop () at postmaster.c:1782
#16 0x00000000008ed9a1 in PostmasterMain (argc=1, argv=0x1cf1a70) at postmaster.c:1466
#17 0x00000000007b8201 in main (argc=1, argv=0x1cf1a70) at main.c:198
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

llvm_compile_expr函数从功能来看是严格对标ExecInterpExpr表达式计算的,例如计算函数表达式的结果EEOP_FUNCEXPR_STRICT分支:
在这里插入图片描述

4 用例

set max_parallel_workers_per_gather to 0;
set jit_expressions to on;
set jit_tuple_deforming to on;
set jit_above_cost to 0;
set jit_inline_above_cost to 0;
set jit_optimize_above_cost to 0;
explain analyze select abs(-10000)+1000+100;
select 1000+abs(-10000)+100;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/573069
推荐阅读
相关标签
  

闽ICP备14008679号