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
This commit is contained in:
parent
3f2393edef
commit
a7aa608e0f
@ -428,7 +428,6 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
|
|||||||
{
|
{
|
||||||
CheckOpSlotCompatibility(op, innerslot);
|
CheckOpSlotCompatibility(op, innerslot);
|
||||||
|
|
||||||
/* XXX: worthwhile to check tts_nvalid inline first? */
|
|
||||||
slot_getsomeattrs(innerslot, op->d.fetch.last_var);
|
slot_getsomeattrs(innerslot, op->d.fetch.last_var);
|
||||||
|
|
||||||
EEO_NEXT();
|
EEO_NEXT();
|
||||||
|
@ -1183,22 +1183,19 @@ slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* slot_getsomeattrs
|
* slot_getsomeattrs_int - workhorse for slot_getsomeattrs()
|
||||||
* This function forces the entries of the slot's Datum/isnull
|
|
||||||
* arrays to be valid at least up through the attnum'th entry.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
slot_getsomeattrs(TupleTableSlot *slot, int attnum)
|
slot_getsomeattrs_int(TupleTableSlot *slot, int attnum)
|
||||||
{
|
{
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
int attno;
|
int attno;
|
||||||
|
|
||||||
/* Quick out if we have 'em all already */
|
/* Check for caller errors */
|
||||||
if (slot->tts_nvalid >= attnum)
|
Assert(slot->tts_nvalid < attnum); /* slot_getsomeattr checked */
|
||||||
return;
|
Assert(attnum > 0);
|
||||||
|
|
||||||
/* Check for caller error */
|
if (unlikely(attnum > slot->tts_tupleDescriptor->natts))
|
||||||
if (attnum <= 0 || attnum > slot->tts_tupleDescriptor->natts)
|
|
||||||
elog(ERROR, "invalid attribute number %d", attnum);
|
elog(ERROR, "invalid attribute number %d", attnum);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1209,9 +1206,7 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum)
|
|||||||
if (tuple == NULL) /* internal error */
|
if (tuple == NULL) /* internal error */
|
||||||
elog(ERROR, "cannot extract attribute from empty tuple slot");
|
elog(ERROR, "cannot extract attribute from empty tuple slot");
|
||||||
|
|
||||||
/*
|
/* Fetch as many attributes as possible from the underlying tuple. */
|
||||||
* load up any slots available from physical tuple
|
|
||||||
*/
|
|
||||||
attno = HeapTupleHeaderGetNatts(tuple->t_data);
|
attno = HeapTupleHeaderGetNatts(tuple->t_data);
|
||||||
attno = Min(attno, attnum);
|
attno = Min(attno, attnum);
|
||||||
|
|
||||||
@ -1220,13 +1215,14 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum)
|
|||||||
attno = slot->tts_nvalid;
|
attno = slot->tts_nvalid;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If tuple doesn't have all the atts indicated by attnum, read the rest
|
* If the underlying tuple doesn't have enough attributes, tuple descriptor
|
||||||
* as NULLs or missing values
|
* must have the missing attributes.
|
||||||
*/
|
*/
|
||||||
if (attno < attnum)
|
if (unlikely(slot->tts_nvalid < attnum))
|
||||||
slot_getmissingattrs(slot, attno, attnum);
|
{
|
||||||
|
slot_getmissingattrs(slot, slot->tts_nvalid, attnum);
|
||||||
slot->tts_nvalid = attnum;
|
slot->tts_nvalid = attnum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
|
@ -79,7 +79,7 @@ LLVMTypeRef StructAggStatePerTransData;
|
|||||||
LLVMValueRef AttributeTemplate;
|
LLVMValueRef AttributeTemplate;
|
||||||
LLVMValueRef FuncStrlen;
|
LLVMValueRef FuncStrlen;
|
||||||
LLVMValueRef FuncVarsizeAny;
|
LLVMValueRef FuncVarsizeAny;
|
||||||
LLVMValueRef FuncSlotGetsomeattrs;
|
LLVMValueRef FuncSlotGetsomeattrsInt;
|
||||||
LLVMValueRef FuncSlotGetmissingattrs;
|
LLVMValueRef FuncSlotGetmissingattrs;
|
||||||
LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal;
|
LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal;
|
||||||
LLVMValueRef FuncExecEvalArrayRefSubscript;
|
LLVMValueRef FuncExecEvalArrayRefSubscript;
|
||||||
@ -820,7 +820,7 @@ llvm_create_types(void)
|
|||||||
AttributeTemplate = LLVMGetNamedFunction(mod, "AttributeTemplate");
|
AttributeTemplate = LLVMGetNamedFunction(mod, "AttributeTemplate");
|
||||||
FuncStrlen = LLVMGetNamedFunction(mod, "strlen");
|
FuncStrlen = LLVMGetNamedFunction(mod, "strlen");
|
||||||
FuncVarsizeAny = LLVMGetNamedFunction(mod, "varsize_any");
|
FuncVarsizeAny = LLVMGetNamedFunction(mod, "varsize_any");
|
||||||
FuncSlotGetsomeattrs = LLVMGetNamedFunction(mod, "slot_getsomeattrs");
|
FuncSlotGetsomeattrsInt = LLVMGetNamedFunction(mod, "slot_getsomeattrs_int");
|
||||||
FuncSlotGetmissingattrs = LLVMGetNamedFunction(mod, "slot_getmissingattrs");
|
FuncSlotGetmissingattrs = LLVMGetNamedFunction(mod, "slot_getmissingattrs");
|
||||||
FuncMakeExpandedObjectReadOnlyInternal = LLVMGetNamedFunction(mod, "MakeExpandedObjectReadOnlyInternal");
|
FuncMakeExpandedObjectReadOnlyInternal = LLVMGetNamedFunction(mod, "MakeExpandedObjectReadOnlyInternal");
|
||||||
FuncExecEvalArrayRefSubscript = LLVMGetNamedFunction(mod, "ExecEvalArrayRefSubscript");
|
FuncExecEvalArrayRefSubscript = LLVMGetNamedFunction(mod, "ExecEvalArrayRefSubscript");
|
||||||
|
@ -345,7 +345,7 @@ llvm_compile_expr(ExprState *state)
|
|||||||
params[1] = l_int32_const(op->d.fetch.last_var);
|
params[1] = l_int32_const(op->d.fetch.last_var);
|
||||||
|
|
||||||
LLVMBuildCall(b,
|
LLVMBuildCall(b,
|
||||||
llvm_get_decl(mod, FuncSlotGetsomeattrs),
|
llvm_get_decl(mod, FuncSlotGetsomeattrsInt),
|
||||||
params, lengthof(params), "");
|
params, lengthof(params), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ void *referenced_functions[] =
|
|||||||
{
|
{
|
||||||
strlen,
|
strlen,
|
||||||
varsize_any,
|
varsize_any,
|
||||||
slot_getsomeattrs,
|
slot_getsomeattrs_int,
|
||||||
slot_getmissingattrs,
|
slot_getmissingattrs,
|
||||||
MakeExpandedObjectReadOnlyInternal,
|
MakeExpandedObjectReadOnlyInternal,
|
||||||
ExecEvalArrayRefSubscript,
|
ExecEvalArrayRefSubscript,
|
||||||
|
@ -219,7 +219,6 @@ extern void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum,
|
|||||||
int lastAttNum);
|
int lastAttNum);
|
||||||
extern Datum slot_getattr(TupleTableSlot *slot, int attnum,
|
extern Datum slot_getattr(TupleTableSlot *slot, int attnum,
|
||||||
bool *isnull);
|
bool *isnull);
|
||||||
extern void slot_getsomeattrs(TupleTableSlot *slot, int attnum);
|
|
||||||
|
|
||||||
/* in access/common/heaptuple.c */
|
/* in access/common/heaptuple.c */
|
||||||
extern bool slot_attisnull(TupleTableSlot *slot, int attnum);
|
extern bool slot_attisnull(TupleTableSlot *slot, int attnum);
|
||||||
@ -227,9 +226,21 @@ extern bool slot_getsysattr(TupleTableSlot *slot, int attnum,
|
|||||||
Datum *value, bool *isnull);
|
Datum *value, bool *isnull);
|
||||||
extern Datum getmissingattr(TupleDesc tupleDesc,
|
extern Datum getmissingattr(TupleDesc tupleDesc,
|
||||||
int attnum, bool *isnull);
|
int attnum, bool *isnull);
|
||||||
|
extern void slot_getsomeattrs_int(TupleTableSlot *slot, int attnum);
|
||||||
|
|
||||||
#ifndef FRONTEND
|
#ifndef FRONTEND
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function forces the entries of the slot's Datum/isnull arrays to be
|
||||||
|
* valid at least up through the attnum'th entry.
|
||||||
|
*/
|
||||||
|
static inline void
|
||||||
|
slot_getsomeattrs(TupleTableSlot *slot, int attnum)
|
||||||
|
{
|
||||||
|
if (slot->tts_nvalid < attnum)
|
||||||
|
slot_getsomeattrs_int(slot, attnum);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* slot_getallattrs
|
* slot_getallattrs
|
||||||
* This function forces all the entries of the slot's Datum/isnull
|
* This function forces all the entries of the slot's Datum/isnull
|
||||||
|
@ -77,8 +77,8 @@ extern LLVMTypeRef StructAggStatePerGroupData;
|
|||||||
extern LLVMValueRef AttributeTemplate;
|
extern LLVMValueRef AttributeTemplate;
|
||||||
extern LLVMValueRef FuncStrlen;
|
extern LLVMValueRef FuncStrlen;
|
||||||
extern LLVMValueRef FuncVarsizeAny;
|
extern LLVMValueRef FuncVarsizeAny;
|
||||||
extern LLVMValueRef FuncSlotGetsomeattrs;
|
|
||||||
extern LLVMValueRef FuncSlotGetmissingattrs;
|
extern LLVMValueRef FuncSlotGetmissingattrs;
|
||||||
|
extern LLVMValueRef FuncSlotGetsomeattrsInt;
|
||||||
extern LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal;
|
extern LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal;
|
||||||
extern LLVMValueRef FuncExecEvalArrayRefSubscript;
|
extern LLVMValueRef FuncExecEvalArrayRefSubscript;
|
||||||
extern LLVMValueRef FuncExecEvalSysVar;
|
extern LLVMValueRef FuncExecEvalSysVar;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user