131#include "utils/fmgroids.h"
144#define DEFAULT_PAGE_CPU_MULTIPLIER 50.0
153#ifndef USE_ASSERT_CHECKING
154#define EQJOINSEL_MCV_HASH_THRESHOLD 200
156#define EQJOINSEL_MCV_HASH_THRESHOLD 20
255 Oid sortop,
Oid collation,
259 Oid collation,
int16 typLen,
bool typByVal,
263 Oid sortop,
Oid collation,
279#define SH_PREFIX MCVHashTable
280#define SH_ELEMENT_TYPE MCVHashEntry
281#define SH_KEY_TYPE Datum
283#define SH_HASH_KEY(tab,key) hash_mcv(tab, key)
284#define SH_EQUAL(tab,key0,key1) mcvs_equal(tab, key0, key1)
285#define SH_SCOPE static inline
287#define SH_GET_HASH(tab,ent) (ent)->hash
441 fcinfo->args[0].isnull =
false;
442 fcinfo->args[1].isnull =
false;
445 fcinfo->args[1].value = constval;
447 fcinfo->args[0].value = constval;
454 fcinfo->args[0].value =
sslot.values[
i];
456 fcinfo->args[1].value =
sslot.values[
i];
457 fcinfo->isnull =
false;
490 for (
i = 0;
i <
sslot.nnumbers;
i++)
700 if (block >=
vardata->rel->pages - 1)
766 constval, consttype);
836 fcinfo->args[0].isnull =
false;
837 fcinfo->args[1].isnull =
false;
840 fcinfo->args[1].value = constval;
842 fcinfo->args[0].value = constval;
849 fcinfo->args[0].value =
sslot.values[
i];
851 fcinfo->args[1].value =
sslot.values[
i];
852 fcinfo->isnull =
false;
934 fcinfo->args[0].isnull =
false;
935 fcinfo->args[1].isnull =
false;
938 fcinfo->args[1].value = constval;
940 fcinfo->args[0].value = constval;
947 fcinfo->args[0].value =
sslot.values[
i];
949 fcinfo->args[1].value =
sslot.values[
i];
950 fcinfo->isnull =
false;
990 List *args,
int varRelid,
1066 else if (
selec > 0.9999)
1145 if (
sslot.nvalues > 1 &&
1146 sslot.stacoll == collation &&
1178 if (
sslot.nvalues == 2)
1186 while (lobound < hibound)
1188 int probe = (lobound + hibound) / 2;
1218 lobound =
probe + 1;
1235 else if (lobound >=
sslot.nvalues)
1308 else if (
val <= low)
1310 else if (
val >= high)
1411 double cutoff = 0.01 / (
double) (
sslot.nvalues - 1);
1419 else if (
sslot.nvalues > 1)
1433 fcinfo->args[0].isnull =
false;
1434 fcinfo->args[1].isnull =
false;
1435 fcinfo->args[1].value = constval;
1436 for (
int i = 0;
i <
sslot.nvalues;
i++)
1440 fcinfo->args[0].value =
sslot.values[
i];
1441 fcinfo->isnull =
false;
1455 double cutoff = 0.01 / (
double) (
sslot.nvalues - 1);
1535 &
vardata, constval, consttype);
1646 &&
sslot.nnumbers > 0)
1665 switch (booltesttype)
1692 elog(
ERROR,
"unrecognized booltesttype: %d",
1693 (
int) booltesttype);
1707 switch (booltesttype)
1729 elog(
ERROR,
"unrecognized booltesttype: %d",
1730 (
int) booltesttype);
1744 switch (booltesttype)
1765 elog(
ERROR,
"unrecognized booltesttype: %d",
1766 (
int) booltesttype);
1800 switch (nulltesttype)
1818 elog(
ERROR,
"unrecognized nulltesttype: %d",
1819 (
int) nulltesttype);
1837 switch (nulltesttype)
1846 elog(
ERROR,
"unrecognized nulltesttype: %d",
1847 (
int) nulltesttype);
1910 bool useOr = clause->
useOr;
1949 if (
operator == typentry->
eq_opr)
2037 &elem_values, &elem_nulls, &num_elems);
2055 for (
i = 0;
i < num_elems;
i++)
2070 clause->inputcollid,
2078 clause->inputcollid,
2112 &elmlen, &elmbyval);
2123 foreach(l, arrayexpr->elements)
2134 if (!useOr &&
IsA(elem,
Const) && ((
Const *) elem)->constisnull)
2145 clause->inputcollid,
2153 clause->inputcollid,
2193 dummyexpr->collation = clause->inputcollid;
2197 clause->inputcollid,
2205 clause->inputcollid,
2210 s1 = useOr ? 0.0 : 1.0;
2217 for (
i = 0;
i < 10;
i++)
2247 if (arrayexpr &&
IsA(arrayexpr,
Const))
2263 else if (arrayexpr &&
root)
2279 if (
IsA(arrayexpr,
Var) && ((
Var *) arrayexpr)->varno == 0)
2295 if (
sslot.nnumbers > 0)
2346 else if (sjinfo ==
NULL)
2559 elog(
ERROR,
"unrecognized join type: %d",
2753 bool op_is_reversed,
2944 bool op_is_reversed,
2961 fcinfo->args[0].isnull =
false;
2962 fcinfo->args[1].isnull =
false;
2991 op_is_reversed = !op_is_reversed;
3007 hash_fcinfo->args[0].isnull =
false;
3054 hash_fcinfo->args[0].isnull =
false;
3094 fcinfo->args[index1].value =
sslot1->values[
i];
3102 fcinfo->args[index2].value =
sslot2->values[
j];
3103 fcinfo->isnull =
false;
3360 opno = ((
OpExpr *) clause)->opno;
3361 collation = ((
OpExpr *) clause)->inputcollid;
3594 *
leftend += stats->stanullfrac;
3709 if (
varinfo->ndistinct <= ndistinct)
3726 varinfo->ndistinct = ndistinct;
3727 varinfo->isdefault = isdefault;
4179 while (clauses !=
NIL)
4198 foreach(
lc, clauses)
4210 relids = rinfo->outer_is_left ?
4211 rinfo->right_relids : rinfo->left_relids;
4212 expr = rinfo->outer_is_left ?
4216 root->simple_rel_array[relid]->statlist !=
NIL)
4356 Assert(ndistinct >= 1.0);
4449 if (
sslot.nnumbers > 0)
4499 if (ndistinct > nbuckets)
4536 path->pathtarget->width,
4790 for (
int j = 0;
j <
tmpitem->nattributes;
j++)
4821 elog(
ERROR,
"corrupt MVNDistinct entry");
5204 if (*lobound != *hibound || *lobound != *
value)
5206 lobound++, hibound++,
value++;
5489 return (
double) (
timetz->time + (
timetz->zone * 1000000.0));
5590 elog(
ERROR,
"join operator should take two arguments");
5684 (varRelid == 0 || varRelid == ((
Var *)
basenode)->varno))
5691 vardata->atttype = var->vartype;
5692 vardata->atttypmod = var->vartypmod;
5722 if (varRelid == 0 || varRelid == relid)
5792 for (pos = 0; pos <
index->ncolumns; pos++)
5794 if (
index->indexkeys[pos] == 0)
5799 elog(
ERROR,
"too few entries in indexprs list");
5809 if (
index->unique &&
5810 index->nkeycolumns == 1 &&
5836 elog(
ERROR,
"no function provided to release variable stats with");
5932 if (
equal(node, expr))
5993 if (
root->glob->lastPHId == 0)
6063 elog(
ERROR,
"no function provided to release variable stats with");
6153 levelsup =
rte->ctelevelsup;
6155 while (levelsup-- > 0)
6159 elog(
ERROR,
"bad levelsup for CTE \"%s\"",
rte->ctename);
6177 elog(
ERROR,
"could not find CTE \"%s\"",
rte->ctename);
6179 elog(
ERROR,
"could not find plan for CTE \"%s\"",
rte->ctename);
6182 elog(
ERROR,
"no plan was made for CTE \"%s\"",
rte->ctename);
6187 if (subroot ==
NULL)
6198 subquery = subroot->
parse;
6223 elog(
ERROR,
"subquery %s does not have attribute %d",
6280 if (
rte->security_barrier)
6284 if (var &&
IsA(var,
Var) &&
6354 if (stats->stadistinct < 0)
6360 stats->stadistinct = (
float4)
6367 (&stats->stakind1)[k] = 0;
6370 if (
vardata->isunique && stats->stanullfrac > 0.0 && stats->stadistinct > 0)
6371 stats->stanullfrac = 1.0 / (stats->stadistinct + 1.0);
6373 stats->stanullfrac = 0.0;
6456 if (
root->append_rel_array !=
NULL)
6494 for (attno = 1; attno <=
appinfo->num_child_cols; attno++)
6513 if (attno >
appinfo->num_child_cols)
6526 varno =
appinfo->parent_relid;
6540 if (
rte->securityQuals !=
NIL)
6558 if (varattnos ==
NULL)
6616 if (
index->indexkeys[indexcol] != 0)
6624 colnum =
index->indexkeys[indexcol];
6636 elog(
ERROR,
"no function provided to release variable stats with");
6650 relid =
index->indexoid;
6651 colnum = indexcol + 1;
6662 elog(
ERROR,
"no function provided to release variable stats with");
6696 (
errmsg_internal(
"not using statistics because function \"%s\" is not leakproof",
6716 double stanullfrac = 0.0;
6733 stadistinct = stats->stadistinct;
6734 stanullfrac = stats->stanullfrac;
6794 stadistinct = -1.0 * (1.0 - stanullfrac);
6799 if (stadistinct > 0.0)
6810 ntuples =
vardata->rel->tuples;
6820 if (stadistinct < 0.0)
6847 Oid sortop,
Oid collation,
6900 if (
sslot.stacoll == collation &&
sslot.nvalues > 0)
6921 collation, typLen, typByVal,
6947 for (
i = 0;
i <
sslot.nnumbers;
i++)
6956 collation, typLen, typByVal,
6974 Oid collation,
int16 typLen,
bool typByVal,
6988 for (
int i = 0;
i <
sslot->nvalues;
i++)
7037 Oid sortop,
Oid collation,
7078 if (
index->hypothetical)
7085 if (!
index->canreturn[0])
7092 if (collation !=
index->indexcollations[0])
7100 if (
index->reverse_sort[0])
7106 if (
index->reverse_sort[0])
7132 "get_actual_variable_range workspace",
7323#define VISITED_PAGES_LIMIT 100
7350 elog(
ERROR,
"no data returned for index-only scan");
7365 elog(
ERROR,
"found unexpected null value in index \"%s\"",
7406 elog(
ERROR,
"could not find RelOptInfo for given relids");
7428 foreach(
lc, indexclauses)
7458 foreach(
lc, indexquals)
7495 elog(
ERROR,
"unsupported indexqual type: %d",
7520 Cost indexStartupCost;
7521 Cost indexTotalCost;
7523 double indexCorrelation;
7524 double numIndexPages;
7525 double numIndexTuples;
7526 double spc_random_page_cost;
7527 double num_sa_scans;
7548 if (num_sa_scans < 1)
7578 if (numIndexTuples <= 0.0)
7580 numIndexTuples = indexSelectivity *
index->rel->tuples;
7589 numIndexTuples =
rint(numIndexTuples / num_sa_scans);
7597 if (numIndexTuples >
index->tuples)
7598 numIndexTuples =
index->tuples;
7599 if (numIndexTuples < 1.0)
7600 numIndexTuples = 1.0;
7619 numIndexPages = 1.0;
7623 &spc_random_page_cost,
7656 (
double)
index->pages,
7673 indexTotalCost = numIndexPages * spc_random_page_cost;
7702 indexCorrelation = 0.0;
7772 double indexCorrelation = 0;
7777 index->opcintype[0],
7778 index->opcintype[0],
7790 if (
index->reverse_sort[0])
7793 if (
index->nkeycolumns > 1)
7801 return indexCorrelation;
7806 Cost *indexStartupCost,
Cost *indexTotalCost,
7807 Selectivity *indexSelectivity,
double *indexCorrelation,
7813 double numIndexTuples;
7823 double num_sa_scans;
7910 bool isdefault =
true;
7981 ndistinct =
Max(ndistinct, 1);
8013 num_sa_scans *= ndistinct;
8032 if (
index->pages < num_sa_scans)
8051 if (indexcol !=
iclause->indexcol)
8069 clause_op = op->
opno;
8084 clause_op = saop->
opno;
8102 elog(
ERROR,
"unsupported indexqual type: %d",
8109 index->opfamily[indexcol]);
8110 Assert(op_strategy != 0);
8134 if (
index->unique &&
8135 indexcol ==
index->nkeycolumns - 1 &&
8139 numIndexTuples = 1.0;
8181 num_sa_scans =
Min(num_sa_scans,
ceil(
index->pages * 0.3333333));
8182 num_sa_scans =
Max(num_sa_scans, 1);
8203 numIndexTuples =
rint(numIndexTuples / num_sa_scans);
8234 if (
index->tuples > 1)
8278 Cost *indexStartupCost,
Cost *indexTotalCost,
8279 Selectivity *indexSelectivity,
double *indexCorrelation,
8323 Cost *indexStartupCost,
Cost *indexTotalCost,
8324 Selectivity *indexSelectivity,
double *indexCorrelation,
8344 if (
index->tree_height < 0)
8346 if (
index->pages > 1)
8349 index->tree_height = 0;
8357 if (
index->tuples > 1)
8380 Cost *indexStartupCost,
Cost *indexTotalCost,
8381 Selectivity *indexSelectivity,
double *indexCorrelation,
8402 if (
index->tree_height < 0)
8404 if (
index->pages > 1)
8407 index->tree_height = 0;
8415 if (
index->tuples > 1)
8491 index->opcintype[indexcol],
8492 index->opcintype[indexcol],
8498 elog(
ERROR,
"missing support function %d for attribute %d of index \"%s\"",
8507 collation =
index->indexcollations[indexcol];
8531 for (
i = 0;
i < nentries;
i++)
8599 if (((
Const *) operand)->constisnull)
8738 Cost *indexStartupCost,
Cost *indexTotalCost,
8739 Selectivity *indexSelectivity,
double *indexCorrelation,
8746 numTuples =
index->tuples;
8760 spc_random_page_cost,
8772 if (!
index->hypothetical)
8859 &spc_random_page_cost,
8865 *indexCorrelation = 0.0;
8870 memset(&counts, 0,
sizeof(counts));
8908 elog(
ERROR,
"unsupported GIN indexqual type: %d",
8917 *indexStartupCost = 0;
8918 *indexTotalCost = 0;
8919 *indexSelectivity = 0;
8930 for (
i = 0;
i <
index->nkeycolumns;
i++)
8987 *indexStartupCost = 0;
8988 *indexTotalCost = 0;
9075 (numTuples / (
BLCKSZ / 3)));
9099 *indexTotalCost += *indexStartupCost +
9128 Cost *indexStartupCost,
Cost *indexTotalCost,
9129 Selectivity *indexSelectivity,
double *indexCorrelation,
9138 Cost spc_random_page_cost;
9154 &spc_random_page_cost,
9161 if (!
index->hypothetical)
9195 *indexCorrelation = 0;
9215 "no function provided to release variable stats with");
9246 elog(
ERROR,
"no function provided to release variable stats with");
9268 if (
sslot.nnumbers > 0)
9296 if (*indexCorrelation < 1.0e-10)
9306 *indexSelectivity =
selec;
9328 *indexTotalCost = *indexStartupCost +
Datum idx(PG_FUNCTION_ARGS)
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
StrategyNumber IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok)
CompareType IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok)
#define DatumGetArrayTypeP(X)
Selectivity scalararraysel_containment(PlannerInfo *root, Node *leftop, Node *rightop, Oid elemtype, bool isEquality, bool useOr, int varRelid)
bool array_contains_nulls(const ArrayType *array)
void deconstruct_array(const ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
int ArrayGetNItems(int ndim, const int *dims)
#define AttrNumberIsForUserDefinedAttr(attributeNumber)
#define InvalidAttrNumber
Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS)
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_make_singleton(int x)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
bool bms_get_singleton_member(const Bitmapset *a, int *member)
#define InvalidBlockNumber
static Datum values[MAXATTR]
void brinGetStats(Relation index, BrinStatsData *stats)
#define BRIN_DEFAULT_PAGES_PER_RANGE
#define REVMAP_PAGE_MAXITEMS
void ReleaseBuffer(Buffer buffer)
#define TextDatumGetCString(d)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
#define MemSet(start, val, len)
#define OidIsValid(objectId)
int NumRelids(PlannerInfo *root, Node *clause)
Node * estimate_expression_value(PlannerInfo *root, Node *node)
bool contain_volatile_functions(Node *clause)
double expression_returns_set_rows(PlannerInfo *root, Node *clause)
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Selectivity clause_selectivity(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
double clamp_row_est(double nrows)
double cpu_index_tuple_cost
double date2timestamp_no_overflow(DateADT dateVal)
static TimeTzADT * DatumGetTimeTzADTP(Datum X)
static DateADT DatumGetDateADT(Datum X)
static TimeADT DatumGetTimeADT(Datum X)
Datum datumCopy(Datum value, bool typByVal, int typLen)
bool datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2, Oid opfamily)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
HeapTuple statext_expressions_load(Oid stxoid, bool inh, int idx)
#define palloc_object(type)
#define palloc0_object(type)
Datum FunctionCall4Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
void set_fn_opclass_options(FmgrInfo *flinfo, bytea *options)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Datum FunctionCall5Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Datum DirectFunctionCall5Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
#define DatumGetByteaPP(X)
#define PG_RETURN_FLOAT8(x)
#define PG_GETARG_POINTER(n)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define DirectFunctionCall1(func, arg1)
#define LOCAL_FCINFO(name, nargs)
#define FunctionCallInvoke(fcinfo)
#define PG_GETARG_INT32(n)
#define PG_GET_COLLATION()
#define PG_GETARG_INT16(n)
#define GIN_EXTRACTQUERY_PROC
#define GIN_SEARCH_MODE_DEFAULT
#define GIN_SEARCH_MODE_INCLUDE_EMPTY
void ginGetStats(Relation index, GinStatsData *stats)
HeapTuple heap_copytuple(HeapTuple tuple)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, IndexScanInstrumentation *instrument, int nkeys, int norderbys, uint32 flags)
void index_close(Relation relation, LOCKMODE lockmode)
ItemPointer index_getnext_tid(IndexScanDesc scan, ScanDirection direction)
bool index_fetch_heap(IndexScanDesc scan, TupleTableSlot *slot)
void index_endscan(IndexScanDesc scan)
Relation index_open(Oid relationId, LOCKMODE lockmode)
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor, Datum *values, bool *isnull)
bool match_index_to_operand(Node *operand, int indexcol, IndexOptInfo *index)
static OffsetNumber ItemPointerGetOffsetNumberNoCheck(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumberNoCheck(const ItemPointerData *pointer)
ItemPointerData * ItemPointer
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * list_copy(const List *oldlist)
bool list_member_ptr(const List *list, const void *datum)
void list_free(List *list)
bool list_member_int(const List *list, int datum)
void list_free_deep(List *list)
char * get_rel_name(Oid relid)
void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, int *strategy, Oid *lefttype, Oid *righttype)
RegProcedure get_oprrest(Oid opno)
void free_attstatsslot(AttStatsSlot *sslot)
bool comparison_ops_are_compatible(Oid opno1, Oid opno2)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
RegProcedure get_oprjoin(Oid opno)
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
RegProcedure get_opcode(Oid opno)
int get_op_opfamily_strategy(Oid opno, Oid opfamily)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
bool get_op_hash_functions_ext(Oid opno, Oid inputtype, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
bool get_func_leakproof(Oid funcid)
char * get_func_name(Oid funcid)
Oid get_base_element_type(Oid typid)
Oid get_opfamily_method(Oid opfid)
bool get_attstatsslot(AttStatsSlot *sslot, HeapTuple statstuple, int reqkind, Oid reqop, int flags)
Oid get_negator(Oid opno)
Oid get_commutator(Oid opno)
#define ATTSTATSSLOT_NUMBERS
#define ATTSTATSSLOT_VALUES
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
MVNDistinct * statext_ndistinct_load(Oid mvoid, bool inh)
double convert_network_to_scalar(Datum value, Oid typid, bool *failure)
Size hash_agg_entry_size(int numTrans, Size tupleWidth, Size transitionSpace)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
#define expression_tree_mutator(n, m, c)
static Node * get_rightop(const void *clause)
static bool is_opclause(const void *clause)
static bool is_funcclause(const void *clause)
#define expression_tree_walker(n, w, c)
static Node * get_leftop(const void *clause)
#define IsA(nodeptr, _type_)
#define PVC_RECURSE_AGGREGATES
#define PVC_RECURSE_PLACEHOLDERS
#define PVC_RECURSE_WINDOWFUNCS
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
bool targetIsInSortList(TargetEntry *tle, Oid sortop, List *sortList)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
#define IS_SIMPLE_REL(rel)
#define planner_rt_fetch(rti, root)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_delete_current(lst, var_or_cell)
#define for_each_from(cell, lst, N)
static void * list_nth(const List *list, int n)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
static int list_nth_int(const List *list, int n)
pg_locale_t pg_newlocale_from_collation(Oid collid)
size_t pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
#define STATISTIC_NUM_SLOTS
FormData_pg_statistic * Form_pg_statistic
Selectivity restriction_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, int varRelid)
bool has_unique_index(RelOptInfo *rel, AttrNumber attno)
Selectivity join_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, JoinType jointype, SpecialJoinInfo *sjinfo)
static uint32 DatumGetUInt32(Datum X)
static bool DatumGetBool(Datum X)
static int64 DatumGetInt64(Datum X)
static float4 DatumGetFloat4(Datum X)
static Oid DatumGetObjectId(Datum X)
static Datum Int16GetDatum(int16 X)
static Datum UInt16GetDatum(uint16 X)
static Datum BoolGetDatum(bool X)
static float8 DatumGetFloat8(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static char DatumGetChar(Datum X)
static Datum Int32GetDatum(int32 X)
static int16 DatumGetInt16(Datum X)
static int32 DatumGetInt32(Datum X)
#define PointerGetDatum(X)
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
GlobalVisState * GlobalVisTestFor(Relation rel)
#define RelationGetRelationName(relation)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
RelOptInfo * find_base_rel_noerr(PlannerInfo *root, int relid)
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Node * remove_nulling_relids(Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
void ScanKeyEntryInitialize(ScanKey entry, int flags, AttrNumber attributeNumber, StrategyNumber strategy, Oid subtype, Oid collation, RegProcedure procedure, Datum argument)
static bool get_actual_variable_endpoint(Relation heapRel, Relation indexRel, ScanDirection indexscandir, ScanKey scankeys, int16 typLen, bool typByVal, TupleTableSlot *tableslot, MemoryContext outercontext, Datum *endpointDatum)
bool get_restriction_variable(PlannerInfo *root, List *args, int varRelid, VariableStatData *vardata, Node **other, bool *varonleft)
Datum neqsel(PG_FUNCTION_ARGS)
static RelOptInfo * find_join_input_rel(PlannerInfo *root, Relids relids)
void mergejoinscansel(PlannerInfo *root, Node *clause, Oid opfamily, CompareType cmptype, bool nulls_first, Selectivity *leftstart, Selectivity *leftend, Selectivity *rightstart, Selectivity *rightend)
static void adjust_statstuple_for_grouping(PlannerInfo *subroot, Var *var, VariableStatData *vardata)
bool all_rows_selectable(PlannerInfo *root, Index varno, Bitmapset *varattnos)
static Node * strip_all_phvs_mutator(Node *node, void *context)
static bool get_variable_range(PlannerInfo *root, VariableStatData *vardata, Oid sortop, Oid collation, Datum *min, Datum *max)
void btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
List * get_quals_from_indexclauses(List *indexclauses)
static void convert_string_to_scalar(char *value, double *scaledvalue, char *lobound, double *scaledlobound, char *hibound, double *scaledhibound)
double var_eq_const(VariableStatData *vardata, Oid oproid, Oid collation, Datum constval, bool constisnull, bool varonleft, bool negate)
List * add_predicate_to_index_quals(IndexOptInfo *index, List *indexQuals)
double generic_restriction_selectivity(PlannerInfo *root, Oid oproid, Oid collation, List *args, int varRelid, double default_selectivity)
#define VISITED_PAGES_LIMIT
void spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
static double eqjoinsel_inner(FmgrInfo *eqproc, Oid collation, Oid hashLeft, Oid hashRight, VariableStatData *vardata1, VariableStatData *vardata2, double nd1, double nd2, bool isdefault1, bool isdefault2, AttStatsSlot *sslot1, AttStatsSlot *sslot2, Form_pg_statistic stats1, Form_pg_statistic stats2, bool have_mcvs1, bool have_mcvs2, bool *hasmatch1, bool *hasmatch2, int *p_nmatches)
Datum scalargtsel(PG_FUNCTION_ARGS)
#define DEFAULT_PAGE_CPU_MULTIPLIER
static bool estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, List **varinfos, double *ndistinct)
Selectivity booltestsel(PlannerInfo *root, BoolTestType booltesttype, Node *arg, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Datum eqjoinsel(PG_FUNCTION_ARGS)
double estimate_array_length(PlannerInfo *root, Node *arrayexpr)
double mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Oid collation, Datum constval, bool varonleft, double *sumcommonp)
Selectivity nulltestsel(PlannerInfo *root, NullTestType nulltesttype, Node *arg, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
static void examine_simple_variable(PlannerInfo *root, Var *var, VariableStatData *vardata)
static List * add_unique_group_var(PlannerInfo *root, List *varinfos, Node *var, VariableStatData *vardata)
Datum matchingsel(PG_FUNCTION_ARGS)
Datum eqsel(PG_FUNCTION_ARGS)
static bool mcvs_equal(MCVHashTable_hash *tab, Datum key0, Datum key1)
void examine_variable(PlannerInfo *root, Node *node, int varRelid, VariableStatData *vardata)
Datum scalargtjoinsel(PG_FUNCTION_ARGS)
static double convert_one_string_to_scalar(char *value, int rangelo, int rangehi)
static Datum scalarineqsel_wrapper(PG_FUNCTION_ARGS, bool isgt, bool iseq)
static Node * strip_all_phvs_deep(PlannerInfo *root, Node *node)
void gincostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
static void eqjoinsel_find_matches(FmgrInfo *eqproc, Oid collation, Oid hashLeft, Oid hashRight, bool op_is_reversed, AttStatsSlot *sslot1, AttStatsSlot *sslot2, int nvalues1, int nvalues2, bool *hasmatch1, bool *hasmatch2, int *p_nmatches, double *p_matchprodfreq)
static double convert_timevalue_to_scalar(Datum value, Oid typid, bool *failure)
static double convert_numeric_to_scalar(Datum value, Oid typid, bool *failure)
#define EQJOINSEL_MCV_HASH_THRESHOLD
static Node * strip_array_coercion(Node *node)
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset, EstimationInfo *estinfo)
static bool convert_to_scalar(Datum value, Oid valuetypid, Oid collid, double *scaledvalue, Datum lobound, Datum hibound, Oid boundstypid, double *scaledlobound, double *scaledhibound)
double ineq_histogram_selectivity(PlannerInfo *root, VariableStatData *vardata, Oid opoid, FmgrInfo *opproc, bool isgt, bool iseq, Oid collation, Datum constval, Oid consttype)
void genericcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, GenericCosts *costs)
List * estimate_multivariate_bucketsize(PlannerInfo *root, RelOptInfo *inner, List *hashclauses, Selectivity *innerbucketsize)
Datum scalarltjoinsel(PG_FUNCTION_ARGS)
static bool gincost_pattern(IndexOptInfo *index, int indexcol, Oid clause_op, Datum query, GinQualCounts *counts)
static bool contain_placeholder_walker(Node *node, void *context)
struct MCVHashTable_hash MCVHashTable_hash
void brincostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
void gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Datum scalargejoinsel(PG_FUNCTION_ARGS)
static double eqjoinsel_semi(FmgrInfo *eqproc, Oid collation, Oid hashLeft, Oid hashRight, bool op_is_reversed, VariableStatData *vardata1, VariableStatData *vardata2, double nd1, double nd2, bool isdefault1, bool isdefault2, AttStatsSlot *sslot1, AttStatsSlot *sslot2, Form_pg_statistic stats1, Form_pg_statistic stats2, bool have_mcvs1, bool have_mcvs2, bool *hasmatch1, bool *hasmatch2, int *p_nmatches, RelOptInfo *inner_rel)
get_index_stats_hook_type get_index_stats_hook
Datum matchingjoinsel(PG_FUNCTION_ARGS)
static bool gincost_scalararrayopexpr(PlannerInfo *root, IndexOptInfo *index, int indexcol, ScalarArrayOpExpr *clause, double numIndexEntries, GinQualCounts *counts)
double histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Oid collation, Datum constval, bool varonleft, int min_hist_size, int n_skip, int *hist_size)
static uint32 hash_mcv(MCVHashTable_hash *tab, Datum key)
Selectivity boolvarsel(PlannerInfo *root, Node *arg, int varRelid)
static void examine_indexcol_variable(PlannerInfo *root, IndexOptInfo *index, int indexcol, VariableStatData *vardata)
Datum scalarlesel(PG_FUNCTION_ARGS)
Datum scalargesel(PG_FUNCTION_ARGS)
static double scalarineqsel(PlannerInfo *root, Oid operator, bool isgt, bool iseq, Oid collation, VariableStatData *vardata, Datum constval, Oid consttype)
static double convert_one_bytea_to_scalar(unsigned char *value, int valuelen, int rangelo, int rangehi)
Selectivity scalararraysel(PlannerInfo *root, ScalarArrayOpExpr *clause, bool is_join_clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Datum scalarltsel(PG_FUNCTION_ARGS)
static double btcost_correlation(IndexOptInfo *index, VariableStatData *vardata)
double var_eq_non_const(VariableStatData *vardata, Oid oproid, Oid collation, Node *other, bool varonleft, bool negate)
static bool get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata, Oid sortop, Oid collation, Datum *min, Datum *max)
Datum scalarlejoinsel(PG_FUNCTION_ARGS)
double get_variable_numdistinct(VariableStatData *vardata, bool *isdefault)
bool statistic_proc_security_check(VariableStatData *vardata, Oid func_oid)
void hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Datum neqjoinsel(PG_FUNCTION_ARGS)
double estimate_hashagg_tablesize(PlannerInfo *root, Path *path, const AggClauseCosts *agg_costs, double dNumGroups)
void estimate_hash_bucket_stats(PlannerInfo *root, Node *hashkey, double nbuckets, Selectivity *mcv_freq, Selectivity *bucketsize_frac)
static void convert_bytea_to_scalar(Datum value, double *scaledvalue, Datum lobound, double *scaledlobound, Datum hibound, double *scaledhibound)
Cost index_other_operands_eval_cost(PlannerInfo *root, List *indexquals)
get_relation_stats_hook_type get_relation_stats_hook
Selectivity rowcomparesel(PlannerInfo *root, RowCompareExpr *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
static bool gincost_opexpr(PlannerInfo *root, IndexOptInfo *index, int indexcol, OpExpr *clause, GinQualCounts *counts)
static void ReleaseDummy(HeapTuple tuple)
static char * convert_string_datum(Datum value, Oid typid, Oid collid, bool *failure)
static double eqsel_internal(PG_FUNCTION_ARGS, bool negate)
static void get_stats_slot_range(AttStatsSlot *sslot, Oid opfuncoid, FmgrInfo *opproc, Oid collation, int16 typLen, bool typByVal, Datum *min, Datum *max, bool *p_have_data)
void get_join_variables(PlannerInfo *root, List *args, SpecialJoinInfo *sjinfo, VariableStatData *vardata1, VariableStatData *vardata2, bool *join_is_reversed)
#define DEFAULT_NOT_UNK_SEL
#define ReleaseVariableStats(vardata)
#define CLAMP_PROBABILITY(p)
bool(* get_relation_stats_hook_type)(PlannerInfo *root, RangeTblEntry *rte, AttrNumber attnum, VariableStatData *vardata)
#define DEFAULT_RANGE_INEQ_SEL
bool(* get_index_stats_hook_type)(PlannerInfo *root, Oid indexOid, AttrNumber indexattnum, VariableStatData *vardata)
#define DEFAULT_MATCHING_SEL
#define DEFAULT_NUM_DISTINCT
#define SELFLAG_USED_DEFAULT
#define InitNonVacuumableSnapshot(snapshotdata, vistestp)
void get_tablespace_page_costs(Oid spcid, double *spc_random_page_cost, double *spc_seq_page_cost)
#define BTLessStrategyNumber
#define BTEqualStrategyNumber
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Selectivity indexSelectivity
BlockNumber numNonLeafPages
double spc_random_page_cost
bool attHasNormalScan[INDEX_MAX_KEYS]
bool attHasFullScan[INDEX_MAX_KEYS]
FunctionCallInfo hash_fcinfo
FunctionCallInfo equal_fcinfo
MVNDistinctItem items[FLEXIBLE_ARRAY_MEMBER]
#define FirstLowInvalidHeapAttributeNumber
#define TableOidAttributeNumber
#define SelfItemPointerAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache3(SysCacheIdentifier cacheId, Datum key1, Datum key2, Datum key3)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
static Interval * DatumGetIntervalP(Datum X)
static Timestamp DatumGetTimestamp(Datum X)
static TimestampTz DatumGetTimestampTz(Datum X)
Relids pull_varnos(PlannerInfo *root, Node *node)
List * pull_var_clause(Node *node, int flags)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
#define VM_ALL_VISIBLE(r, b, v)