131 #include "utils/fmgroids.h"
144 #define DEFAULT_PAGE_CPU_MULTIPLIER 50.0
153 double nd1,
double nd2,
154 bool isdefault1,
bool isdefault2,
157 bool have_mcvs1,
bool have_mcvs2);
160 double nd1,
double nd2,
161 bool isdefault1,
bool isdefault2,
164 bool have_mcvs1,
bool have_mcvs2,
171 double *scaledlobound,
double *scaledhibound);
176 double *scaledlobound,
178 double *scaledhibound);
182 double *scaledlobound,
184 double *scaledhibound);
186 int rangelo,
int rangehi);
188 int rangelo,
int rangehi);
196 Oid sortop,
Oid collation,
200 Oid collation,
int16 typLen,
bool typByVal,
204 Oid sortop,
Oid collation,
214 Datum *endpointDatum);
267 &vardata, &other, &varonleft))
277 ((
Const *) other)->constvalue,
278 ((
Const *) other)->constisnull,
296 Datum constval,
bool constisnull,
297 bool varonleft,
bool negate)
300 double nullfrac = 0.0;
320 nullfrac = stats->stanullfrac;
366 fcinfo->args[0].isnull =
false;
367 fcinfo->args[1].isnull =
false;
370 fcinfo->args[1].value = constval;
372 fcinfo->args[0].value = constval;
379 fcinfo->args[0].value = sslot.
values[
i];
381 fcinfo->args[1].value = sslot.
values[
i];
382 fcinfo->isnull =
false;
412 double sumcommon = 0.0;
413 double otherdistinct;
417 selec = 1.0 - sumcommon - nullfrac;
427 if (otherdistinct > 1)
428 selec /= otherdistinct;
452 selec = 1.0 - selec - nullfrac;
468 bool varonleft,
bool negate)
471 double nullfrac = 0.0;
482 nullfrac = stats->stanullfrac;
511 selec = 1.0 - nullfrac;
541 selec = 1.0 - selec - nullfrac;
625 if (block >= vardata->
rel->
pages - 1)
640 block +=
Min(offset / density, 1.0);
647 selec = block / (vardata->
rel->
pages - 0.5);
657 if (iseq == isgt && vardata->
rel->
tuples >= 1.0)
681 mcv_selec =
mcv_selectivity(vardata, &opproc, collation, constval,
true,
689 operator, &opproc, isgt, iseq,
691 constval, consttype);
698 selec = 1.0 - stats->stanullfrac - sumcommon;
700 if (hist_selec >= 0.0)
733 Datum constval,
bool varonleft,
761 fcinfo->args[0].isnull =
false;
762 fcinfo->args[1].isnull =
false;
765 fcinfo->args[1].value = constval;
767 fcinfo->args[0].value = constval;
774 fcinfo->args[0].value = sslot.
values[
i];
776 fcinfo->args[1].value = sslot.
values[
i];
777 fcinfo->isnull =
false;
786 *sumcommonp = sumcommon;
825 Datum constval,
bool varonleft,
826 int min_hist_size,
int n_skip,
834 Assert(min_hist_size > 2 * n_skip);
843 if (sslot.
nvalues >= min_hist_size)
859 fcinfo->args[0].isnull =
false;
860 fcinfo->args[1].isnull =
false;
863 fcinfo->args[1].value = constval;
865 fcinfo->args[0].value = constval;
867 for (
i = n_skip;
i < sslot.
nvalues - n_skip;
i++)
872 fcinfo->args[0].value = sslot.
values[
i];
874 fcinfo->args[1].value = sslot.
values[
i];
875 fcinfo->isnull =
false;
880 result = ((double) nmatch) / ((double) (sslot.
nvalues - 2 * n_skip));
916 double default_selectivity)
928 &vardata, &other, &varonleft))
929 return default_selectivity;
936 ((
Const *) other)->constisnull)
945 Datum constval = ((
Const *) other)->constvalue;
973 selec = default_selectivity;
975 else if (hist_size < 100)
982 double hist_weight = hist_size / 100.0;
984 selec = selec * hist_weight +
985 default_selectivity * (1.0 - hist_weight);
991 else if (selec > 0.9999)
1005 selec *= 1.0 - nullfrac - mcvsum;
1011 selec = default_selectivity;
1043 Oid opoid,
FmgrInfo *opproc,
bool isgt,
bool iseq,
1095 bool have_end =
false;
1111 while (lobound < hibound)
1113 int probe = (lobound + hibound) / 2;
1121 if (probe == 0 && sslot.
nvalues > 2)
1143 lobound = probe + 1;
1160 else if (lobound >= sslot.
nvalues)
1171 double eq_selec = 0;
1193 if (
i == 1 || isgt == iseq)
1195 double otherdistinct;
1213 if (otherdistinct > 1)
1214 eq_selec = 1.0 / otherdistinct;
1233 else if (
val <= low)
1235 else if (
val >= high)
1239 binfrac = (
val - low) / (high - low);
1247 if (isnan(binfrac) ||
1248 binfrac < 0.0 || binfrac > 1.0)
1270 histfrac = (double) (
i - 1) + binfrac;
1271 histfrac /= (double) (sslot.
nvalues - 1);
1306 histfrac += eq_selec * (1.0 - binfrac);
1314 histfrac -= eq_selec;
1321 hist_selec = isgt ? (1.0 - histfrac) : histfrac;
1336 double cutoff = 0.01 / (double) (sslot.
nvalues - 1);
1338 if (hist_selec < cutoff)
1339 hist_selec = cutoff;
1340 else if (hist_selec > 1.0 - cutoff)
1341 hist_selec = 1.0 - cutoff;
1358 fcinfo->args[0].isnull =
false;
1359 fcinfo->args[1].isnull =
false;
1360 fcinfo->args[1].value = constval;
1365 fcinfo->args[0].value = sslot.
values[
i];
1366 fcinfo->isnull =
false;
1371 hist_selec = ((double) nmatch) / ((double) sslot.
nvalues);
1380 double cutoff = 0.01 / (double) (sslot.
nvalues - 1);
1382 if (hist_selec < cutoff)
1383 hist_selec = cutoff;
1384 else if (hist_selec > 1.0 - cutoff)
1385 hist_selec = 1.0 - cutoff;
1419 &vardata, &other, &varonleft))
1435 if (((
Const *) other)->constisnull)
1440 constval = ((
Const *) other)->constvalue;
1441 consttype = ((
Const *) other)->consttype;
1460 &vardata, constval, consttype);
1555 freq_null = stats->stanullfrac;
1571 freq_true = 1.0 - sslot.
numbers[0] - freq_null;
1577 freq_false = 1.0 - freq_true - freq_null;
1579 switch (booltesttype)
1587 selec = 1.0 - freq_null;
1595 selec = 1.0 - freq_true;
1603 selec = 1.0 - freq_false;
1606 elog(
ERROR,
"unrecognized booltesttype: %d",
1607 (
int) booltesttype);
1621 switch (booltesttype)
1629 selec = 1.0 - freq_null;
1634 selec = (1.0 - freq_null) / 2.0;
1640 selec = (freq_null + 1.0) / 2.0;
1643 elog(
ERROR,
"unrecognized booltesttype: %d",
1644 (
int) booltesttype);
1658 switch (booltesttype)
1679 elog(
ERROR,
"unrecognized booltesttype: %d",
1680 (
int) booltesttype);
1712 freq_null = stats->stanullfrac;
1714 switch (nulltesttype)
1729 selec = 1.0 - freq_null;
1732 elog(
ERROR,
"unrecognized nulltesttype: %d",
1733 (
int) nulltesttype);
1738 ((
Var *) vardata.
var)->varattno < 0)
1744 selec = (nulltesttype ==
IS_NULL) ? 0.0 : 1.0;
1751 switch (nulltesttype)
1760 elog(
ERROR,
"unrecognized nulltesttype: %d",
1761 (
int) nulltesttype);
1818 bool is_join_clause,
1824 bool useOr = clause->
useOr;
1825 bool isEquality =
false;
1826 bool isInequality =
false;
1829 Oid nominal_element_type;
1830 Oid nominal_element_collation;
1863 if (
operator == typentry->
eq_opr)
1866 isInequality =
true;
1875 if ((isEquality || isInequality) && !is_join_clause)
1878 nominal_element_type,
1879 isEquality, useOr, varRelid);
1904 if (oprsel == F_EQSEL || oprsel == F_EQJOINSEL)
1906 else if (oprsel == F_NEQSEL || oprsel == F_NEQJOINSEL)
1907 isInequality =
true;
1921 if (rightop &&
IsA(rightop,
Const))
1923 Datum arraydatum = ((
Const *) rightop)->constvalue;
1924 bool arrayisnull = ((
Const *) rightop)->constisnull;
1938 &elmlen, &elmbyval, &elmalign);
1941 elmlen, elmbyval, elmalign,
1942 &elem_values, &elem_nulls, &num_elems);
1958 s1 = s1disjoint = (useOr ? 0.0 : 1.0);
1960 for (
i = 0;
i < num_elems;
i++)
1968 nominal_element_collation,
1975 clause->inputcollid,
1983 clause->inputcollid,
1999 s1disjoint +=
s2 - 1.0;
2004 if ((useOr ? isEquality : isInequality) &&
2005 s1disjoint >= 0.0 && s1disjoint <= 1.0)
2017 &elmlen, &elmbyval);
2026 s1 = s1disjoint = (useOr ? 0.0 : 1.0);
2042 clause->inputcollid,
2050 clause->inputcollid,
2066 s1disjoint +=
s2 - 1.0;
2071 if ((useOr ? isEquality : isInequality) &&
2072 s1disjoint >= 0.0 && s1disjoint <= 1.0)
2088 dummyexpr->
typeId = nominal_element_type;
2089 dummyexpr->typeMod = -1;
2090 dummyexpr->collation = clause->inputcollid;
2094 clause->inputcollid,
2102 clause->inputcollid,
2107 s1 = useOr ? 0.0 : 1.0;
2114 for (
i = 0;
i < 10;
i++)
2141 if (arrayexpr &&
IsA(arrayexpr,
Const))
2143 Datum arraydatum = ((
Const *) arrayexpr)->constvalue;
2144 bool arrayisnull = ((
Const *) arrayexpr)->constisnull;
2210 bool is_join_clause;
2226 is_join_clause =
false;
2228 else if (sjinfo == NULL)
2234 is_join_clause =
false;
2293 bool have_mcvs1 =
false;
2294 bool have_mcvs2 =
false;
2296 bool join_is_reversed;
2300 &vardata1, &vardata2, &join_is_reversed);
2307 memset(&sslot1, 0,
sizeof(sslot1));
2308 memset(&sslot2, 0,
sizeof(sslot2));
2327 if (get_mcv_stats &&
2338 if (get_mcv_stats &&
2347 &vardata1, &vardata2,
2349 isdefault1, isdefault2,
2352 have_mcvs1, have_mcvs2);
2359 selec = selec_inner;
2372 if (!join_is_reversed)
2374 &vardata1, &vardata2,
2376 isdefault1, isdefault2,
2379 have_mcvs1, have_mcvs2,
2387 &vardata2, &vardata1,
2389 isdefault2, isdefault1,
2392 have_mcvs2, have_mcvs1,
2406 selec =
Min(selec, inner_rel->
rows * selec_inner);
2410 elog(
ERROR,
"unrecognized join type: %d",
2436 double nd1,
double nd2,
2437 bool isdefault1,
bool isdefault2,
2440 bool have_mcvs1,
bool have_mcvs2)
2444 if (have_mcvs1 && have_mcvs2)
2462 double nullfrac1 = stats1->stanullfrac;
2463 double nullfrac2 = stats2->stanullfrac;
2464 double matchprodfreq,
2486 fcinfo->args[0].isnull =
false;
2487 fcinfo->args[1].isnull =
false;
2498 matchprodfreq = 0.0;
2504 fcinfo->args[0].value = sslot1->
values[
i];
2512 fcinfo->args[1].value = sslot2->
values[
j];
2513 fcinfo->isnull =
false;
2517 hasmatch1[
i] = hasmatch2[
j] =
true;
2526 matchfreq1 = unmatchfreq1 = 0.0;
2532 unmatchfreq1 += sslot1->
numbers[
i];
2536 matchfreq2 = unmatchfreq2 = 0.0;
2542 unmatchfreq2 += sslot2->
numbers[
i];
2553 otherfreq1 = 1.0 - nullfrac1 - matchfreq1 - unmatchfreq1;
2554 otherfreq2 = 1.0 - nullfrac2 - matchfreq2 - unmatchfreq2;
2566 totalsel1 = matchprodfreq;
2568 totalsel1 += unmatchfreq1 * otherfreq2 / (nd2 - sslot2->
nvalues);
2570 totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) /
2573 totalsel2 = matchprodfreq;
2575 totalsel2 += unmatchfreq2 * otherfreq1 / (nd1 - sslot1->
nvalues);
2577 totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) /
2586 selec = (totalsel1 < totalsel2) ? totalsel1 : totalsel2;
2610 double nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
2611 double nullfrac2 = stats2 ? stats2->stanullfrac : 0.0;
2613 selec = (1.0 - nullfrac1) * (1.0 - nullfrac2);
2633 double nd1,
double nd2,
2634 bool isdefault1,
bool isdefault2,
2637 bool have_mcvs1,
bool have_mcvs2,
2663 if (nd2 >= vardata2->
rel->
rows)
2669 if (nd2 >= inner_rel->
rows)
2671 nd2 = inner_rel->
rows;
2675 if (have_mcvs1 && have_mcvs2 &&
OidIsValid(opfuncoid))
2689 double nullfrac1 = stats1->stanullfrac;
2704 clamped_nvalues2 =
Min(sslot2->
nvalues, nd2);
2716 fcinfo->args[0].isnull =
false;
2717 fcinfo->args[1].isnull =
false;
2720 hasmatch2 = (
bool *)
palloc0(clamped_nvalues2 *
sizeof(
bool));
2733 fcinfo->args[0].value = sslot1->
values[
i];
2735 for (
j = 0;
j < clamped_nvalues2;
j++)
2741 fcinfo->args[1].value = sslot2->
values[
j];
2742 fcinfo->isnull =
false;
2746 hasmatch1[
i] = hasmatch2[
j] =
true;
2778 if (!isdefault1 && !isdefault2)
2782 if (nd1 <= nd2 || nd2 < 0)
2783 uncertainfrac = 1.0;
2785 uncertainfrac = nd2 / nd1;
2788 uncertainfrac = 0.5;
2789 uncertain = 1.0 - matchfreq1 - nullfrac1;
2791 selec = matchfreq1 + uncertainfrac * uncertain;
2799 double nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
2801 if (!isdefault1 && !isdefault2)
2803 if (nd1 <= nd2 || nd2 < 0)
2804 selec = 1.0 - nullfrac1;
2806 selec = (nd2 / nd1) * (1.0 - nullfrac1);
2809 selec = 0.5 * (1.0 - nullfrac1);
2861 result = 1.0 - nullfrac;
2887 result = 1.0 - result;
2953 Oid opfamily,
int strategy,
bool nulls_first,
2983 *leftstart = *rightstart = 0.0;
2984 *leftend = *rightend = 1.0;
2989 opno = ((
OpExpr *) clause)->opno;
2990 collation = ((
OpExpr *) clause)->inputcollid;
3018 if (op_lefttype == op_righttype)
3022 op_lefttype, op_righttype,
3025 op_lefttype, op_righttype,
3037 op_lefttype, op_righttype,
3040 op_lefttype, op_righttype,
3043 op_lefttype, op_lefttype,
3046 op_righttype, op_righttype,
3051 op_righttype, op_lefttype,
3054 op_righttype, op_lefttype,
3061 if (op_lefttype == op_righttype)
3065 op_lefttype, op_righttype,
3068 op_lefttype, op_righttype,
3073 op_lefttype, op_lefttype,
3082 op_lefttype, op_righttype,
3085 op_lefttype, op_righttype,
3088 op_lefttype, op_lefttype,
3091 op_righttype, op_righttype,
3094 op_lefttype, op_lefttype,
3097 op_righttype, op_righttype,
3100 op_righttype, op_lefttype,
3103 op_righttype, op_lefttype,
3125 &leftmin, &leftmax))
3128 &rightmin, &rightmax))
3135 &leftmax, &leftmin))
3138 &rightmax, &rightmin))
3148 rightmax, op_righttype);
3154 leftmax, op_lefttype);
3164 if (*leftend > *rightend)
3166 else if (*leftend < *rightend)
3169 *leftend = *rightend = 1.0;
3178 rightmin, op_righttype);
3184 leftmin, op_lefttype);
3186 *rightstart = selec;
3194 if (*leftstart < *rightstart)
3196 else if (*leftstart > *rightstart)
3199 *leftstart = *rightstart = 0.0;
3214 *leftstart += stats->stanullfrac;
3216 *leftend += stats->stanullfrac;
3222 *rightstart += stats->stanullfrac;
3224 *rightend += stats->stanullfrac;
3230 if (*leftstart >= *leftend)
3235 if (*rightstart >= *rightend)
3306 foreach(lc, varinfos)
3319 if (vardata->
rel != varinfo->
rel &&
3338 varinfo->
rel = vardata->
rel;
3341 varinfos =
lappend(varinfos, varinfo);
3421 double srf_multiplier = 1.0;
3427 if (estinfo != NULL)
3443 if (groupExprs ==
NIL || (pgset && *pgset ==
NIL))
3456 foreach(l, groupExprs)
3459 double this_srf_multiplier;
3480 if (srf_multiplier < this_srf_multiplier)
3481 srf_multiplier = this_srf_multiplier;
3484 if (
exprType(groupexpr) == BOOLOID)
3507 groupexpr, &vardata);
3530 if (varshere ==
NIL)
3540 foreach(l2, varshere)
3554 if (varinfos ==
NIL)
3557 numdistinct *= srf_multiplier;
3559 numdistinct = ceil(numdistinct);
3561 if (numdistinct > input_rows)
3562 numdistinct = input_rows;
3563 if (numdistinct < 1.0)
3580 double reldistinct = 1;
3581 double relmaxndistinct = reldistinct;
3582 int relvarcount = 0;
3590 relvarinfos =
lappend(relvarinfos, varinfo1);
3595 if (varinfo2->
rel == varinfo1->
rel)
3598 relvarinfos =
lappend(relvarinfos, varinfo2);
3603 newvarinfos =
lappend(newvarinfos, varinfo2);
3626 reldistinct *= mvndistinct;
3627 if (relmaxndistinct < mvndistinct)
3628 relmaxndistinct = mvndistinct;
3633 foreach(l, relvarinfos)
3638 if (relmaxndistinct < varinfo2->ndistinct)
3646 if (estinfo != NULL && varinfo2->
isdefault)
3668 double clamp = rel->
tuples;
3670 if (relvarcount > 1)
3673 if (clamp < relmaxndistinct)
3675 clamp = relmaxndistinct;
3681 if (reldistinct > clamp)
3682 reldistinct = clamp;
3689 if (reldistinct > 0 && rel->
rows < rel->
tuples)
3727 rel->
tuples / reldistinct));
3734 numdistinct *= reldistinct;
3737 varinfos = newvarinfos;
3738 }
while (varinfos !=
NIL);
3741 numdistinct *= srf_multiplier;
3744 numdistinct = ceil(numdistinct);
3747 if (numdistinct > input_rows)
3748 numdistinct = input_rows;
3749 if (numdistinct < 1.0)
3851 stanullfrac = stats->stanullfrac;
3857 avgfreq = (1.0 - stanullfrac) / ndistinct;
3878 if (ndistinct > nbuckets)
3879 estfract = 1.0 / nbuckets;
3881 estfract = 1.0 / ndistinct;
3886 if (avgfreq > 0.0 && *mcv_freq > avgfreq)
3887 estfract *= *mcv_freq / avgfreq;
3894 if (estfract < 1.0e-6)
3896 else if (estfract > 1.0)
3924 path->pathtarget->width,
3933 return hashentrysize * dNumGroups;
3956 List **varinfos,
double *ndistinct)
3977 int nshared_vars = 0;
3978 int nshared_exprs = 0;
3981 if (info->
kind != STATS_EXT_NDISTINCT)
3993 foreach(lc2, *varinfos)
4021 foreach(lc3, info->
exprs)
4033 if (nshared_vars + nshared_exprs < 2)
4043 if ((nshared_exprs > nmatches_exprs) ||
4044 (((nshared_exprs == nmatches_exprs)) && (nshared_vars > nmatches_vars)))
4047 nmatches_vars = nshared_vars;
4048 nmatches_exprs = nshared_exprs;
4049 matched_info = info;
4057 Assert(nmatches_vars + nmatches_exprs > 1);
4079 if (matched_info->
exprs)
4085 foreach(lc2, *varinfos)
4133 foreach(lc3, matched_info->
exprs)
4200 elog(
ERROR,
"corrupt MVNDistinct entry");
4203 foreach(lc, *varinfos)
4225 newlist =
lappend(newlist, varinfo);
4234 newlist =
lappend(newlist, varinfo);
4250 foreach(lc3, matched_info->
exprs)
4265 newlist =
lappend(newlist, varinfo);
4268 *varinfos = newlist;
4308 double *scaledlobound,
double *scaledhibound)
4310 bool failure =
false;
4344 case REGPROCEDUREOID:
4346 case REGOPERATOROID:
4349 case REGCOLLATIONOID:
4351 case REGDICTIONARYOID:
4353 case REGNAMESPACEOID:
4387 lostr, scaledlobound,
4388 histr, scaledhibound);
4401 if (boundstypid != BYTEAOID)
4404 lobound, scaledlobound,
4405 hibound, scaledhibound);
4413 case TIMESTAMPTZOID:
4442 *scaledvalue = *scaledlobound = *scaledhibound = 0;
4476 case REGPROCEDUREOID:
4478 case REGOPERATOROID:
4481 case REGCOLLATIONOID:
4483 case REGDICTIONARYOID:
4485 case REGNAMESPACEOID:
4516 double *scaledvalue,
4518 double *scaledlobound,
4520 double *scaledhibound)
4526 rangelo = rangehi = (
unsigned char) hibound[0];
4527 for (sptr = lobound; *sptr; sptr++)
4529 if (rangelo > (
unsigned char) *sptr)
4530 rangelo = (
unsigned char) *sptr;
4531 if (rangehi < (
unsigned char) *sptr)
4532 rangehi = (
unsigned char) *sptr;
4534 for (sptr = hibound; *sptr; sptr++)
4536 if (rangelo > (
unsigned char) *sptr)
4537 rangelo = (
unsigned char) *sptr;
4538 if (rangehi < (
unsigned char) *sptr)
4539 rangehi = (
unsigned char) *sptr;
4542 if (rangelo <= 'Z' && rangehi >=
'A')
4550 if (rangelo <= 'z' && rangehi >=
'a')
4558 if (rangelo <= '9' && rangehi >=
'0')
4570 if (rangehi - rangelo < 9)
4581 if (*lobound != *hibound || *lobound != *
value)
4583 lobound++, hibound++,
value++;
4597 int slen = strlen(
value);
4618 base = rangehi - rangelo + 1;
4623 int ch = (
unsigned char) *
value++;
4627 else if (ch > rangehi)
4629 num += ((double) (ch - rangelo)) / denom;
4704 if (xfrmlen == INT_MAX)
4707 xfrmstr = (
char *)
palloc(xfrmlen + 1);
4714 Assert(xfrmlen2 <= xfrmlen);
4735 double *scaledvalue,
4737 double *scaledlobound,
4739 double *scaledhibound)
4751 unsigned char *valstr = (
unsigned char *)
VARDATA_ANY(valuep);
4752 unsigned char *lostr = (
unsigned char *)
VARDATA_ANY(loboundp);
4753 unsigned char *histr = (
unsigned char *)
VARDATA_ANY(hiboundp);
4764 minlen =
Min(
Min(valuelen, loboundlen), hiboundlen);
4765 for (
i = 0;
i < minlen;
i++)
4767 if (*lostr != *histr || *lostr != *valstr)
4769 lostr++, histr++, valstr++;
4770 loboundlen--, hiboundlen--, valuelen--;
4783 int rangelo,
int rangehi)
4800 base = rangehi - rangelo + 1;
4803 while (valuelen-- > 0)
4809 else if (ch > rangehi)
4811 num += ((double) (ch - rangelo)) / denom;
4831 case TIMESTAMPTZOID:
4858 return (
double) (timetz->
time + (timetz->
zone * 1000000.0));
4916 if (vardata->
rel && rdata.
rel == NULL)
4924 if (vardata->
rel == NULL && rdata.
rel)
4953 bool *join_is_reversed)
4959 elog(
ERROR,
"join operator should take two arguments");
4967 if (vardata1->
rel &&
4969 *join_is_reversed =
true;
4970 else if (vardata2->
rel &&
4972 *join_is_reversed =
true;
4974 *join_is_reversed =
false;
5042 if (
IsA(basenode,
Var) &&
5043 (varRelid == 0 || varRelid == ((
Var *) basenode)->varno))
5045 Var *var = (
Var *) basenode;
5048 vardata->
var = basenode;
5050 vardata->
atttype = var->vartype;
5079 if (varRelid == 0 || varRelid == relid)
5082 vardata->
rel = onerel;
5109 vardata->
var = node;
5150 if (indexpr_item == NULL)
5153 for (pos = 0; pos <
index->ncolumns; pos++)
5155 if (
index->indexkeys[pos] == 0)
5159 if (indexpr_item == NULL)
5160 elog(
ERROR,
"too few entries in indexprs list");
5164 if (
equal(node, indexkey))
5170 if (
index->unique &&
5171 index->nkeycolumns == 1 &&
5197 elog(
ERROR,
"no function provided to release variable stats with");
5226 rte->securityQuals ==
NIL &&
5247 root->append_rel_array != NULL)
5252 appinfo =
root->append_rel_array[varno];
5258 appinfo =
root->append_rel_array[varno];
5260 if (varno !=
index->rel->relid)
5267 rte->securityQuals ==
NIL &&
5283 indexpr_item =
lnext(
index->indexprs, indexpr_item);
5311 if (info->
kind != STATS_EXT_EXPRESSIONS)
5319 foreach(expr_item, info->
exprs)
5330 if (
equal(node, expr))
5350 rte->securityQuals ==
NIL &&
5368 root->append_rel_array != NULL)
5373 appinfo =
root->append_rel_array[varno];
5379 appinfo =
root->append_rel_array[varno];
5381 if (varno != onerel->
relid)
5388 rte->securityQuals ==
NIL &&
5430 elog(
ERROR,
"no function provided to release variable stats with");
5472 rte->securityQuals ==
NIL &&
5489 root->append_rel_array != NULL)
5496 appinfo =
root->append_rel_array[varno];
5509 int parent_varattno;
5514 parent_varattno = appinfo->parent_colnos[varattno - 1];
5515 if (parent_varattno == 0)
5519 varattno = parent_varattno;
5523 appinfo =
root->append_rel_array[varno];
5543 rte->securityQuals ==
NIL &&
5610 while (levelsup-- > 0)
5612 cteroot = cteroot->parent_root;
5642 if (subroot == NULL)
5653 subquery = subroot->
parse;
5675 if (ste == NULL || ste->resjunk)
5676 elog(
ERROR,
"subquery %s does not have attribute %d",
5677 rte->eref->aliasname, var->
varattno);
5708 if (rte->security_barrier)
5712 if (var &&
IsA(var,
Var) &&
5755 (
errmsg_internal(
"not using statistics because function \"%s\" is not leak-proof",
5775 double stanullfrac = 0.0;
5792 stadistinct = stats->stadistinct;
5793 stanullfrac = stats->stanullfrac;
5795 else if (vardata->
vartype == BOOLOID)
5824 switch (((
Var *) vardata->
var)->varattno)
5853 stadistinct = -1.0 * (1.0 - stanullfrac);
5858 if (stadistinct > 0.0)
5864 if (vardata->
rel == NULL)
5879 if (stadistinct < 0.0)
5906 Oid sortop,
Oid collation,
5911 bool have_data =
false;
5956 STATISTIC_KIND_HISTOGRAM, sortop,
5980 collation, typLen, typByVal,
5981 &tmin, &tmax, &have_data);
5998 bool use_mcvs = have_data;
6002 double sumcommon = 0.0;
6009 if (sumcommon + nullfrac > 0.99999)
6015 collation, typLen, typByVal,
6016 &tmin, &tmax, &have_data);