129 #include "utils/fmgroids.h" 150 double nd1,
double nd2,
151 bool isdefault1,
bool isdefault2,
154 bool have_mcvs1,
bool have_mcvs2);
157 double nd1,
double nd2,
158 bool isdefault1,
bool isdefault2,
161 bool have_mcvs1,
bool have_mcvs2,
168 double *scaledlobound,
double *scaledhibound);
173 double *scaledlobound,
175 double *scaledhibound);
179 double *scaledlobound,
181 double *scaledhibound);
183 int rangelo,
int rangehi);
185 int rangelo,
int rangehi);
193 Oid sortop,
Oid collation,
197 Oid collation,
int16 typLen,
bool typByVal,
201 Oid sortop,
Oid collation,
211 Datum *endpointDatum);
264 &vardata, &other, &varonleft))
274 ((
Const *) other)->constvalue,
275 ((
Const *) other)->constisnull,
293 Datum constval,
bool constisnull,
294 bool varonleft,
bool negate)
297 double nullfrac = 0.0;
317 nullfrac = stats->stanullfrac;
363 fcinfo->args[0].isnull =
false;
364 fcinfo->args[1].isnull =
false;
367 fcinfo->args[1].value = constval;
369 fcinfo->args[0].value = constval;
371 for (i = 0; i < sslot.
nvalues; i++)
376 fcinfo->args[0].value = sslot.
values[
i];
378 fcinfo->args[1].value = sslot.
values[
i];
379 fcinfo->isnull =
false;
409 double sumcommon = 0.0;
410 double otherdistinct;
412 for (i = 0; i < sslot.
nnumbers; i++)
414 selec = 1.0 - sumcommon - nullfrac;
424 if (otherdistinct > 1)
425 selec /= otherdistinct;
449 selec = 1.0 - selec - nullfrac;
465 bool varonleft,
bool negate)
468 double nullfrac = 0.0;
479 nullfrac = stats->stanullfrac;
508 selec = 1.0 - nullfrac;
538 selec = 1.0 - selec - nullfrac;
622 if (block >= vardata->
rel->
pages - 1)
637 block +=
Min(offset / density, 1.0);
644 selec = block / (vardata->
rel->
pages - 0.5);
654 if (iseq == isgt && vardata->
rel->
tuples >= 1.0)
678 mcv_selec =
mcv_selectivity(vardata, &opproc, collation, constval,
true,
686 operator, &opproc, isgt, iseq,
688 constval, consttype);
695 selec = 1.0 - stats->stanullfrac - sumcommon;
697 if (hist_selec >= 0.0)
730 Datum constval,
bool varonleft,
758 fcinfo->args[0].isnull =
false;
759 fcinfo->args[1].isnull =
false;
762 fcinfo->args[1].value = constval;
764 fcinfo->args[0].value = constval;
766 for (i = 0; i < sslot.
nvalues; i++)
771 fcinfo->args[0].value = sslot.
values[
i];
773 fcinfo->args[1].value = sslot.
values[
i];
774 fcinfo->isnull =
false;
783 *sumcommonp = sumcommon;
822 Datum constval,
bool varonleft,
823 int min_hist_size,
int n_skip,
831 Assert(min_hist_size > 2 * n_skip);
840 if (sslot.
nvalues >= min_hist_size)
856 fcinfo->args[0].isnull =
false;
857 fcinfo->args[1].isnull =
false;
860 fcinfo->args[1].value = constval;
862 fcinfo->args[0].value = constval;
864 for (i = n_skip; i < sslot.
nvalues - n_skip; i++)
869 fcinfo->args[0].value = sslot.
values[
i];
871 fcinfo->args[1].value = sslot.
values[
i];
872 fcinfo->isnull =
false;
877 result = ((double) nmatch) / ((double) (sslot.
nvalues - 2 * n_skip));
913 double default_selectivity)
925 &vardata, &other, &varonleft))
926 return default_selectivity;
933 ((
Const *) other)->constisnull)
942 Datum constval = ((
Const *) other)->constvalue;
970 selec = default_selectivity;
972 else if (hist_size < 100)
979 double hist_weight = hist_size / 100.0;
981 selec = selec * hist_weight +
982 default_selectivity * (1.0 - hist_weight);
988 else if (selec > 0.9999)
1002 selec *= 1.0 - nullfrac - mcvsum;
1008 selec = default_selectivity;
1040 Oid opoid,
FmgrInfo *opproc,
bool isgt,
bool iseq,
1092 bool have_end =
false;
1108 while (lobound < hibound)
1110 int probe = (lobound + hibound) / 2;
1118 if (probe == 0 && sslot.
nvalues > 2)
1140 lobound = probe + 1;
1157 else if (lobound >= sslot.
nvalues)
1168 double eq_selec = 0;
1190 if (i == 1 || isgt == iseq)
1192 double otherdistinct;
1210 if (otherdistinct > 1)
1211 eq_selec = 1.0 / otherdistinct;
1230 else if (val <= low)
1232 else if (val >= high)
1236 binfrac = (val - low) / (high - low);
1244 if (isnan(binfrac) ||
1245 binfrac < 0.0 || binfrac > 1.0)
1267 histfrac = (double) (i - 1) + binfrac;
1268 histfrac /= (double) (sslot.
nvalues - 1);
1303 histfrac += eq_selec * (1.0 - binfrac);
1311 histfrac -= eq_selec;
1318 hist_selec = isgt ? (1.0 - histfrac) : histfrac;
1333 double cutoff = 0.01 / (double) (sslot.
nvalues - 1);
1335 if (hist_selec < cutoff)
1336 hist_selec = cutoff;
1337 else if (hist_selec > 1.0 - cutoff)
1338 hist_selec = 1.0 - cutoff;
1355 fcinfo->args[0].isnull =
false;
1356 fcinfo->args[1].isnull =
false;
1357 fcinfo->args[1].value = constval;
1362 fcinfo->args[0].value = sslot.
values[
i];
1363 fcinfo->isnull =
false;
1368 hist_selec = ((double) nmatch) / ((double) sslot.
nvalues);
1377 double cutoff = 0.01 / (double) (sslot.
nvalues - 1);
1379 if (hist_selec < cutoff)
1380 hist_selec = cutoff;
1381 else if (hist_selec > 1.0 - cutoff)
1382 hist_selec = 1.0 - cutoff;
1416 &vardata, &other, &varonleft))
1432 if (((
Const *) other)->constisnull)
1437 constval = ((
Const *) other)->constvalue;
1438 consttype = ((
Const *) other)->consttype;
1456 selec =
scalarineqsel(root,
operator, isgt, iseq, collation,
1457 &vardata, constval, consttype);
1552 freq_null = stats->stanullfrac;
1568 freq_true = 1.0 - sslot.
numbers[0] - freq_null;
1574 freq_false = 1.0 - freq_true - freq_null;
1576 switch (booltesttype)
1584 selec = 1.0 - freq_null;
1592 selec = 1.0 - freq_true;
1600 selec = 1.0 - freq_false;
1603 elog(
ERROR,
"unrecognized booltesttype: %d",
1604 (
int) booltesttype);
1618 switch (booltesttype)
1626 selec = 1.0 - freq_null;
1631 selec = (1.0 - freq_null) / 2.0;
1637 selec = (freq_null + 1.0) / 2.0;
1640 elog(
ERROR,
"unrecognized booltesttype: %d",
1641 (
int) booltesttype);
1655 switch (booltesttype)
1676 elog(
ERROR,
"unrecognized booltesttype: %d",
1677 (
int) booltesttype);
1709 freq_null = stats->stanullfrac;
1711 switch (nulltesttype)
1726 selec = 1.0 - freq_null;
1729 elog(
ERROR,
"unrecognized nulltesttype: %d",
1730 (
int) nulltesttype);
1735 ((
Var *) vardata.
var)->varattno < 0)
1741 selec = (nulltesttype ==
IS_NULL) ? 0.0 : 1.0;
1748 switch (nulltesttype)
1757 elog(
ERROR,
"unrecognized nulltesttype: %d",
1758 (
int) nulltesttype);
1815 bool is_join_clause,
1821 bool useOr = clause->
useOr;
1822 bool isEquality =
false;
1823 bool isInequality =
false;
1826 Oid nominal_element_type;
1827 Oid nominal_element_collation;
1860 if (
operator == typentry->
eq_opr)
1863 isInequality =
true;
1872 if ((isEquality || isInequality) && !is_join_clause)
1875 nominal_element_type,
1876 isEquality, useOr, varRelid);
1901 if (oprsel == F_EQSEL || oprsel == F_EQJOINSEL)
1903 else if (oprsel == F_NEQSEL || oprsel == F_NEQJOINSEL)
1904 isInequality =
true;
1918 if (rightop &&
IsA(rightop,
Const))
1920 Datum arraydatum = ((
Const *) rightop)->constvalue;
1921 bool arrayisnull = ((
Const *) rightop)->constisnull;
1935 &elmlen, &elmbyval, &elmalign);
1938 elmlen, elmbyval, elmalign,
1939 &elem_values, &elem_nulls, &num_elems);
1955 s1 = s1disjoint = (useOr ? 0.0 : 1.0);
1957 for (i = 0; i < num_elems; i++)
1965 nominal_element_collation,
1988 s1 = s1 + s2 - s1 *
s2;
1996 s1disjoint += s2 - 1.0;
2001 if ((useOr ? isEquality : isInequality) &&
2002 s1disjoint >= 0.0 && s1disjoint <= 1.0)
2014 &elmlen, &elmbyval);
2023 s1 = s1disjoint = (useOr ? 0.0 : 1.0);
2055 s1 = s1 + s2 - s1 *
s2;
2063 s1disjoint += s2 - 1.0;
2068 if ((useOr ? isEquality : isInequality) &&
2069 s1disjoint >= 0.0 && s1disjoint <= 1.0)
2085 dummyexpr->
typeId = nominal_element_type;
2104 s1 = useOr ? 0.0 : 1.0;
2111 for (i = 0; i < 10; i++)
2114 s1 = s1 + s2 - s1 *
s2;
2137 if (arrayexpr &&
IsA(arrayexpr,
Const))
2139 Datum arraydatum = ((
Const *) arrayexpr)->constvalue;
2140 bool arrayisnull = ((
Const *) arrayexpr)->constisnull;
2178 bool is_join_clause;
2194 is_join_clause =
false;
2196 else if (sjinfo == NULL)
2202 is_join_clause =
false;
2261 bool have_mcvs1 =
false;
2262 bool have_mcvs2 =
false;
2263 bool join_is_reversed;
2267 &vardata1, &vardata2, &join_is_reversed);
2274 memset(&sslot1, 0,
sizeof(sslot1));
2275 memset(&sslot2, 0,
sizeof(sslot2));
2299 &vardata1, &vardata2,
2301 isdefault1, isdefault2,
2304 have_mcvs1, have_mcvs2);
2311 selec = selec_inner;
2324 if (!join_is_reversed)
2326 &vardata1, &vardata2,
2328 isdefault1, isdefault2,
2331 have_mcvs1, have_mcvs2,
2339 &vardata2, &vardata1,
2341 isdefault2, isdefault1,
2344 have_mcvs2, have_mcvs1,
2358 selec =
Min(selec, inner_rel->
rows * selec_inner);
2362 elog(
ERROR,
"unrecognized join type: %d",
2388 double nd1,
double nd2,
2389 bool isdefault1,
bool isdefault2,
2392 bool have_mcvs1,
bool have_mcvs2)
2396 if (have_mcvs1 && have_mcvs2)
2414 double nullfrac1 = stats1->stanullfrac;
2415 double nullfrac2 = stats2->stanullfrac;
2416 double matchprodfreq,
2438 fcinfo->args[0].isnull =
false;
2439 fcinfo->args[1].isnull =
false;
2450 matchprodfreq = 0.0;
2452 for (i = 0; i < sslot1->
nvalues; i++)
2456 fcinfo->args[0].value = sslot1->
values[
i];
2458 for (j = 0; j < sslot2->
nvalues; j++)
2464 fcinfo->args[1].value = sslot2->
values[j];
2465 fcinfo->isnull =
false;
2469 hasmatch1[
i] = hasmatch2[j] =
true;
2478 matchfreq1 = unmatchfreq1 = 0.0;
2479 for (i = 0; i < sslot1->
nvalues; i++)
2484 unmatchfreq1 += sslot1->
numbers[
i];
2488 matchfreq2 = unmatchfreq2 = 0.0;
2489 for (i = 0; i < sslot2->
nvalues; i++)
2494 unmatchfreq2 += sslot2->
numbers[
i];
2505 otherfreq1 = 1.0 - nullfrac1 - matchfreq1 - unmatchfreq1;
2506 otherfreq2 = 1.0 - nullfrac2 - matchfreq2 - unmatchfreq2;
2518 totalsel1 = matchprodfreq;
2520 totalsel1 += unmatchfreq1 * otherfreq2 / (nd2 - sslot2->
nvalues);
2522 totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) /
2525 totalsel2 = matchprodfreq;
2527 totalsel2 += unmatchfreq2 * otherfreq1 / (nd1 - sslot1->
nvalues);
2529 totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) /
2538 selec = (totalsel1 < totalsel2) ? totalsel1 : totalsel2;
2562 double nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
2563 double nullfrac2 = stats2 ? stats2->stanullfrac : 0.0;
2565 selec = (1.0 - nullfrac1) * (1.0 - nullfrac2);
2585 double nd1,
double nd2,
2586 bool isdefault1,
bool isdefault2,
2589 bool have_mcvs1,
bool have_mcvs2,
2615 if (nd2 >= vardata2->
rel->
rows)
2621 if (nd2 >= inner_rel->
rows)
2623 nd2 = inner_rel->
rows;
2627 if (have_mcvs1 && have_mcvs2 &&
OidIsValid(opfuncoid))
2641 double nullfrac1 = stats1->stanullfrac;
2656 clamped_nvalues2 =
Min(sslot2->
nvalues, nd2);
2668 fcinfo->args[0].isnull =
false;
2669 fcinfo->args[1].isnull =
false;
2672 hasmatch2 = (
bool *)
palloc0(clamped_nvalues2 *
sizeof(
bool));
2681 for (i = 0; i < sslot1->
nvalues; i++)
2685 fcinfo->args[0].value = sslot1->
values[
i];
2687 for (j = 0; j < clamped_nvalues2; j++)
2693 fcinfo->args[1].value = sslot2->
values[j];
2694 fcinfo->isnull =
false;
2698 hasmatch1[
i] = hasmatch2[j] =
true;
2706 for (i = 0; i < sslot1->
nvalues; i++)
2730 if (!isdefault1 && !isdefault2)
2734 if (nd1 <= nd2 || nd2 < 0)
2735 uncertainfrac = 1.0;
2737 uncertainfrac = nd2 / nd1;
2740 uncertainfrac = 0.5;
2741 uncertain = 1.0 - matchfreq1 - nullfrac1;
2743 selec = matchfreq1 + uncertainfrac * uncertain;
2751 double nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
2753 if (!isdefault1 && !isdefault2)
2755 if (nd1 <= nd2 || nd2 < 0)
2756 selec = 1.0 - nullfrac1;
2758 selec = (nd2 / nd1) * (1.0 - nullfrac1);
2761 selec = 0.5 * (1.0 - nullfrac1);
2813 result = 1.0 - nullfrac;
2839 result = 1.0 - result;
2905 Oid opfamily,
int strategy,
bool nulls_first,
2935 *leftstart = *rightstart = 0.0;
2936 *leftend = *rightend = 1.0;
2941 opno = ((
OpExpr *) clause)->opno;
2942 collation = ((
OpExpr *) clause)->inputcollid;
2970 if (op_lefttype == op_righttype)
2974 op_lefttype, op_righttype,
2977 op_lefttype, op_righttype,
2989 op_lefttype, op_righttype,
2992 op_lefttype, op_righttype,
2995 op_lefttype, op_lefttype,
2998 op_righttype, op_righttype,
3003 op_righttype, op_lefttype,
3006 op_righttype, op_lefttype,
3013 if (op_lefttype == op_righttype)
3017 op_lefttype, op_righttype,
3020 op_lefttype, op_righttype,
3025 op_lefttype, op_lefttype,
3034 op_lefttype, op_righttype,
3037 op_lefttype, op_righttype,
3040 op_lefttype, op_lefttype,
3043 op_righttype, op_righttype,
3046 op_lefttype, op_lefttype,
3049 op_righttype, op_righttype,
3052 op_righttype, op_lefttype,
3055 op_righttype, op_lefttype,
3077 &leftmin, &leftmax))
3080 &rightmin, &rightmax))
3087 &leftmax, &leftmin))
3090 &rightmax, &rightmin))
3099 selec =
scalarineqsel(root, leop, isgt,
true, collation, &leftvar,
3100 rightmax, op_righttype);
3105 selec =
scalarineqsel(root, revleop, isgt,
true, collation, &rightvar,
3106 leftmax, op_lefttype);
3116 if (*leftend > *rightend)
3118 else if (*leftend < *rightend)
3121 *leftend = *rightend = 1.0;
3129 selec =
scalarineqsel(root, ltop, isgt,
false, collation, &leftvar,
3130 rightmin, op_righttype);
3135 selec =
scalarineqsel(root, revltop, isgt,
false, collation, &rightvar,
3136 leftmin, op_lefttype);
3138 *rightstart = selec;
3146 if (*leftstart < *rightstart)
3148 else if (*leftstart > *rightstart)
3151 *leftstart = *rightstart = 0.0;
3166 *leftstart += stats->stanullfrac;
3168 *leftend += stats->stanullfrac;
3174 *rightstart += stats->stanullfrac;
3176 *rightend += stats->stanullfrac;
3182 if (*leftstart >= *leftend)
3187 if (*rightstart >= *rightend)
3257 foreach(lc, varinfos)
3269 if (vardata->
rel != varinfo->
rel &&
3288 varinfo->
rel = vardata->
rel;
3290 varinfos =
lappend(varinfos, varinfo);
3364 double srf_multiplier = 1.0;
3395 foreach(l, groupExprs)
3398 double this_srf_multiplier;
3419 if (srf_multiplier < this_srf_multiplier)
3420 srf_multiplier = this_srf_multiplier;
3423 if (
exprType(groupexpr) == BOOLOID)
3438 groupexpr, &vardata);
3461 if (varshere ==
NIL)
3471 foreach(l2, varshere)
3485 if (varinfos ==
NIL)
3488 numdistinct *= srf_multiplier;
3490 numdistinct = ceil(numdistinct);
3492 if (numdistinct > input_rows)
3493 numdistinct = input_rows;
3494 if (numdistinct < 1.0)
3511 double reldistinct = 1;
3512 double relmaxndistinct = reldistinct;
3513 int relvarcount = 0;
3521 relvarinfos =
lappend(relvarinfos, varinfo1);
3526 if (varinfo2->
rel == varinfo1->
rel)
3529 relvarinfos =
lappend(relvarinfos, varinfo2);
3534 newvarinfos =
lappend(newvarinfos, varinfo2);
3557 reldistinct *= mvndistinct;
3558 if (relmaxndistinct < mvndistinct)
3559 relmaxndistinct = mvndistinct;
3564 foreach(l, relvarinfos)
3569 if (relmaxndistinct < varinfo2->ndistinct)
3592 double clamp = rel->
tuples;
3594 if (relvarcount > 1)
3597 if (clamp < relmaxndistinct)
3599 clamp = relmaxndistinct;
3605 if (reldistinct > clamp)
3606 reldistinct = clamp;
3613 if (reldistinct > 0 && rel->
rows < rel->
tuples)
3651 rel->
tuples / reldistinct));
3658 numdistinct *= reldistinct;
3661 varinfos = newvarinfos;
3662 }
while (varinfos !=
NIL);
3665 numdistinct *= srf_multiplier;
3668 numdistinct = ceil(numdistinct);
3671 if (numdistinct > input_rows)
3672 numdistinct = input_rows;
3673 if (numdistinct < 1.0)
3775 stanullfrac = stats->stanullfrac;
3781 avgfreq = (1.0 - stanullfrac) / ndistinct;
3802 if (ndistinct > nbuckets)
3803 estfract = 1.0 / nbuckets;
3805 estfract = 1.0 / ndistinct;
3810 if (avgfreq > 0.0 && *mcv_freq > avgfreq)
3811 estfract *= *mcv_freq / avgfreq;
3818 if (estfract < 1.0
e-6)
3820 else if (estfract > 1.0)
3857 return hashentrysize * dNumGroups;
3880 List **varinfos,
double *ndistinct)
3894 foreach(lc, *varinfos)
3904 attnum = ((
Var *) varinfo->
var)->varattno;
3921 if (info->
kind != STATS_EXT_NDISTINCT)
3935 if (nshared > nmatches)
3946 Assert(nmatches > 1 && matched != NULL);
3961 for (i = 0; i < stats->
nitems; i++)
3974 elog(
ERROR,
"corrupt MVNDistinct entry");
3977 foreach(lc, *varinfos)
3984 newlist =
lappend(newlist, varinfo);
3988 attnum = ((
Var *) varinfo->
var)->varattno;
3994 newlist =
lappend(newlist, varinfo);
3997 *varinfos = newlist;
4037 double *scaledlobound,
double *scaledhibound)
4039 bool failure =
false;
4073 case REGPROCEDUREOID:
4075 case REGOPERATOROID:
4079 case REGDICTIONARYOID:
4081 case REGNAMESPACEOID:
4115 lostr, scaledlobound,
4116 histr, scaledhibound);
4129 if (boundstypid != BYTEAOID)
4132 lobound, scaledlobound,
4133 hibound, scaledhibound);
4141 case TIMESTAMPTZOID:
4170 *scaledvalue = *scaledlobound = *scaledhibound = 0;
4204 case REGPROCEDUREOID:
4206 case REGOPERATOROID:
4210 case REGDICTIONARYOID:
4212 case REGNAMESPACEOID:
4243 double *scaledvalue,
4245 double *scaledlobound,
4247 double *scaledhibound)
4253 rangelo = rangehi = (
unsigned char) hibound[0];
4254 for (sptr = lobound; *sptr; sptr++)
4256 if (rangelo > (
unsigned char) *sptr)
4257 rangelo = (
unsigned char) *sptr;
4258 if (rangehi < (
unsigned char) *sptr)
4259 rangehi = (
unsigned char) *sptr;
4261 for (sptr = hibound; *sptr; sptr++)
4263 if (rangelo > (
unsigned char) *sptr)
4264 rangelo = (
unsigned char) *sptr;
4265 if (rangehi < (
unsigned char) *sptr)
4266 rangehi = (
unsigned char) *sptr;
4269 if (rangelo <= 'Z' && rangehi >=
'A')
4277 if (rangelo <= 'z' && rangehi >=
'a')
4285 if (rangelo <= '9' && rangehi >=
'0')
4297 if (rangehi - rangelo < 9)
4308 if (*lobound != *hibound || *lobound != *value)
4310 lobound++, hibound++, value++;
4324 int slen = strlen(value);
4345 base = rangehi - rangelo + 1;
4350 int ch = (
unsigned char) *value++;
4354 else if (ch > rangehi)
4356 num += ((double) (ch - rangelo)) / denom;
4380 val = (
char *)
palloc(2);
4416 xfrmlen = strxfrm(NULL, val, 0);
4424 if (xfrmlen == INT_MAX)
4427 xfrmstr = (
char *)
palloc(xfrmlen + 1);
4428 xfrmlen2 = strxfrm(xfrmstr, val, xfrmlen + 1);
4434 Assert(xfrmlen2 <= xfrmlen);
4455 double *scaledvalue,
4457 double *scaledlobound,
4459 double *scaledhibound)
4471 unsigned char *valstr = (
unsigned char *)
VARDATA_ANY(valuep);
4472 unsigned char *lostr = (
unsigned char *)
VARDATA_ANY(loboundp);
4473 unsigned char *histr = (
unsigned char *)
VARDATA_ANY(hiboundp);
4484 minlen =
Min(
Min(valuelen, loboundlen), hiboundlen);
4485 for (
i = 0;
i < minlen;
i++)
4487 if (*lostr != *histr || *lostr != *valstr)
4489 lostr++, histr++, valstr++;
4490 loboundlen--, hiboundlen--, valuelen--;
4503 int rangelo,
int rangehi)
4520 base = rangehi - rangelo + 1;
4523 while (valuelen-- > 0)
4529 else if (ch > rangehi)
4531 num += ((double) (ch - rangelo)) / denom;
4551 case TIMESTAMPTZOID:
4574 return (
double) (timetz->
time + (timetz->
zone * 1000000.0));
4632 if (vardata->
rel && rdata.
rel == NULL)
4640 if (vardata->
rel == NULL && rdata.
rel)
4669 bool *join_is_reversed)
4675 elog(
ERROR,
"join operator should take two arguments");
4683 if (vardata1->
rel &&
4685 *join_is_reversed =
true;
4686 else if (vardata2->
rel &&
4688 *join_is_reversed =
true;
4690 *join_is_reversed =
false;
4751 if (
IsA(basenode,
Var) &&
4752 (varRelid == 0 || varRelid == ((
Var *) basenode)->varno))
4754 Var *var = (
Var *) basenode;
4757 vardata->
var = basenode;
4788 vardata->
rel = onerel;
4813 vardata->
var = node;
4841 if (indexpr_item == NULL)
4844 for (pos = 0; pos < index->
ncolumns; pos++)
4850 if (indexpr_item == NULL)
4851 elog(
ERROR,
"too few entries in indexprs list");
4855 if (
equal(node, indexkey))
4888 elog(
ERROR,
"no function provided to release variable stats with");
5018 elog(
ERROR,
"no function provided to release variable stats with");
5082 int parent_varattno;
5088 if (parent_varattno == 0)
5092 varattno = parent_varattno;
5181 if (ste == NULL || ste->
resjunk)
5182 elog(
ERROR,
"subquery %s does not have attribute %d",
5218 if (var &&
IsA(var,
Var) &&
5261 (
errmsg_internal(
"not using statistics because function \"%s\" is not leak-proof",
5281 double stanullfrac = 0.0;
5298 stadistinct = stats->stadistinct;
5299 stanullfrac = stats->stanullfrac;
5301 else if (vardata->
vartype == BOOLOID)
5330 switch (((
Var *) vardata->
var)->varattno)
5359 stadistinct = -1.0 * (1.0 - stanullfrac);
5364 if (stadistinct > 0.0)
5370 if (vardata->
rel == NULL)
5385 if (stadistinct < 0.0)
5412 Oid sortop,
Oid collation,
5417 bool have_data =
false;
5462 STATISTIC_KIND_HISTOGRAM, sortop,
5486 collation, typLen, typByVal,
5487 &tmin, &tmax, &have_data);
5501 collation, typLen, typByVal,
5502 &tmin, &tmax, &have_data);
5519 Oid collation,
int16 typLen,
bool typByVal,
5524 bool have_data = *p_have_data;
5525 bool found_tmin =
false;
5526 bool found_tmax =
false;
5529 if (opproc->
fn_oid != opfuncoid)
5537 tmin = tmax = sslot->
values[
i];
5538 found_tmin = found_tmax =
true;
5539 *p_have_data = have_data =
true;
5562 *min =
datumCopy(tmin, typByVal, typLen);
5564 *max =
datumCopy(tmax, typByVal, typLen);
5582 Oid sortop,
Oid collation,
5585 bool have_data =
false;
5604 if (index->
relam != BTREE_AM_OID)
5664 "get_actual_variable_range workspace",
5709 if (max && have_data)
5762 Datum *endpointDatum)
5764 bool have_data =
false;
5815 &SnapshotNonVacuumable,
5846 elog(
ERROR,
"no data returned for index-only scan");
5848 elog(
ERROR,
"unexpected recheck indication from btree");
5857 elog(
ERROR,
"found unexpected null value in index \"%s\"",
5862 *endpointDatum =
datumCopy(values[0], typByVal, typLen);
5901 elog(
ERROR,
"could not find RelOptInfo for given relids");
5923 foreach(lc, indexclauses)
5932 result =
lappend(result, rinfo);
5950 Cost qual_arg_cost = 0;
5953 foreach(lc, indexquals)
5956 Node *other_operand;
5986 other_operand = NULL;
5990 elog(
ERROR,
"unsupported indexqual type: %d",
5992 other_operand = NULL;
5998 return qual_arg_cost;
6010 Cost indexStartupCost;
6011 Cost indexTotalCost;
6013 double indexCorrelation;
6014 double numIndexPages;
6015 double numIndexTuples;
6016 double spc_random_page_cost;
6017 double num_sa_scans;
6018 double num_outer_scans;
6020 double qual_op_cost;
6021 double qual_arg_cost;
6022 List *selectivityQuals;
6037 foreach(l, indexQuals)
6047 num_sa_scans *= alength;
6063 if (numIndexTuples <= 0.0)
6065 numIndexTuples = indexSelectivity * index->
rel->
tuples;
6074 numIndexTuples = rint(numIndexTuples / num_sa_scans);
6082 if (numIndexTuples > index->
tuples)
6083 numIndexTuples = index->
tuples;
6084 if (numIndexTuples < 1.0)
6085 numIndexTuples = 1.0;
6100 numIndexPages = ceil(numIndexTuples * index->
pages / index->
tuples);
6102 numIndexPages = 1.0;
6106 &spc_random_page_cost,
6126 num_outer_scans = loop_count;
6127 num_scans = num_sa_scans * num_outer_scans;
6131 double pages_fetched;
6134 pages_fetched = numIndexPages * num_scans;
6139 (
double) index->
pages,
6147 indexTotalCost = (pages_fetched * spc_random_page_cost)
6156 indexTotalCost = numIndexPages * spc_random_page_cost;
6178 indexStartupCost = qual_arg_cost;
6179 indexTotalCost += qual_arg_cost;
6185 indexCorrelation = 0.0;