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

Commitbf6c614

Browse files
committed
Do execGrouping.c via expression eval machinery, take two.
This has a performance benefit on own, although not hugely so. Theprimary benefit is that it will allow for to JIT tuple deforming andcomparator invocations.Large parts of this were previously committed (773aec7), but thecommit contained an omission around cross-type comparisons and wasthus reverted.Author: Andres FreundDiscussion:https://postgr.es/m/20171129080934.amqqkke2zjtekd4t@alap3.anarazel.de
1 parentad9a274 commitbf6c614

File tree

15 files changed

+566
-400
lines changed

15 files changed

+566
-400
lines changed

‎src/backend/executor/execExpr.c

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,3 +3193,146 @@ ExecBuildAggTransCall(ExprState *state, AggState *aggstate,
31933193
as->d.agg_strict_trans_check.jumpnull=state->steps_len;
31943194
}
31953195
}
3196+
3197+
/*
3198+
* Build equality expression that can be evaluated using ExecQual(), returning
3199+
* true if the expression context's inner/outer tuple are NOT DISTINCT. I.e
3200+
* two nulls match, a null and a not-null don't match.
3201+
*
3202+
* desc: tuple descriptor of the to-be-compared tuples
3203+
* numCols: the number of attributes to be examined
3204+
* keyColIdx: array of attribute column numbers
3205+
* eqFunctions: array of function oids of the equality functions to use
3206+
* parent: parent executor node
3207+
*/
3208+
ExprState*
3209+
ExecBuildGroupingEqual(TupleDescldesc,TupleDescrdesc,
3210+
intnumCols,
3211+
AttrNumber*keyColIdx,
3212+
Oid*eqfunctions,
3213+
PlanState*parent)
3214+
{
3215+
ExprState*state=makeNode(ExprState);
3216+
ExprEvalStepscratch= {0};
3217+
intnatt;
3218+
intmaxatt=-1;
3219+
List*adjust_jumps=NIL;
3220+
ListCell*lc;
3221+
3222+
/*
3223+
* When no columns are actually compared, the result's always true. See
3224+
* special case in ExecQual().
3225+
*/
3226+
if (numCols==0)
3227+
returnNULL;
3228+
3229+
state->expr=NULL;
3230+
state->flags=EEO_FLAG_IS_QUAL;
3231+
state->parent=parent;
3232+
3233+
scratch.resvalue=&state->resvalue;
3234+
scratch.resnull=&state->resnull;
3235+
3236+
/* compute max needed attribute */
3237+
for (natt=0;natt<numCols;natt++)
3238+
{
3239+
intattno=keyColIdx[natt];
3240+
3241+
if (attno>maxatt)
3242+
maxatt=attno;
3243+
}
3244+
Assert(maxatt >=0);
3245+
3246+
/* push deform steps */
3247+
scratch.opcode=EEOP_INNER_FETCHSOME;
3248+
scratch.d.fetch.last_var=maxatt;
3249+
ExprEvalPushStep(state,&scratch);
3250+
3251+
scratch.opcode=EEOP_OUTER_FETCHSOME;
3252+
scratch.d.fetch.last_var=maxatt;
3253+
ExprEvalPushStep(state,&scratch);
3254+
3255+
/*
3256+
* Start comparing at the last field (least significant sort key). That's
3257+
* the most likely to be different if we are dealing with sorted input.
3258+
*/
3259+
for (natt=numCols;--natt >=0;)
3260+
{
3261+
intattno=keyColIdx[natt];
3262+
Form_pg_attributelatt=TupleDescAttr(ldesc,attno-1);
3263+
Form_pg_attributeratt=TupleDescAttr(rdesc,attno-1);
3264+
Oidfoid=eqfunctions[natt];
3265+
FmgrInfo*finfo;
3266+
FunctionCallInfofcinfo;
3267+
AclResultaclresult;
3268+
3269+
/* Check permission to call function */
3270+
aclresult=pg_proc_aclcheck(foid,GetUserId(),ACL_EXECUTE);
3271+
if (aclresult!=ACLCHECK_OK)
3272+
aclcheck_error(aclresult,OBJECT_FUNCTION,get_func_name(foid));
3273+
3274+
InvokeFunctionExecuteHook(foid);
3275+
3276+
/* Set up the primary fmgr lookup information */
3277+
finfo=palloc0(sizeof(FmgrInfo));
3278+
fcinfo=palloc0(sizeof(FunctionCallInfoData));
3279+
fmgr_info(foid,finfo);
3280+
fmgr_info_set_expr(NULL,finfo);
3281+
InitFunctionCallInfoData(*fcinfo,finfo,2,
3282+
InvalidOid,NULL,NULL);
3283+
3284+
/* left arg */
3285+
scratch.opcode=EEOP_INNER_VAR;
3286+
scratch.d.var.attnum=attno-1;
3287+
scratch.d.var.vartype=latt->atttypid;
3288+
scratch.resvalue=&fcinfo->arg[0];
3289+
scratch.resnull=&fcinfo->argnull[0];
3290+
ExprEvalPushStep(state,&scratch);
3291+
3292+
/* right arg */
3293+
scratch.opcode=EEOP_OUTER_VAR;
3294+
scratch.d.var.attnum=attno-1;
3295+
scratch.d.var.vartype=ratt->atttypid;
3296+
scratch.resvalue=&fcinfo->arg[1];
3297+
scratch.resnull=&fcinfo->argnull[1];
3298+
ExprEvalPushStep(state,&scratch);
3299+
3300+
/* evaluate distinctness */
3301+
scratch.opcode=EEOP_NOT_DISTINCT;
3302+
scratch.d.func.finfo=finfo;
3303+
scratch.d.func.fcinfo_data=fcinfo;
3304+
scratch.d.func.fn_addr=finfo->fn_addr;
3305+
scratch.d.func.nargs=2;
3306+
scratch.resvalue=&state->resvalue;
3307+
scratch.resnull=&state->resnull;
3308+
ExprEvalPushStep(state,&scratch);
3309+
3310+
/* then emit EEOP_QUAL to detect if result is false (or null) */
3311+
scratch.opcode=EEOP_QUAL;
3312+
scratch.d.qualexpr.jumpdone=-1;
3313+
scratch.resvalue=&state->resvalue;
3314+
scratch.resnull=&state->resnull;
3315+
ExprEvalPushStep(state,&scratch);
3316+
adjust_jumps=lappend_int(adjust_jumps,
3317+
state->steps_len-1);
3318+
}
3319+
3320+
/* adjust jump targets */
3321+
foreach(lc,adjust_jumps)
3322+
{
3323+
ExprEvalStep*as=&state->steps[lfirst_int(lc)];
3324+
3325+
Assert(as->opcode==EEOP_QUAL);
3326+
Assert(as->d.qualexpr.jumpdone==-1);
3327+
as->d.qualexpr.jumpdone=state->steps_len;
3328+
}
3329+
3330+
scratch.resvalue=NULL;
3331+
scratch.resnull=NULL;
3332+
scratch.opcode=EEOP_DONE;
3333+
ExprEvalPushStep(state,&scratch);
3334+
3335+
ExecReadyExpr(state);
3336+
3337+
returnstate;
3338+
}

‎src/backend/executor/execExprInterp.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
355355
&&CASE_EEOP_MAKE_READONLY,
356356
&&CASE_EEOP_IOCOERCE,
357357
&&CASE_EEOP_DISTINCT,
358+
&&CASE_EEOP_NOT_DISTINCT,
358359
&&CASE_EEOP_NULLIF,
359360
&&CASE_EEOP_SQLVALUEFUNCTION,
360361
&&CASE_EEOP_CURRENTOFEXPR,
@@ -1198,6 +1199,34 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
11981199
EEO_NEXT();
11991200
}
12001201

1202+
/* see EEOP_DISTINCT for comments, this is just inverted */
1203+
EEO_CASE(EEOP_NOT_DISTINCT)
1204+
{
1205+
FunctionCallInfofcinfo=op->d.func.fcinfo_data;
1206+
1207+
if (fcinfo->argnull[0]&&fcinfo->argnull[1])
1208+
{
1209+
*op->resvalue=BoolGetDatum(true);
1210+
*op->resnull= false;
1211+
}
1212+
elseif (fcinfo->argnull[0]||fcinfo->argnull[1])
1213+
{
1214+
*op->resvalue=BoolGetDatum(false);
1215+
*op->resnull= false;
1216+
}
1217+
else
1218+
{
1219+
Datumeqresult;
1220+
1221+
fcinfo->isnull= false;
1222+
eqresult=op->d.func.fn_addr(fcinfo);
1223+
*op->resvalue=eqresult;
1224+
*op->resnull=fcinfo->isnull;
1225+
}
1226+
1227+
EEO_NEXT();
1228+
}
1229+
12011230
EEO_CASE(EEOP_NULLIF)
12021231
{
12031232
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp