Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a7aa608

Browse files
committed
Inline hot path of slot_getsomeattrs().
This yields a minor speedup, which roughly balances the loss from the upcoming introduction of callbacks to do some operations on slots. Author: Andres Freund Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
1 parent 3f2393e commit a7aa608

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, int attnum)
1189+
slot_getsomeattrs_int(TupleTableSlot *slot, int attnum)
11921190
{
11931191
HeapTuple tuple;
11941192
int attno;
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 have all the atts indicated by attnum, read the rest
1224-
* as NULLs or missing values
1218+
* If the underlying tuple doesn't have enough attributes, tuple descriptor
1219+
* must have the missing attributes.
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
LLVMValueRef AttributeTemplate;
8080
LLVMValueRef FuncStrlen;
8181
LLVMValueRef FuncVarsizeAny;
82-
LLVMValueRef FuncSlotGetsomeattrs;
82+
LLVMValueRef FuncSlotGetsomeattrsInt;
8383
LLVMValueRef FuncSlotGetmissingattrs;
8484
LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal;
8585
LLVMValueRef FuncExecEvalArrayRefSubscript;
@@ -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
int lastAttNum);
220220
extern Datum slot_getattr(TupleTableSlot *slot, int attnum,
221221
bool *isnull);
222-
extern void slot_getsomeattrs(TupleTableSlot *slot, int attnum);
223222

224223
/* in access/common/heaptuple.c */
225224
extern bool slot_attisnull(TupleTableSlot *slot, int attnum);
226225
extern bool slot_getsysattr(TupleTableSlot *slot, int attnum,
227226
Datum *value, bool *isnull);
228227
extern Datum getmissingattr(TupleDesc tupleDesc,
229228
int attnum, bool *isnull);
229+
extern void slot_getsomeattrs_int(TupleTableSlot *slot, int attnum);
230230

231231
#ifndef FRONTEND
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+
static inline void
238+
slot_getsomeattrs(TupleTableSlot *slot, int attnum)
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
extern LLVMValueRef AttributeTemplate;
7878
extern LLVMValueRef FuncStrlen;
7979
extern LLVMValueRef FuncVarsizeAny;
80-
extern LLVMValueRef FuncSlotGetsomeattrs;
8180
extern LLVMValueRef FuncSlotGetmissingattrs;
81+
extern LLVMValueRef FuncSlotGetsomeattrsInt;
8282
extern LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal;
8383
extern LLVMValueRef FuncExecEvalArrayRefSubscript;
8484
extern LLVMValueRef FuncExecEvalSysVar;

0 commit comments

Comments
 (0)