130 #include "utils/fmgroids.h"
143 #define DEFAULT_PAGE_CPU_MULTIPLIER 50.0
152 double nd1,
double nd2,
153 bool isdefault1,
bool isdefault2,
156 bool have_mcvs1,
bool have_mcvs2);
159 double nd1,
double nd2,
160 bool isdefault1,
bool isdefault2,
163 bool have_mcvs1,
bool have_mcvs2,
170 double *scaledlobound,
double *scaledhibound);
175 double *scaledlobound,
177 double *scaledhibound);
181 double *scaledlobound,
183 double *scaledhibound);
185 int rangelo,
int rangehi);
187 int rangelo,
int rangehi);
195 Oid sortop,
Oid collation,
199 Oid collation,
int16 typLen,
bool typByVal,
203 Oid sortop,
Oid collation,
213 Datum *endpointDatum);
266 &vardata, &other, &varonleft))
276 ((
Const *) other)->constvalue,
277 ((
Const *) other)->constisnull,
295 Datum constval,
bool constisnull,
296 bool varonleft,
bool negate)
299 double nullfrac = 0.0;
319 nullfrac = stats->stanullfrac;
365 fcinfo->args[0].isnull =
false;
366 fcinfo->args[1].isnull =
false;
369 fcinfo->args[1].value = constval;
371 fcinfo->args[0].value = constval;
378 fcinfo->args[0].value = sslot.
values[
i];
380 fcinfo->args[1].value = sslot.
values[
i];
381 fcinfo->isnull =
false;
411 double sumcommon = 0.0;
412 double otherdistinct;
416 selec = 1.0 - sumcommon - nullfrac;
426 if (otherdistinct > 1)
427 selec /= otherdistinct;
451 selec = 1.0 - selec - nullfrac;
467 bool varonleft,
bool negate)
470 double nullfrac = 0.0;
481 nullfrac = stats->stanullfrac;
510 selec = 1.0 - nullfrac;
540 selec = 1.0 - selec - nullfrac;
624 if (block >= vardata->
rel->
pages - 1)
639 block +=
Min(offset / density, 1.0);
646 selec = block / (vardata->
rel->
pages - 0.5);
656 if (iseq == isgt && vardata->
rel->
tuples >= 1.0)
680 mcv_selec =
mcv_selectivity(vardata, &opproc, collation, constval,
true,
688 operator, &opproc, isgt, iseq,
690 constval, consttype);
697 selec = 1.0 - stats->stanullfrac - sumcommon;
699 if (hist_selec >= 0.0)
732 Datum constval,
bool varonleft,
760 fcinfo->args[0].isnull =
false;
761 fcinfo->args[1].isnull =
false;
764 fcinfo->args[1].value = constval;
766 fcinfo->args[0].value = constval;
773 fcinfo->args[0].value = sslot.
values[
i];
775 fcinfo->args[1].value = sslot.
values[
i];
776 fcinfo->isnull =
false;
785 *sumcommonp = sumcommon;
824 Datum constval,
bool varonleft,
825 int min_hist_size,
int n_skip,
833 Assert(min_hist_size > 2 * n_skip);
842 if (sslot.
nvalues >= min_hist_size)
858 fcinfo->args[0].isnull =
false;
859 fcinfo->args[1].isnull =
false;
862 fcinfo->args[1].value = constval;
864 fcinfo->args[0].value = constval;
866 for (
i = n_skip;
i < sslot.
nvalues - n_skip;
i++)
871 fcinfo->args[0].value = sslot.
values[
i];
873 fcinfo->args[1].value = sslot.
values[
i];
874 fcinfo->isnull =
false;
879 result = ((double) nmatch) / ((double) (sslot.
nvalues - 2 * n_skip));
915 double default_selectivity)
927 &vardata, &other, &varonleft))
928 return default_selectivity;
935 ((
Const *) other)->constisnull)
944 Datum constval = ((
Const *) other)->constvalue;
972 selec = default_selectivity;
974 else if (hist_size < 100)
981 double hist_weight = hist_size / 100.0;
983 selec = selec * hist_weight +
984 default_selectivity * (1.0 - hist_weight);
990 else if (selec > 0.9999)
1004 selec *= 1.0 - nullfrac - mcvsum;
1010 selec = default_selectivity;
1042 Oid opoid,
FmgrInfo *opproc,
bool isgt,
bool iseq,
1094 bool have_end =
false;
1110 while (lobound < hibound)
1112 int probe = (lobound + hibound) / 2;
1120 if (probe == 0 && sslot.
nvalues > 2)
1142 lobound = probe + 1;
1159 else if (lobound >= sslot.
nvalues)
1170 double eq_selec = 0;
1192 if (
i == 1 || isgt == iseq)
1194 double otherdistinct;
1212 if (otherdistinct > 1)
1213 eq_selec = 1.0 / otherdistinct;
1232 else if (
val <= low)
1234 else if (
val >= high)
1238 binfrac = (
val - low) / (high - low);
1246 if (isnan(binfrac) ||
1247 binfrac < 0.0 || binfrac > 1.0)
1269 histfrac = (double) (
i - 1) + binfrac;
1270 histfrac /= (double) (sslot.
nvalues - 1);
1305 histfrac += eq_selec * (1.0 - binfrac);
1313 histfrac -= eq_selec;
1320 hist_selec = isgt ? (1.0 - histfrac) : histfrac;
1335 double cutoff = 0.01 / (double) (sslot.
nvalues - 1);
1337 if (hist_selec < cutoff)
1338 hist_selec = cutoff;
1339 else if (hist_selec > 1.0 - cutoff)
1340 hist_selec = 1.0 - cutoff;
1357 fcinfo->args[0].isnull =
false;
1358 fcinfo->args[1].isnull =
false;
1359 fcinfo->args[1].value = constval;
1364 fcinfo->args[0].value = sslot.
values[
i];
1365 fcinfo->isnull =
false;
1370 hist_selec = ((double) nmatch) / ((double) sslot.
nvalues);
1379 double cutoff = 0.01 / (double) (sslot.
nvalues - 1);
1381 if (hist_selec < cutoff)
1382 hist_selec = cutoff;
1383 else if (hist_selec > 1.0 - cutoff)
1384 hist_selec = 1.0 - cutoff;
1418 &vardata, &other, &varonleft))
1434 if (((
Const *) other)->constisnull)
1439 constval = ((
Const *) other)->constvalue;
1440 consttype = ((
Const *) other)->consttype;
1458 selec =
scalarineqsel(root,
operator, isgt, iseq, collation,
1459 &vardata, constval, consttype);
1554 freq_null = stats->stanullfrac;
1570 freq_true = 1.0 - sslot.
numbers[0] - freq_null;
1576 freq_false = 1.0 - freq_true - freq_null;
1578 switch (booltesttype)
1586 selec = 1.0 - freq_null;
1594 selec = 1.0 - freq_true;
1602 selec = 1.0 - freq_false;
1605 elog(
ERROR,
"unrecognized booltesttype: %d",
1606 (
int) booltesttype);
1620 switch (booltesttype)
1628 selec = 1.0 - freq_null;
1633 selec = (1.0 - freq_null) / 2.0;
1639 selec = (freq_null + 1.0) / 2.0;
1642 elog(
ERROR,
"unrecognized booltesttype: %d",
1643 (
int) booltesttype);
1657 switch (booltesttype)
1678 elog(
ERROR,
"unrecognized booltesttype: %d",
1679 (
int) booltesttype);
1711 freq_null = stats->stanullfrac;
1713 switch (nulltesttype)
1728 selec = 1.0 - freq_null;
1731 elog(
ERROR,
"unrecognized nulltesttype: %d",
1732 (
int) nulltesttype);
1737 ((
Var *) vardata.
var)->varattno < 0)
1743 selec = (nulltesttype ==
IS_NULL) ? 0.0 : 1.0;
1750 switch (nulltesttype)
1759 elog(
ERROR,
"unrecognized nulltesttype: %d",
1760 (
int) nulltesttype);
1817 bool is_join_clause,
1823 bool useOr = clause->
useOr;
1824 bool isEquality =
false;
1825 bool isInequality =
false;
1828 Oid nominal_element_type;
1829 Oid nominal_element_collation;
1862 if (
operator == typentry->
eq_opr)
1865 isInequality =
true;
1874 if ((isEquality || isInequality) && !is_join_clause)
1877 nominal_element_type,
1878 isEquality, useOr, varRelid);
1903 if (oprsel == F_EQSEL || oprsel == F_EQJOINSEL)
1905 else if (oprsel == F_NEQSEL || oprsel == F_NEQJOINSEL)
1906 isInequality =
true;
1920 if (rightop &&
IsA(rightop,
Const))
1922 Datum arraydatum = ((
Const *) rightop)->constvalue;
1923 bool arrayisnull = ((
Const *) rightop)->constisnull;
1937 &elmlen, &elmbyval, &elmalign);
1940 elmlen, elmbyval, elmalign,
1941 &elem_values, &elem_nulls, &num_elems);
1957 s1 = s1disjoint = (useOr ? 0.0 : 1.0);
1959 for (
i = 0;
i < num_elems;
i++)
1967 nominal_element_collation,
1974 clause->inputcollid,
1982 clause->inputcollid,
1998 s1disjoint +=
s2 - 1.0;
2003 if ((useOr ? isEquality : isInequality) &&
2004 s1disjoint >= 0.0 && s1disjoint <= 1.0)
2016 &elmlen, &elmbyval);
2025 s1 = s1disjoint = (useOr ? 0.0 : 1.0);
2041 clause->inputcollid,
2049 clause->inputcollid,
2065 s1disjoint +=
s2 - 1.0;
2070 if ((useOr ? isEquality : isInequality) &&
2071 s1disjoint >= 0.0 && s1disjoint <= 1.0)
2087 dummyexpr->
typeId = nominal_element_type;
2088 dummyexpr->typeMod = -1;
2089 dummyexpr->collation = clause->inputcollid;
2093 clause->inputcollid,
2101 clause->inputcollid,
2106 s1 = useOr ? 0.0 : 1.0;
2113 for (
i = 0;
i < 10;
i++)
2139 if (arrayexpr &&
IsA(arrayexpr,
Const))
2141 Datum arraydatum = ((
Const *) arrayexpr)->constvalue;
2142 bool arrayisnull = ((
Const *) arrayexpr)->constisnull;
2180 bool is_join_clause;
2196 is_join_clause =
false;
2198 else if (sjinfo == NULL)
2204 is_join_clause =
false;
2263 bool have_mcvs1 =
false;
2264 bool have_mcvs2 =
false;
2266 bool join_is_reversed;
2270 &vardata1, &vardata2, &join_is_reversed);
2277 memset(&sslot1, 0,
sizeof(sslot1));
2278 memset(&sslot2, 0,
sizeof(sslot2));
2297 if (get_mcv_stats &&
2308 if (get_mcv_stats &&
2317 &vardata1, &vardata2,
2319 isdefault1, isdefault2,
2322 have_mcvs1, have_mcvs2);
2329 selec = selec_inner;
2342 if (!join_is_reversed)
2344 &vardata1, &vardata2,
2346 isdefault1, isdefault2,
2349 have_mcvs1, have_mcvs2,
2357 &vardata2, &vardata1,
2359 isdefault2, isdefault1,
2362 have_mcvs2, have_mcvs1,
2376 selec =
Min(selec, inner_rel->
rows * selec_inner);
2380 elog(
ERROR,
"unrecognized join type: %d",
2406 double nd1,
double nd2,
2407 bool isdefault1,
bool isdefault2,
2410 bool have_mcvs1,
bool have_mcvs2)
2414 if (have_mcvs1 && have_mcvs2)
2432 double nullfrac1 = stats1->stanullfrac;
2433 double nullfrac2 = stats2->stanullfrac;
2434 double matchprodfreq,
2456 fcinfo->args[0].isnull =
false;
2457 fcinfo->args[1].isnull =
false;
2468 matchprodfreq = 0.0;
2474 fcinfo->args[0].value = sslot1->
values[
i];
2482 fcinfo->args[1].value = sslot2->
values[
j];
2483 fcinfo->isnull =
false;
2487 hasmatch1[
i] = hasmatch2[
j] =
true;
2496 matchfreq1 = unmatchfreq1 = 0.0;
2502 unmatchfreq1 += sslot1->
numbers[
i];
2506 matchfreq2 = unmatchfreq2 = 0.0;
2512 unmatchfreq2 += sslot2->
numbers[
i];
2523 otherfreq1 = 1.0 - nullfrac1 - matchfreq1 - unmatchfreq1;
2524 otherfreq2 = 1.0 - nullfrac2 - matchfreq2 - unmatchfreq2;
2536 totalsel1 = matchprodfreq;
2538 totalsel1 += unmatchfreq1 * otherfreq2 / (nd2 - sslot2->
nvalues);
2540 totalsel1 += otherfreq1 * (otherfreq2 + unmatchfreq2) /
2543 totalsel2 = matchprodfreq;
2545 totalsel2 += unmatchfreq2 * otherfreq1 / (nd1 - sslot1->
nvalues);
2547 totalsel2 += otherfreq2 * (otherfreq1 + unmatchfreq1) /
2556 selec = (totalsel1 < totalsel2) ? totalsel1 : totalsel2;
2580 double nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
2581 double nullfrac2 = stats2 ? stats2->stanullfrac : 0.0;
2583 selec = (1.0 - nullfrac1) * (1.0 - nullfrac2);
2603 double nd1,
double nd2,
2604 bool isdefault1,
bool isdefault2,
2607 bool have_mcvs1,
bool have_mcvs2,
2633 if (nd2 >= vardata2->
rel->
rows)
2639 if (nd2 >= inner_rel->
rows)
2641 nd2 = inner_rel->
rows;
2645 if (have_mcvs1 && have_mcvs2 &&
OidIsValid(opfuncoid))
2659 double nullfrac1 = stats1->stanullfrac;
2674 clamped_nvalues2 =
Min(sslot2->
nvalues, nd2);
2686 fcinfo->args[0].isnull =
false;
2687 fcinfo->args[1].isnull =
false;
2690 hasmatch2 = (
bool *)
palloc0(clamped_nvalues2 *
sizeof(
bool));
2703 fcinfo->args[0].value = sslot1->
values[
i];
2705 for (
j = 0;
j < clamped_nvalues2;
j++)
2711 fcinfo->args[1].value = sslot2->
values[
j];
2712 fcinfo->isnull =
false;
2716 hasmatch1[
i] = hasmatch2[
j] =
true;
2748 if (!isdefault1 && !isdefault2)
2752 if (nd1 <= nd2 || nd2 < 0)
2753 uncertainfrac = 1.0;
2755 uncertainfrac = nd2 / nd1;
2758 uncertainfrac = 0.5;
2759 uncertain = 1.0 - matchfreq1 - nullfrac1;
2761 selec = matchfreq1 + uncertainfrac * uncertain;
2769 double nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
2771 if (!isdefault1 && !isdefault2)
2773 if (nd1 <= nd2 || nd2 < 0)
2774 selec = 1.0 - nullfrac1;
2776 selec = (nd2 / nd1) * (1.0 - nullfrac1);
2779 selec = 0.5 * (1.0 - nullfrac1);
2831 result = 1.0 - nullfrac;
2857 result = 1.0 - result;
2923 Oid opfamily,
int strategy,
bool nulls_first,
2953 *leftstart = *rightstart = 0.0;
2954 *leftend = *rightend = 1.0;
2959 opno = ((
OpExpr *) clause)->opno;
2960 collation = ((
OpExpr *) clause)->inputcollid;
2988 if (op_lefttype == op_righttype)
2992 op_lefttype, op_righttype,
2995 op_lefttype, op_righttype,
3007 op_lefttype, op_righttype,
3010 op_lefttype, op_righttype,
3013 op_lefttype, op_lefttype,
3016 op_righttype, op_righttype,
3021 op_righttype, op_lefttype,
3024 op_righttype, op_lefttype,
3031 if (op_lefttype == op_righttype)
3035 op_lefttype, op_righttype,
3038 op_lefttype, op_righttype,
3043 op_lefttype, op_lefttype,
3052 op_lefttype, op_righttype,
3055 op_lefttype, op_righttype,
3058 op_lefttype, op_lefttype,
3061 op_righttype, op_righttype,
3064 op_lefttype, op_lefttype,
3067 op_righttype, op_righttype,
3070 op_righttype, op_lefttype,
3073 op_righttype, op_lefttype,
3095 &leftmin, &leftmax))
3098 &rightmin, &rightmax))
3105 &leftmax, &leftmin))
3108 &rightmax, &rightmin))
3117 selec =
scalarineqsel(root, leop, isgt,
true, collation, &leftvar,
3118 rightmax, op_righttype);
3123 selec =
scalarineqsel(root, revleop, isgt,
true, collation, &rightvar,
3124 leftmax, op_lefttype);
3134 if (*leftend > *rightend)
3136 else if (*leftend < *rightend)
3139 *leftend = *rightend = 1.0;
3147 selec =
scalarineqsel(root, ltop, isgt,
false, collation, &leftvar,
3148 rightmin, op_righttype);
3153 selec =
scalarineqsel(root, revltop, isgt,
false, collation, &rightvar,
3154 leftmin, op_lefttype);
3156 *rightstart = selec;
3164 if (*leftstart < *rightstart)
3166 else if (*leftstart > *rightstart)
3169 *leftstart = *rightstart = 0.0;
3184 *leftstart += stats->stanullfrac;
3186 *leftend += stats->stanullfrac;
3192 *rightstart += stats->stanullfrac;
3194 *rightend += stats->stanullfrac;
3200 if (*leftstart >= *leftend)
3205 if (*rightstart >= *rightend)
3276 foreach(lc, varinfos)
3288 if (vardata->
rel != varinfo->
rel &&
3307 varinfo->
rel = vardata->
rel;
3310 varinfos =
lappend(varinfos, varinfo);
3390 double srf_multiplier = 1.0;
3396 if (estinfo != NULL)
3412 if (groupExprs ==
NIL || (pgset && *pgset ==
NIL))
3425 foreach(l, groupExprs)
3428 double this_srf_multiplier;
3449 if (srf_multiplier < this_srf_multiplier)
3450 srf_multiplier = this_srf_multiplier;
3453 if (
exprType(groupexpr) == BOOLOID)
3476 groupexpr, &vardata);
3499 if (varshere ==
NIL)
3509 foreach(l2, varshere)
3523 if (varinfos ==
NIL)
3526 numdistinct *= srf_multiplier;
3528 numdistinct = ceil(numdistinct);
3530 if (numdistinct > input_rows)
3531 numdistinct = input_rows;
3532 if (numdistinct < 1.0)
3549 double reldistinct = 1;
3550 double relmaxndistinct = reldistinct;
3551 int relvarcount = 0;
3559 relvarinfos =
lappend(relvarinfos, varinfo1);
3564 if (varinfo2->
rel == varinfo1->
rel)
3567 relvarinfos =
lappend(relvarinfos, varinfo2);
3572 newvarinfos =
lappend(newvarinfos, varinfo2);
3595 reldistinct *= mvndistinct;
3596 if (relmaxndistinct < mvndistinct)
3597 relmaxndistinct = mvndistinct;
3602 foreach(l, relvarinfos)
3607 if (relmaxndistinct < varinfo2->ndistinct)
3615 if (estinfo != NULL && varinfo2->
isdefault)
3637 double clamp = rel->
tuples;
3639 if (relvarcount > 1)
3642 if (clamp < relmaxndistinct)
3644 clamp = relmaxndistinct;
3650 if (reldistinct > clamp)
3651 reldistinct = clamp;
3658 if (reldistinct > 0 && rel->
rows < rel->
tuples)
3696 rel->
tuples / reldistinct));
3703 numdistinct *= reldistinct;
3706 varinfos = newvarinfos;
3707 }
while (varinfos !=
NIL);
3710 numdistinct *= srf_multiplier;
3713 numdistinct = ceil(numdistinct);
3716 if (numdistinct > input_rows)
3717 numdistinct = input_rows;
3718 if (numdistinct < 1.0)
3820 stanullfrac = stats->stanullfrac;
3826 avgfreq = (1.0 - stanullfrac) / ndistinct;
3847 if (ndistinct > nbuckets)
3848 estfract = 1.0 / nbuckets;
3850 estfract = 1.0 / ndistinct;
3855 if (avgfreq > 0.0 && *mcv_freq > avgfreq)
3856 estfract *= *mcv_freq / avgfreq;
3863 if (estfract < 1.0e-6)
3865 else if (estfract > 1.0)
3893 path->pathtarget->width,
3902 return hashentrysize * dNumGroups;
3925 List **varinfos,
double *ndistinct)
3946 int nshared_vars = 0;
3947 int nshared_exprs = 0;
3950 if (info->
kind != STATS_EXT_NDISTINCT)
3962 foreach(lc2, *varinfos)
3990 foreach(lc3, info->
exprs)
4002 if (nshared_vars + nshared_exprs < 2)
4012 if ((nshared_exprs > nmatches_exprs) ||
4013 (((nshared_exprs == nmatches_exprs)) && (nshared_vars > nmatches_vars)))
4016 nmatches_vars = nshared_vars;
4017 nmatches_exprs = nshared_exprs;
4018 matched_info = info;
4026 Assert(nmatches_vars + nmatches_exprs > 1);
4048 if (matched_info->
exprs)
4054 foreach(lc2, *varinfos)
4102 foreach(lc3, matched_info->
exprs)
4169 elog(
ERROR,
"corrupt MVNDistinct entry");
4172 foreach(lc, *varinfos)
4194 newlist =
lappend(newlist, varinfo);
4203 newlist =
lappend(newlist, varinfo);
4219 foreach(lc3, matched_info->
exprs)
4234 newlist =
lappend(newlist, varinfo);
4237 *varinfos = newlist;
4277 double *scaledlobound,
double *scaledhibound)
4279 bool failure =
false;
4313 case REGPROCEDUREOID:
4315 case REGOPERATOROID:
4318 case REGCOLLATIONOID:
4320 case REGDICTIONARYOID:
4322 case REGNAMESPACEOID:
4356 lostr, scaledlobound,
4357 histr, scaledhibound);
4370 if (boundstypid != BYTEAOID)
4373 lobound, scaledlobound,
4374 hibound, scaledhibound);
4382 case TIMESTAMPTZOID:
4411 *scaledvalue = *scaledlobound = *scaledhibound = 0;
4445 case REGPROCEDUREOID:
4447 case REGOPERATOROID:
4450 case REGCOLLATIONOID:
4452 case REGDICTIONARYOID:
4454 case REGNAMESPACEOID:
4485 double *scaledvalue,
4487 double *scaledlobound,
4489 double *scaledhibound)
4495 rangelo = rangehi = (
unsigned char) hibound[0];
4496 for (sptr = lobound; *sptr; sptr++)
4498 if (rangelo > (
unsigned char) *sptr)
4499 rangelo = (
unsigned char) *sptr;
4500 if (rangehi < (
unsigned char) *sptr)
4501 rangehi = (
unsigned char) *sptr;
4503 for (sptr = hibound; *sptr; sptr++)
4505 if (rangelo > (
unsigned char) *sptr)
4506 rangelo = (
unsigned char) *sptr;
4507 if (rangehi < (
unsigned char) *sptr)
4508 rangehi = (
unsigned char) *sptr;
4511 if (rangelo <= 'Z' && rangehi >=
'A')
4519 if (rangelo <= 'z' && rangehi >=
'a')
4527 if (rangelo <= '9' && rangehi >=
'0')
4539 if (rangehi - rangelo < 9)
4550 if (*lobound != *hibound || *lobound != *
value)
4552 lobound++, hibound++,
value++;
4566 int slen = strlen(
value);
4587 base = rangehi - rangelo + 1;
4592 int ch = (
unsigned char) *
value++;
4596 else if (ch > rangehi)
4598 num += ((double) (ch - rangelo)) / denom;
4658 xfrmlen = strxfrm(NULL,
val, 0);
4666 if (xfrmlen == INT_MAX)
4669 xfrmstr = (
char *)
palloc(xfrmlen + 1);
4670 xfrmlen2 = strxfrm(xfrmstr,
val, xfrmlen + 1);
4676 Assert(xfrmlen2 <= xfrmlen);
4697 double *scaledvalue,
4699 double *scaledlobound,
4701 double *scaledhibound)
4713 unsigned char *valstr = (
unsigned char *)
VARDATA_ANY(valuep);
4714 unsigned char *lostr = (
unsigned char *)
VARDATA_ANY(loboundp);
4715 unsigned char *histr = (
unsigned char *)
VARDATA_ANY(hiboundp);
4726 minlen =
Min(
Min(valuelen, loboundlen), hiboundlen);
4727 for (
i = 0;
i < minlen;
i++)
4729 if (*lostr != *histr || *lostr != *valstr)
4731 lostr++, histr++, valstr++;
4732 loboundlen--, hiboundlen--, valuelen--;
4745 int rangelo,
int rangehi)
4762 base = rangehi - rangelo + 1;
4765 while (valuelen-- > 0)
4771 else if (ch > rangehi)
4773 num += ((double) (ch - rangelo)) / denom;
4793 case TIMESTAMPTZOID:
4816 return (
double) (timetz->
time + (timetz->
zone * 1000000.0));
4874 if (vardata->
rel && rdata.
rel == NULL)
4882 if (vardata->
rel == NULL && rdata.
rel)
4911 bool *join_is_reversed)
4917 elog(
ERROR,
"join operator should take two arguments");
4925 if (vardata1->
rel &&
4927 *join_is_reversed =
true;
4928 else if (vardata2->
rel &&
4930 *join_is_reversed =
true;
4932 *join_is_reversed =
false;
5000 if (
IsA(basenode,
Var) &&
5001 (varRelid == 0 || varRelid == ((
Var *) basenode)->varno))
5003 Var *var = (
Var *) basenode;
5006 vardata->
var = basenode;
5008 vardata->
atttype = var->vartype;
5037 vardata->
rel = onerel;
5062 vardata->
var = node;
5103 if (indexpr_item == NULL)
5106 for (pos = 0; pos <
index->ncolumns; pos++)
5108 if (
index->indexkeys[pos] == 0)
5112 if (indexpr_item == NULL)
5113 elog(
ERROR,
"too few entries in indexprs list");
5117 if (
equal(node, indexkey))
5123 if (
index->unique &&
5124 index->nkeycolumns == 1 &&
5150 elog(
ERROR,
"no function provided to release variable stats with");
5200 root->append_rel_array != NULL)
5205 appinfo = root->append_rel_array[varno];
5211 appinfo = root->append_rel_array[varno];
5213 if (varno !=
index->rel->relid)
5236 indexpr_item =
lnext(
index->indexprs, indexpr_item);
5264 if (info->
kind != STATS_EXT_EXPRESSIONS)
5272 foreach(expr_item, info->
exprs)
5283 if (
equal(node, expr))
5321 root->append_rel_array != NULL)
5326 appinfo = root->append_rel_array[varno];
5332 appinfo = root->append_rel_array[varno];
5334 if (varno != onerel->
relid)
5383 elog(
ERROR,
"no function provided to release variable stats with");
5429 root->append_rel_array != NULL)
5436 appinfo = root->append_rel_array[varno];
5449 int parent_varattno;
5454 parent_varattno = appinfo->parent_colnos[varattno - 1];
5455 if (parent_varattno == 0)
5459 varattno = parent_varattno;
5463 appinfo = root->append_rel_array[varno];
5551 if (ste == NULL || ste->resjunk)
5552 elog(
ERROR,
"subquery %s does not have attribute %d",
5588 if (var &&
IsA(var,
Var) &&
5631 (
errmsg_internal(
"not using statistics because function \"%s\" is not leak-proof",
5651 double stanullfrac = 0.0;
5668 stadistinct = stats->stadistinct;
5669 stanullfrac = stats->stanullfrac;
5671 else if (vardata->
vartype == BOOLOID)
5700 switch (((
Var *) vardata->
var)->varattno)
5729 stadistinct = -1.0 * (1.0 - stanullfrac);
5734 if (stadistinct > 0.0)
5740 if (vardata->
rel == NULL)
5755 if (stadistinct < 0.0)
5782 Oid sortop,
Oid collation,
5787 bool have_data =
false;
5832 STATISTIC_KIND_HISTOGRAM, sortop,
5856 collation, typLen, typByVal,
5857 &tmin, &tmax, &have_data);
5874 bool use_mcvs = have_data;
5878 double sumcommon = 0.0;
5885 if (sumcommon + nullfrac > 0.99999)
5891 collation, typLen, typByVal,
5892 &tmin, &tmax, &have_data);
5909 Oid collation,
int16 typLen,
bool typByVal,
5914 bool have_data = *p_have_data;
5915 bool found_tmin =
false;
5916 bool found_tmax =
false;
5919 if (opproc->
fn_oid != opfuncoid)
5927 tmin = tmax = sslot->
values[
i];
5928 found_tmin = found_tmax =
true;
5929 *p_have_data = have_data =
true;
5952 *min =
datumCopy(tmin, typByVal, typLen);
5954 *max =
datumCopy(tmax, typByVal, typLen);
5972 Oid sortop,
Oid collation,
5975 bool have_data =
false;
5984 rte = root->simple_rte_array[rel->
relid];
5988 if (rte->
relkind == RELKIND_PARTITIONED_TABLE)
5998 if (
index->relam != BTREE_AM_OID)
6012 if (
index->hypothetical)
6019 if (collation !=
index->indexcollations[0])
6026 if (
index->reverse_sort[0])
6032 if (
index->reverse_sort[0])
6058 "get_actual_variable_range workspace",