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
253 Oid sortop,
Oid collation,
257 Oid collation,
int16 typLen,
bool typByVal,
261 Oid sortop,
Oid collation,
277#define SH_PREFIX MCVHashTable
278#define SH_ELEMENT_TYPE MCVHashEntry
279#define SH_KEY_TYPE Datum
281#define SH_HASH_KEY(tab,key) hash_mcv(tab, key)
282#define SH_EQUAL(tab,key0,key1) mcvs_equal(tab, key0, key1)
283#define SH_SCOPE static inline
285#define SH_GET_HASH(tab,ent) (ent)->hash
439 fcinfo->args[0].isnull =
false;
440 fcinfo->args[1].isnull =
false;
443 fcinfo->args[1].value = constval;
445 fcinfo->args[0].value = constval;
452 fcinfo->args[0].value =
sslot.values[
i];
454 fcinfo->args[1].value =
sslot.values[
i];
455 fcinfo->isnull =
false;
488 for (
i = 0;
i <
sslot.nnumbers;
i++)
698 if (block >=
vardata->rel->pages - 1)
764 constval, consttype);
834 fcinfo->args[0].isnull =
false;
835 fcinfo->args[1].isnull =
false;
838 fcinfo->args[1].value = constval;
840 fcinfo->args[0].value = constval;
847 fcinfo->args[0].value =
sslot.values[
i];
849 fcinfo->args[1].value =
sslot.values[
i];
850 fcinfo->isnull =
false;
932 fcinfo->args[0].isnull =
false;
933 fcinfo->args[1].isnull =
false;
936 fcinfo->args[1].value = constval;
938 fcinfo->args[0].value = constval;
945 fcinfo->args[0].value =
sslot.values[
i];
947 fcinfo->args[1].value =
sslot.values[
i];
948 fcinfo->isnull =
false;
988 List *args,
int varRelid,
1064 else if (
selec > 0.9999)
1143 if (
sslot.nvalues > 1 &&
1144 sslot.stacoll == collation &&
1176 if (
sslot.nvalues == 2)
1184 while (lobound < hibound)
1186 int probe = (lobound + hibound) / 2;
1216 lobound =
probe + 1;
1233 else if (lobound >=
sslot.nvalues)
1306 else if (
val <= low)
1308 else if (
val >= high)
1409 double cutoff = 0.01 / (
double) (
sslot.nvalues - 1);
1417 else if (
sslot.nvalues > 1)
1431 fcinfo->args[0].isnull =
false;
1432 fcinfo->args[1].isnull =
false;
1433 fcinfo->args[1].value = constval;
1434 for (
int i = 0;
i <
sslot.nvalues;
i++)
1438 fcinfo->args[0].value =
sslot.values[
i];
1439 fcinfo->isnull =
false;
1453 double cutoff = 0.01 / (
double) (
sslot.nvalues - 1);
1533 &
vardata, constval, consttype);
1644 &&
sslot.nnumbers > 0)
1663 switch (booltesttype)
1690 elog(
ERROR,
"unrecognized booltesttype: %d",
1691 (
int) booltesttype);
1705 switch (booltesttype)
1727 elog(
ERROR,
"unrecognized booltesttype: %d",
1728 (
int) booltesttype);
1742 switch (booltesttype)
1763 elog(
ERROR,
"unrecognized booltesttype: %d",
1764 (
int) booltesttype);
1798 switch (nulltesttype)
1816 elog(
ERROR,
"unrecognized nulltesttype: %d",
1817 (
int) nulltesttype);
1835 switch (nulltesttype)
1844 elog(
ERROR,
"unrecognized nulltesttype: %d",
1845 (
int) nulltesttype);
1908 bool useOr = clause->
useOr;
1947 if (
operator == typentry->
eq_opr)
2035 &elem_values, &elem_nulls, &num_elems);
2053 for (
i = 0;
i < num_elems;
i++)
2068 clause->inputcollid,
2076 clause->inputcollid,
2110 &elmlen, &elmbyval);
2121 foreach(l, arrayexpr->elements)
2132 if (!useOr &&
IsA(elem,
Const) && ((
Const *) elem)->constisnull)
2143 clause->inputcollid,
2151 clause->inputcollid,
2191 dummyexpr->collation = clause->inputcollid;
2195 clause->inputcollid,
2203 clause->inputcollid,
2208 s1 = useOr ? 0.0 : 1.0;
2215 for (
i = 0;
i < 10;
i++)
2245 if (arrayexpr &&
IsA(arrayexpr,
Const))
2261 else if (arrayexpr &&
root)
2281 if (
sslot.nnumbers > 0)
2332 else if (sjinfo ==
NULL)
2543 elog(
ERROR,
"unrecognized join type: %d",
2737 bool op_is_reversed,
2928 bool op_is_reversed,
2945 fcinfo->args[0].isnull =
false;
2946 fcinfo->args[1].isnull =
false;
2975 op_is_reversed = !op_is_reversed;
2991 hash_fcinfo->args[0].isnull =
false;
3038 hash_fcinfo->args[0].isnull =
false;
3078 fcinfo->args[index1].value =
sslot1->values[
i];
3086 fcinfo->args[index2].value =
sslot2->values[
j];
3087 fcinfo->isnull =
false;
3237 result = 1.0 - result;
3344 opno = ((
OpExpr *) clause)->opno;
3345 collation = ((
OpExpr *) clause)->inputcollid;
3578 *
leftend += stats->stanullfrac;
3693 if (
varinfo->ndistinct <= ndistinct)
3710 varinfo->ndistinct = ndistinct;
3711 varinfo->isdefault = isdefault;
4163 while (clauses !=
NIL)
4182 foreach(
lc, clauses)
4194 relids = rinfo->outer_is_left ?
4195 rinfo->right_relids : rinfo->left_relids;
4196 expr = rinfo->outer_is_left ?
4200 root->simple_rel_array[relid]->statlist !=
NIL)
4340 Assert(ndistinct >= 1.0);
4433 if (
sslot.nnumbers > 0)
4483 if (ndistinct > nbuckets)
4520 path->pathtarget->width,
4807 elog(
ERROR,
"corrupt MVNDistinct entry");
5190 if (*lobound != *hibound || *lobound != *
value)
5192 lobound++, hibound++,
value++;
5467 return (
double) (
timetz->time + (
timetz->zone * 1000000.0));
5568 elog(
ERROR,
"join operator should take two arguments");
5662 (varRelid == 0 || varRelid == ((
Var *)
basenode)->varno))
5669 vardata->atttype = var->vartype;
5670 vardata->atttypmod = var->vartypmod;
5700 if (varRelid == 0 || varRelid == relid)
5770 for (pos = 0; pos <
index->ncolumns; pos++)
5772 if (
index->indexkeys[pos] == 0)
5777 elog(
ERROR,
"too few entries in indexprs list");
5787 if (
index->unique &&
5788 index->nkeycolumns == 1 &&
5814 elog(
ERROR,
"no function provided to release variable stats with");
5910 if (
equal(node, expr))
5971 if (
root->glob->lastPHId == 0)
6041 elog(
ERROR,
"no function provided to release variable stats with");
6130 levelsup =
rte->ctelevelsup;
6132 while (levelsup-- > 0)
6136 elog(
ERROR,
"bad levelsup for CTE \"%s\"",
rte->ctename);
6154 elog(
ERROR,
"could not find CTE \"%s\"",
rte->ctename);
6156 elog(
ERROR,
"could not find plan for CTE \"%s\"",
rte->ctename);
6159 elog(
ERROR,
"no plan was made for CTE \"%s\"",
rte->ctename);
6164 if (subroot ==
NULL)
6175 subquery = subroot->
parse;
6197 elog(
ERROR,
"subquery %s does not have attribute %d",
6239 if (
rte->security_barrier)
6243 if (var &&
IsA(var,
Var) &&
6342 if (
root->append_rel_array !=
NULL)
6380 for (attno = 1; attno <=
appinfo->num_child_cols; attno++)
6399 if (attno >
appinfo->num_child_cols)
6412 varno =
appinfo->parent_relid;
6426 if (
rte->securityQuals !=
NIL)
6444 if (varattnos ==
NULL)
6502 if (
index->indexkeys[indexcol] != 0)
6510 colnum =
index->indexkeys[indexcol];
6522 elog(
ERROR,
"no function provided to release variable stats with");
6536 relid =
index->indexoid;
6537 colnum = indexcol + 1;
6548 elog(
ERROR,
"no function provided to release variable stats with");
6582 (
errmsg_internal(
"not using statistics because function \"%s\" is not leakproof",
6602 double stanullfrac = 0.0;
6619 stadistinct = stats->stadistinct;
6620 stanullfrac = stats->stanullfrac;
6680 stadistinct = -1.0 * (1.0 - stanullfrac);
6685 if (stadistinct > 0.0)
6696 ntuples =
vardata->rel->tuples;
6706 if (stadistinct < 0.0)
6733 Oid sortop,
Oid collation,
6786 if (
sslot.stacoll == collation &&
sslot.nvalues > 0)
6807 collation, typLen, typByVal,
6833 for (
i = 0;
i <
sslot.nnumbers;
i++)
6842 collation, typLen, typByVal,
6860 Oid collation,
int16 typLen,
bool typByVal,
6874 for (
int i = 0;
i <
sslot->nvalues;
i++)
6923 Oid sortop,
Oid collation,
6964 if (
index->hypothetical)
6971 if (!
index->canreturn[0])
6978 if (collation !=
index->indexcollations[0])
6986 if (
index->reverse_sort[0])
6992 if (
index->reverse_sort[0])
7018 "get_actual_variable_range workspace",
7208#define VISITED_PAGES_LIMIT 100
7235 elog(
ERROR,
"no data returned for index-only scan");
7250 elog(
ERROR,
"found unexpected null value in index \"%s\"",
7291 elog(
ERROR,
"could not find RelOptInfo for given relids");
7313 foreach(
lc, indexclauses)
7322 result =
lappend(result, rinfo);
7343 foreach(
lc, indexquals)
7380 elog(
ERROR,
"unsupported indexqual type: %d",
7405 Cost indexStartupCost;
7406 Cost indexTotalCost;
7408 double indexCorrelation;
7409 double numIndexPages;
7410 double numIndexTuples;
7411 double spc_random_page_cost;
7412 double num_sa_scans;
7433 if (num_sa_scans < 1)
7463 if (numIndexTuples <= 0.0)
7465 numIndexTuples = indexSelectivity *
index->rel->tuples;
7474 numIndexTuples =
rint(numIndexTuples / num_sa_scans);
7482 if (numIndexTuples >
index->tuples)
7483 numIndexTuples =
index->tuples;
7484 if (numIndexTuples < 1.0)
7485 numIndexTuples = 1.0;
7504 numIndexPages = 1.0;
7508 &spc_random_page_cost,
7541 (
double)
index->pages,
7558 indexTotalCost = numIndexPages * spc_random_page_cost;
7587 indexCorrelation = 0.0;
7657 double indexCorrelation = 0;
7662 index->opcintype[0],
7663 index->opcintype[0],
7675 if (
index->reverse_sort[0])
7678 if (
index->nkeycolumns > 1)
7686 return indexCorrelation;
7691 Cost *indexStartupCost,
Cost *indexTotalCost,
7692 Selectivity *indexSelectivity,
double *indexCorrelation,
7698 double numIndexTuples;
7708 double num_sa_scans;
7795 bool isdefault =
true;
7866 ndistinct =
Max(ndistinct, 1);
7898 num_sa_scans *= ndistinct;
7917 if (
index->pages < num_sa_scans)
7936 if (indexcol !=
iclause->indexcol)
7954 clause_op = op->
opno;
7969 clause_op = saop->
opno;
7987 elog(
ERROR,
"unsupported indexqual type: %d",
7994 index->opfamily[indexcol]);
7995 Assert(op_strategy != 0);
8019 if (
index->unique &&
8020 indexcol ==
index->nkeycolumns - 1 &&
8024 numIndexTuples = 1.0;
8066 num_sa_scans =
Min(num_sa_scans,
ceil(
index->pages * 0.3333333));
8067 num_sa_scans =
Max(num_sa_scans, 1);
8088 numIndexTuples =
rint(numIndexTuples / num_sa_scans);
8119 if (
index->tuples > 1)
8163 Cost *indexStartupCost,
Cost *indexTotalCost,
8164 Selectivity *indexSelectivity,
double *indexCorrelation,
8208 Cost *indexStartupCost,
Cost *indexTotalCost,
8209 Selectivity *indexSelectivity,
double *indexCorrelation,
8229 if (
index->tree_height < 0)
8231 if (
index->pages > 1)
8234 index->tree_height = 0;
8242 if (
index->tuples > 1)
8265 Cost *indexStartupCost,
Cost *indexTotalCost,
8266 Selectivity *indexSelectivity,
double *indexCorrelation,
8287 if (
index->tree_height < 0)
8289 if (
index->pages > 1)
8292 index->tree_height = 0;
8300 if (
index->tuples > 1)
8376 index->opcintype[indexcol],
8377 index->opcintype[indexcol],
8383 elog(
ERROR,
"missing support function %d for attribute %d of index \"%s\"",
8392 collation =
index->indexcollations[indexcol];
8416 for (
i = 0;
i < nentries;
i++)
8484 if (((
Const *) operand)->constisnull)
8623 Cost *indexStartupCost,
Cost *indexTotalCost,
8624 Selectivity *indexSelectivity,
double *indexCorrelation,
8631 numTuples =
index->tuples;
8645 spc_random_page_cost,
8657 if (!
index->hypothetical)
8744 &spc_random_page_cost,
8750 *indexCorrelation = 0.0;
8755 memset(&counts, 0,
sizeof(counts));
8793 elog(
ERROR,
"unsupported GIN indexqual type: %d",
8802 *indexStartupCost = 0;
8803 *indexTotalCost = 0;
8804 *indexSelectivity = 0;
8815 for (
i = 0;
i <
index->nkeycolumns;
i++)
8872 *indexStartupCost = 0;
8873 *indexTotalCost = 0;
8960 (numTuples / (
BLCKSZ / 3)));
8984 *indexTotalCost += *indexStartupCost +
9013 Cost *indexStartupCost,
Cost *indexTotalCost,
9014 Selectivity *indexSelectivity,
double *indexCorrelation,
9023 Cost spc_random_page_cost;
9039 &spc_random_page_cost,
9046 if (!
index->hypothetical)
9080 *indexCorrelation = 0;
9100 "no function provided to release variable stats with");
9131 elog(
ERROR,
"no function provided to release variable stats with");
9153 if (
sslot.nnumbers > 0)
9181 if (*indexCorrelation < 1.0e-10)
9191 *indexSelectivity =
selec;
9213 *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)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, IndexScanInstrumentation *instrument, int nkeys, int norderbys)
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_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_op_hash_functions(Oid opno, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
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)
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 Datum PointerGetDatum(const void *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)
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)
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)