diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 5ee3775..e1b6d1d 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -139,6 +139,8 @@ #include "utils/timestamp.h" #include "utils/typcache.h" +#include "portability/instr_time.h" + #define DEFAULT_PAGE_CPU_MULTIPLIER 50.0 /* @@ -373,6 +375,11 @@ var_eq_const(VariableStatData *vardata, Oid oproid, Oid collation, double nullfrac = 0.0; bool isdefault; Oid opfuncoid; + Oid valuetype = 0; + instr_time comparestart, + compareuration; + + INSTR_TIME_SET_CURRENT(comparestart); /* * If the constant is NULL, assume operator is strict and return zero, ie, @@ -426,6 +433,8 @@ var_eq_const(VariableStatData *vardata, Oid oproid, Oid collation, LOCAL_FCINFO(fcinfo, 2); FmgrInfo eqproc; + valuetype = sslot.valuetype; + fmgr_info(opfuncoid, &eqproc); /* @@ -527,6 +536,27 @@ var_eq_const(VariableStatData *vardata, Oid oproid, Oid collation, /* result should be in range, but make sure... */ CLAMP_PROBABILITY(selec); + if (valuetype == 25) { + double plantime; + char *conststr; + int len; + + INSTR_TIME_SET_CURRENT(compareuration); + INSTR_TIME_SUBTRACT(compareuration, comparestart); + plantime = INSTR_TIME_GET_DOUBLE(compareuration); + + conststr = TextDatumGetCString(constval); + len = strlen(conststr); + + if (len > 1000) + { + conststr += (len - 3); + + elog(NOTICE, "var_eq_cosnt(%s) : %.*f", + conststr, 3, 1000.0 * plantime); + } + } + return selec; } @@ -811,6 +841,11 @@ mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Oid collation, sumcommon; AttStatsSlot sslot; int i; + Oid valuetype = 0; + instr_time comparestart, + compareuration; + + INSTR_TIME_SET_CURRENT(comparestart); mcv_selec = 0.0; sumcommon = 0.0; @@ -823,6 +858,8 @@ mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Oid collation, { LOCAL_FCINFO(fcinfo, 2); + valuetype = sslot.valuetype; + /* * We invoke the opproc "by hand" so that we won't fail on NULL * results. Such cases won't arise for normal comparison functions, @@ -858,6 +895,27 @@ mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Oid collation, } *sumcommonp = sumcommon; + + if (valuetype == 25) { + double plantime; + char *conststr; + int len; + + INSTR_TIME_SET_CURRENT(compareuration); + INSTR_TIME_SUBTRACT(compareuration, comparestart); + plantime = INSTR_TIME_GET_DOUBLE(compareuration); + + conststr = TextDatumGetCString(constval); + len = strlen(conststr); + + if (len > 1000) + { + conststr += (len - 3); + elog(NOTICE, "mcv_selectivity(opproc->fn_oid=%d,%s) : %.*f", + opproc->fn_oid, conststr, 3, 1000.0 * plantime); + } + } + return mcv_selec; } @@ -2418,6 +2476,11 @@ eqjoinsel(PG_FUNCTION_ARGS) bool get_mcv_stats; bool join_is_reversed; RelOptInfo *inner_rel; + /* just for perf test*/ + instr_time comparestart, + compareuration; + + INSTR_TIME_SET_CURRENT(comparestart); get_join_variables(root, args, sjinfo, &vardata1, &vardata2, &join_is_reversed); @@ -2476,7 +2539,8 @@ eqjoinsel(PG_FUNCTION_ARGS) * If the MCV lists are long enough to justify hashing, try to look up * hash functions for the join operator. */ - if ((sslot1.nvalues + sslot2.nvalues) >= EQJOINSEL_MCV_HASH_THRESHOLD) + /* if ((sslot1.nvalues + sslot2.nvalues) >= EQJOINSEL_MCV_HASH_THRESHOLD) */ + if ((sslot1.nvalues + sslot2.nvalues) >= 202) /* just for perf test*/ (void) get_op_hash_functions_ext(operator, exprType((Node *) linitial(args)), &hashLeft, &hashRight); @@ -2574,6 +2638,16 @@ eqjoinsel(PG_FUNCTION_ARGS) CLAMP_PROBABILITY(selec); + { + double plantime; + + INSTR_TIME_SET_CURRENT(compareuration); + INSTR_TIME_SUBTRACT(compareuration, comparestart); + plantime = INSTR_TIME_GET_DOUBLE(compareuration); + + elog(NOTICE, "eqjoinsel() : %.*f", 3, 1000.0 * plantime); + } + PG_RETURN_FLOAT8((float8) selec); } @@ -3347,6 +3421,11 @@ mergejoinscansel(PlannerInfo *root, Node *clause, rightmin, rightmax; double selec; + /* just for perf test*/ + instr_time comparestart, + compareuration; + + INSTR_TIME_SET_CURRENT(comparestart); /* Set default results if we can't figure anything out. */ /* XXX should default "start" fraction be a bit more than 0? */ @@ -3614,6 +3693,15 @@ mergejoinscansel(PlannerInfo *root, Node *clause, *rightstart = 0.0; *rightend = 1.0; } + { + double plantime; + + INSTR_TIME_SET_CURRENT(compareuration); + INSTR_TIME_SUBTRACT(compareuration, comparestart); + plantime = INSTR_TIME_GET_DOUBLE(compareuration); + + elog(NOTICE, "mergejoinscansel() : %.*f", 3, 1000.0 * plantime); + } fail: ReleaseVariableStats(leftvar);