Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf4f5845

Browse files
committed
Quick adaption of JIT tuple deforming to the fast default patch.
Instead using memset to set tts_isnull, call the newslot_getmissingattrs().Also fix a bug (= instead of >=) in the code generation. Normally = iscorrect, but when repeatedly deforming fields not in atuple (e.g. deform up to natts + 1 and then natts + 2) >= is needed.Discussion:https://postgr.es/m/20180328010053.i2qvsuuusst4lgmc@alap3.anarazel.de
1 parentb4013b8 commitf4f5845

File tree

6 files changed

+41
-57
lines changed

6 files changed

+41
-57
lines changed

‎src/backend/access/common/heaptuple.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ getmissingattr(TupleDesc tupleDesc,
112112
}
113113

114114
/*
115-
* Fill in missing values for a TupleTableSlot
115+
* Fill in missing values for a TupleTableSlot.
116+
*
117+
* This is only exposed because it's needed for JIT compiled tuple
118+
* deforming. That exception aside, there should be no callers outside of this
119+
* file.
116120
*/
117-
staticvoid
121+
void
118122
slot_getmissingattrs(TupleTableSlot*slot,intstartAttNum,intlastAttNum)
119123
{
120124
AttrMissing*attrmiss=NULL;

‎src/backend/jit/llvm/llvmjit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ LLVMValueRef AttributeTemplate;
7676
LLVMValueRefFuncStrlen;
7777
LLVMValueRefFuncVarsizeAny;
7878
LLVMValueRefFuncSlotGetsomeattrs;
79+
LLVMValueRefFuncSlotGetmissingattrs;
7980
LLVMValueRefFuncHeapGetsysattr;
8081
LLVMValueRefFuncMakeExpandedObjectReadOnlyInternal;
8182
LLVMValueRefFuncExecEvalArrayRefSubscript;
@@ -798,6 +799,7 @@ llvm_create_types(void)
798799
FuncStrlen=LLVMGetNamedFunction(mod,"strlen");
799800
FuncVarsizeAny=LLVMGetNamedFunction(mod,"varsize_any");
800801
FuncSlotGetsomeattrs=LLVMGetNamedFunction(mod,"slot_getsomeattrs");
802+
FuncSlotGetmissingattrs=LLVMGetNamedFunction(mod,"slot_getmissingattrs");
801803
FuncHeapGetsysattr=LLVMGetNamedFunction(mod,"heap_getsysattr");
802804
FuncMakeExpandedObjectReadOnlyInternal=LLVMGetNamedFunction(mod,"MakeExpandedObjectReadOnlyInternal");
803805
FuncExecEvalArrayRefSubscript=LLVMGetNamedFunction(mod,"ExecEvalArrayRefSubscript");

‎src/backend/jit/llvm/llvmjit_deform.c

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
#include<llvm-c/Core.h>
2222

2323
#include"access/htup_details.h"
24+
#include"access/tupdesc_details.h"
2425
#include"executor/tuptable.h"
2526
#include"jit/llvmjit.h"
2627
#include"jit/llvmjit_emit.h"
2728

2829

29-
staticLLVMValueRefget_memset(LLVMModuleRefmod);
30-
31-
3230
/*
3331
* Create a function that deforms a tuple of type desc up to natts columns.
3432
*/
@@ -100,10 +98,23 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
10098
*/
10199
for (attnum=0;attnum<desc->natts;attnum++)
102100
{
103-
if (TupleDescAttr(desc,attnum)->attnotnull)
104-
{
101+
Form_pg_attributeatt=TupleDescAttr(desc,attnum);
102+
103+
/*
104+
* If the column is possibly missing, we can't rely on its (or
105+
* subsequent) NOT NULL constraints to indicate minimum attributes in
106+
* the tuple, so stop here.
107+
*/
108+
if (att->atthasmissing)
109+
break;
110+
111+
/*
112+
* Column is NOT NULL and there've been no preceding missing columns,
113+
* it's guaranteed that all columns up to here exist at least in the
114+
* NULL bitmap.
115+
*/
116+
if (att->attnotnull)
105117
guaranteed_column_number=attnum;
106-
}
107118
}
108119

109120
/* Create the signature and function */
@@ -242,9 +253,8 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
242253

243254
/*
244255
* Check if's guaranteed the all the desired attributes are available in
245-
* tuple. If so, we can start deforming. If not, need to make sure
246-
* tts_values/isnull is set appropriately for columns not available in the
247-
* tuple.
256+
* tuple. If so, we can start deforming. If not, need to make sure to
257+
* fetch the missing columns.
248258
*/
249259
if ((natts-1) <=guaranteed_column_number)
250260
{
@@ -255,9 +265,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
255265
}
256266
else
257267
{
258-
LLVMValueRefv_set;
259-
LLVMValueRefv_startset;
260-
LLVMValueRefv_params[5];
268+
LLVMValueRefv_params[3];
261269

262270
/* branch if not all columns available */
263271
LLVMBuildCondBr(b,
@@ -271,19 +279,10 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
271279
/* if not, memset tts_isnull of relevant cols to true */
272280
LLVMPositionBuilderAtEnd(b,b_adjust_unavail_cols);
273281

274-
v_set=LLVMBuildSub(b,
275-
l_int16_const(attnum),
276-
v_maxatt,"");
277-
278-
v_startset=LLVMBuildGEP(b,v_tts_nulls,&v_maxatt,1,"");
279-
280-
v_params[0]=v_startset;
281-
v_params[1]=l_int8_const(1);
282-
v_params[2]=LLVMBuildZExt(b,v_set,LLVMInt32Type(),"");
283-
v_params[3]=l_int32_const(1);
284-
v_params[4]=LLVMConstInt(LLVMInt1Type(),0, false);
285-
286-
LLVMBuildCall(b,get_memset(mod),
282+
v_params[0]=v_slot;
283+
v_params[1]=LLVMBuildZExt(b,v_maxatt,LLVMInt32Type(),"");
284+
v_params[2]=l_int32_const(natts);
285+
LLVMBuildCall(b,llvm_get_decl(mod,FuncSlotGetmissingattrs),
287286
v_params,lengthof(v_params),"");
288287
LLVMBuildBr(b,b_find_start);
289288
}
@@ -358,15 +357,19 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
358357
{
359358
LLVMValueRefv_islast;
360359

361-
v_islast=LLVMBuildICmp(b,LLVMIntEQ,
360+
v_islast=LLVMBuildICmp(b,LLVMIntUGE,
362361
l_attno,
363362
v_maxatt,
364363
"heap_natts");
365364
LLVMBuildCondBr(b,v_islast,b_out,attstartblocks[attnum]);
366365
}
367366
LLVMPositionBuilderAtEnd(b,attstartblocks[attnum]);
368367

369-
/* check for nulls if necessary */
368+
/*
369+
* Check for nulls if necessary. No need to take missing attributes
370+
* into account, because in case they're present the heaptuple's natts
371+
* would have indicated that a slot_getmissingattrs() is needed.
372+
*/
370373
if (!att->attnotnull)
371374
{
372375
LLVMBasicBlockRefb_ifnotnull;
@@ -699,31 +702,3 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, int natts)
699702

700703
returnv_deform_fn;
701704
}
702-
703-
staticLLVMValueRef
704-
get_memset(LLVMModuleRefmod)
705-
{
706-
LLVMTypeRefsig;
707-
LLVMValueRefv_fn;
708-
LLVMTypeRefparam_types[5];
709-
constchar*nm="llvm.memset.p0i8.i32";
710-
711-
v_fn=LLVMGetNamedFunction(mod,nm);
712-
if (v_fn)
713-
returnv_fn;
714-
715-
param_types[0]=LLVMPointerType(LLVMInt8Type(),0);/* addr */
716-
param_types[1]=LLVMInt8Type();/* val */
717-
param_types[2]=LLVMInt32Type();/* len */
718-
param_types[3]=LLVMInt32Type();/* align */
719-
param_types[4]=LLVMInt1Type();/* volatile */
720-
721-
sig=LLVMFunctionType(LLVMVoidType(),param_types,lengthof(param_types),0);
722-
v_fn=LLVMAddFunction(mod,nm,sig);
723-
724-
LLVMSetFunctionCallConv(v_fn,LLVMCCallConv);
725-
726-
Assert(LLVMGetIntrinsicID(v_fn));
727-
728-
returnv_fn;
729-
}

‎src/backend/jit/llvm/llvmjit_types.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void *referenced_functions[] =
9898
strlen,
9999
varsize_any,
100100
slot_getsomeattrs,
101+
slot_getmissingattrs,
101102
heap_getsysattr,
102103
MakeExpandedObjectReadOnlyInternal,
103104
ExecEvalArrayRefSubscript,

‎src/include/executor/tuptable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,6 @@ extern void slot_getsomeattrs(TupleTableSlot *slot, int attnum);
179179
externboolslot_attisnull(TupleTableSlot*slot,intattnum);
180180
externboolslot_getsysattr(TupleTableSlot*slot,intattnum,
181181
Datum*value,bool*isnull);
182+
externvoidslot_getmissingattrs(TupleTableSlot*slot,intstartAttNum,intlastAttNum);
182183

183184
#endif/* TUPTABLE_H */

‎src/include/jit/llvmjit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extern LLVMValueRef AttributeTemplate;
7878
externLLVMValueRefFuncStrlen;
7979
externLLVMValueRefFuncVarsizeAny;
8080
externLLVMValueRefFuncSlotGetsomeattrs;
81+
externLLVMValueRefFuncSlotGetmissingattrs;
8182
externLLVMValueRefFuncHeapGetsysattr;
8283
externLLVMValueRefFuncMakeExpandedObjectReadOnlyInternal;
8384
externLLVMValueRefFuncExecEvalArrayRefSubscript;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp