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

Commita7aa608

Browse files
committed
Inline hot path of slot_getsomeattrs().
This yields a minor speedup, which roughly balances the loss from theupcoming introduction of callbacks to do some operations on slots.Author: Andres FreundDiscussion:https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
1 parent3f2393e commita7aa608

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

‎src/backend/executor/execExprInterp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
428428
{
429429
CheckOpSlotCompatibility(op,innerslot);
430430

431-
/* XXX: worthwhile to check tts_nvalid inline first? */
432431
slot_getsomeattrs(innerslot,op->d.fetch.last_var);
433432

434433
EEO_NEXT();

‎src/backend/executor/execTuples.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,22 +1183,19 @@ slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
11831183
}
11841184

11851185
/*
1186-
* slot_getsomeattrs
1187-
*This function forces the entries of the slot's Datum/isnull
1188-
*arrays to be valid at least up through the attnum'th entry.
1186+
* slot_getsomeattrs_int - workhorse for slot_getsomeattrs()
11891187
*/
11901188
void
1191-
slot_getsomeattrs(TupleTableSlot*slot,intattnum)
1189+
slot_getsomeattrs_int(TupleTableSlot*slot,intattnum)
11921190
{
11931191
HeapTupletuple;
11941192
intattno;
11951193

1196-
/*Quick out if we have 'em all already */
1197-
if(slot->tts_nvalid>=attnum)
1198-
return;
1194+
/*Check for caller errors */
1195+
Assert(slot->tts_nvalid<attnum);/* slot_getsomeattr checked */
1196+
Assert(attnum>0);
11991197

1200-
/* Check for caller error */
1201-
if (attnum <=0||attnum>slot->tts_tupleDescriptor->natts)
1198+
if (unlikely(attnum>slot->tts_tupleDescriptor->natts))
12021199
elog(ERROR,"invalid attribute number %d",attnum);
12031200

12041201
/*
@@ -1209,9 +1206,7 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum)
12091206
if (tuple==NULL)/* internal error */
12101207
elog(ERROR,"cannot extract attribute from empty tuple slot");
12111208

1212-
/*
1213-
* load up any slots available from physical tuple
1214-
*/
1209+
/* Fetch as many attributes as possible from the underlying tuple. */
12151210
attno=HeapTupleHeaderGetNatts(tuple->t_data);
12161211
attno=Min(attno,attnum);
12171212

@@ -1220,13 +1215,14 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum)
12201215
attno=slot->tts_nvalid;
12211216

12221217
/*
1223-
* If tuple doesn't haveall the atts indicated by attnum, read the rest
1224-
*as NULLs or missingvalues
1218+
* Ifthe underlyingtuple doesn't haveenough attributes, tuple descriptor
1219+
*must have the missingattributes.
12251220
*/
1226-
if (attno<attnum)
1227-
slot_getmissingattrs(slot,attno,attnum);
1228-
1229-
slot->tts_nvalid=attnum;
1221+
if (unlikely(slot->tts_nvalid<attnum))
1222+
{
1223+
slot_getmissingattrs(slot,slot->tts_nvalid,attnum);
1224+
slot->tts_nvalid=attnum;
1225+
}
12301226
}
12311227

12321228
/* ----------------------------------------------------------------

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ LLVMTypeRef StructAggStatePerTransData;
7979
LLVMValueRefAttributeTemplate;
8080
LLVMValueRefFuncStrlen;
8181
LLVMValueRefFuncVarsizeAny;
82-
LLVMValueRefFuncSlotGetsomeattrs;
82+
LLVMValueRefFuncSlotGetsomeattrsInt;
8383
LLVMValueRefFuncSlotGetmissingattrs;
8484
LLVMValueRefFuncMakeExpandedObjectReadOnlyInternal;
8585
LLVMValueRefFuncExecEvalArrayRefSubscript;
@@ -820,7 +820,7 @@ llvm_create_types(void)
820820
AttributeTemplate=LLVMGetNamedFunction(mod,"AttributeTemplate");
821821
FuncStrlen=LLVMGetNamedFunction(mod,"strlen");
822822
FuncVarsizeAny=LLVMGetNamedFunction(mod,"varsize_any");
823-
FuncSlotGetsomeattrs=LLVMGetNamedFunction(mod,"slot_getsomeattrs");
823+
FuncSlotGetsomeattrsInt=LLVMGetNamedFunction(mod,"slot_getsomeattrs_int");
824824
FuncSlotGetmissingattrs=LLVMGetNamedFunction(mod,"slot_getmissingattrs");
825825
FuncMakeExpandedObjectReadOnlyInternal=LLVMGetNamedFunction(mod,"MakeExpandedObjectReadOnlyInternal");
826826
FuncExecEvalArrayRefSubscript=LLVMGetNamedFunction(mod,"ExecEvalArrayRefSubscript");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ llvm_compile_expr(ExprState *state)
345345
params[1]=l_int32_const(op->d.fetch.last_var);
346346

347347
LLVMBuildCall(b,
348-
llvm_get_decl(mod,FuncSlotGetsomeattrs),
348+
llvm_get_decl(mod,FuncSlotGetsomeattrsInt),
349349
params,lengthof(params),"");
350350
}
351351

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void *referenced_functions[] =
9797
{
9898
strlen,
9999
varsize_any,
100-
slot_getsomeattrs,
100+
slot_getsomeattrs_int,
101101
slot_getmissingattrs,
102102
MakeExpandedObjectReadOnlyInternal,
103103
ExecEvalArrayRefSubscript,

‎src/include/executor/tuptable.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,28 @@ extern void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum,
219219
intlastAttNum);
220220
externDatumslot_getattr(TupleTableSlot*slot,intattnum,
221221
bool*isnull);
222-
externvoidslot_getsomeattrs(TupleTableSlot*slot,intattnum);
223222

224223
/* in access/common/heaptuple.c */
225224
externboolslot_attisnull(TupleTableSlot*slot,intattnum);
226225
externboolslot_getsysattr(TupleTableSlot*slot,intattnum,
227226
Datum*value,bool*isnull);
228227
externDatumgetmissingattr(TupleDesctupleDesc,
229228
intattnum,bool*isnull);
229+
externvoidslot_getsomeattrs_int(TupleTableSlot*slot,intattnum);
230230

231231
#ifndefFRONTEND
232232

233+
/*
234+
* This function forces the entries of the slot's Datum/isnull arrays to be
235+
* valid at least up through the attnum'th entry.
236+
*/
237+
staticinlinevoid
238+
slot_getsomeattrs(TupleTableSlot*slot,intattnum)
239+
{
240+
if (slot->tts_nvalid<attnum)
241+
slot_getsomeattrs_int(slot,attnum);
242+
}
243+
233244
/*
234245
* slot_getallattrs
235246
*This function forces all the entries of the slot's Datum/isnull

‎src/include/jit/llvmjit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ extern LLVMTypeRef StructAggStatePerGroupData;
7777
externLLVMValueRefAttributeTemplate;
7878
externLLVMValueRefFuncStrlen;
7979
externLLVMValueRefFuncVarsizeAny;
80-
externLLVMValueRefFuncSlotGetsomeattrs;
8180
externLLVMValueRefFuncSlotGetmissingattrs;
81+
externLLVMValueRefFuncSlotGetsomeattrsInt;
8282
externLLVMValueRefFuncMakeExpandedObjectReadOnlyInternal;
8383
externLLVMValueRefFuncExecEvalArrayRefSubscript;
8484
externLLVMValueRefFuncExecEvalSysVar;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp