The JIT compiled implementation missed maintaining
AggState->{current_set,curaggcontext}. That could lead to trouble
because the transition value could be allocated in the wrong context.
Reported-By: Rushabh Lathia
Diagnosed-By: Dmitry Dolgov
Author: Dmitry Dolgov, with minor changes by me
Discussion: https://postgr.es/m/CAGPqQf165-=+Drw3Voim7M5EjHT1zwPF9BQRjLFQzCzYnNZEiQ@mail.gmail.com
Backpatch: 11-, where JIT compilation support was added
{
LLVMValueRef params[3];
+ LLVMValueRef v_curaggcontext;
+ LLVMValueRef v_current_set;
+ LLVMValueRef v_aggcontext;
+
+ v_aggcontext = l_ptr_const(op->d.agg_init_trans.aggcontext,
+ l_ptr(StructExprContext));
+
+ v_current_set =
+ LLVMBuildStructGEP(b,
+ v_aggstatep,
+ FIELDNO_AGGSTATE_CURRENT_SET,
+ "aggstate.current_set");
+ v_curaggcontext =
+ LLVMBuildStructGEP(b,
+ v_aggstatep,
+ FIELDNO_AGGSTATE_CURAGGCONTEXT,
+ "aggstate.curaggcontext");
+
+ LLVMBuildStore(b, l_int32_const(op->d.agg_init_trans.setno),
+ v_current_set);
+ LLVMBuildStore(b, v_aggcontext,
+ v_curaggcontext);
params[0] = v_aggstatep;
params[1] = v_pertransp;