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)
2277 if (
IsA(arrayexpr,
Var) && ((
Var *) arrayexpr)->varno == 0)
2293 if (
sslot.nnumbers > 0)
2344 else if (sjinfo ==
NULL)
2557 elog(
ERROR,
"unrecognized join type: %d",
2751 bool op_is_reversed,
2942 bool op_is_reversed,
2959 fcinfo->args[0].isnull =
false;
2960 fcinfo->args[1].isnull =
false;
2989 op_is_reversed = !op_is_reversed;
3005 hash_fcinfo->args[0].isnull =
false;
3052 hash_fcinfo->args[0].isnull =
false;
3092 fcinfo->args[index1].value =
sslot1->values[
i];
3100 fcinfo->args[index2].value =
sslot2->values[
j];
3101 fcinfo->isnull =
false;
3358 opno = ((
OpExpr *) clause)->opno;
3359 collation = ((
OpExpr *) clause)->inputcollid;
3592 *
leftend += stats->stanullfrac;
3707 if (
varinfo->ndistinct <= ndistinct)
3724 varinfo->ndistinct = ndistinct;
3725 varinfo->isdefault = isdefault;
4177 while (clauses !=
NIL)
4196 foreach(
lc, clauses)
4208 relids = rinfo->outer_is_left ?
4209 rinfo->right_relids : rinfo->left_relids;
4210 expr = rinfo->outer_is_left ?
4214 root->simple_rel_array[relid]->statlist !=
NIL)
4354 Assert(ndistinct >= 1.0);
4447 if (
sslot.nnumbers > 0)
4497 if (ndistinct > nbuckets)
4534 path->pathtarget->width,
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");
6152 levelsup =
rte->ctelevelsup;
6154 while (levelsup-- > 0)
6158 elog(
ERROR,
"bad levelsup for CTE \"%s\"",
rte->ctename);
6176 elog(
ERROR,
"could not find CTE \"%s\"",
rte->ctename);
6178 elog(
ERROR,
"could not find plan for CTE \"%s\"",
rte->ctename);
6181 elog(
ERROR,
"no plan was made for CTE \"%s\"",
rte->ctename);
6186 if (subroot ==
NULL)
6197 subquery = subroot->
parse;
6219 elog(
ERROR,
"subquery %s does not have attribute %d",
6261 if (
rte->security_barrier)
6265 if (var &&
IsA(var,
Var) &&
6364 if (
root->append_rel_array !=
NULL)
6402 for (attno = 1; attno <=
appinfo->num_child_cols; attno++)
6421 if (attno >
appinfo->num_child_cols)
6434 varno =
appinfo->parent_relid;
6448 if (
rte->securityQuals !=
NIL)
6466 if (varattnos ==
NULL)
6524 if (
index->indexkeys[indexcol] != 0)
6532 colnum =
index->indexkeys[indexcol];
6544 elog(
ERROR,
"no function provided to release variable stats with");
6558 relid =
index->indexoid;
6559 colnum = indexcol + 1;
6570 elog(
ERROR,
"no function provided to release variable stats with");
6604 (
errmsg_internal(
"not using statistics because function \"%s\" is not leakproof",
6624 double stanullfrac = 0.0;
6641 stadistinct = stats->stadistinct;
6642 stanullfrac = stats->stanullfrac;
6702 stadistinct = -1.0 * (1.0 - stanullfrac);
6707 if (stadistinct > 0.0)
6718 ntuples =
vardata->rel->tuples;
6728 if (stadistinct < 0.0)
6755 Oid sortop,
Oid collation,
6808 if (
sslot.stacoll == collation &&
sslot.nvalues > 0)
6829 collation, typLen, typByVal,
6855 for (
i = 0;
i <
sslot.nnumbers;
i++)
6864 collation, typLen, typByVal,
6882 Oid collation,
int16 typLen,
bool typByVal,
6896 for (
int i = 0;
i <
sslot->nvalues;
i++)
6945 Oid sortop,
Oid collation,
6986 if (
index->hypothetical)
6993 if (!
index->canreturn[0])
7000 if (collation !=
index->indexcollations[0])
7008 if (
index->reverse_sort[0])
7014 if (
index->reverse_sort[0])
7040 "get_actual_variable_range workspace",
7231#define VISITED_PAGES_LIMIT 100
7258 elog(
ERROR,
"no data returned for index-only scan");
7273 elog(
ERROR,
"found unexpected null value in index \"%s\"",
7314 elog(
ERROR,
"could not find RelOptInfo for given relids");
7336 foreach(
lc, indexclauses)
7366 foreach(
lc, indexquals)
7403 elog(
ERROR,
"unsupported indexqual type: %d",
7428 Cost indexStartupCost;
7429 Cost indexTotalCost;
7431 double indexCorrelation;
7432 double numIndexPages;
7433 double numIndexTuples;
7434 double spc_random_page_cost;
7435 double num_sa_scans;
7456 if (num_sa_scans < 1)
7486 if (numIndexTuples <= 0.0)
7488 numIndexTuples = indexSelectivity *
index->rel->tuples;
7497 numIndexTuples =
rint(numIndexTuples / num_sa_scans);
7505 if (numIndexTuples >
index->tuples)
7506 numIndexTuples =
index->tuples;
7507 if (numIndexTuples < 1.0)
7508 numIndexTuples = 1.0;
7527 numIndexPages = 1.0;
7531 &spc_random_page_cost,
7564 (
double)
index->pages,
7581 indexTotalCost = numIndexPages * spc_random_page_cost;
7610 indexCorrelation = 0.0;
7680 double indexCorrelation = 0;
7685 index->opcintype[0],
7686 index->opcintype[0],
7698 if (
index->reverse_sort[0])
7701 if (
index->nkeycolumns > 1)
7709 return indexCorrelation;
7714 Cost *indexStartupCost,
Cost *indexTotalCost,
7715 Selectivity *indexSelectivity,
double *indexCorrelation,
7721 double numIndexTuples;
7731 double num_sa_scans;
7818 bool isdefault =
true;
7889 ndistinct =
Max(ndistinct, 1);
7921 num_sa_scans *= ndistinct;
7940 if (
index->pages < num_sa_scans)
7959 if (indexcol !=
iclause->indexcol)
7977 clause_op = op->
opno;
7992 clause_op = saop->
opno;
8010 elog(
ERROR,
"unsupported indexqual type: %d",
8017 index->opfamily[indexcol]);
8018 Assert(op_strategy != 0);
8042 if (
index->unique &&
8043 indexcol ==
index->nkeycolumns - 1 &&
8047 numIndexTuples = 1.0;
8089 num_sa_scans =
Min(num_sa_scans,
ceil(
index->pages * 0.3333333));
8090 num_sa_scans =
Max(num_sa_scans, 1);
8111 numIndexTuples =
rint(numIndexTuples / num_sa_scans);
8142 if (
index->tuples > 1)
8186 Cost *indexStartupCost,
Cost *indexTotalCost,
8187 Selectivity *indexSelectivity,
double *indexCorrelation,
8231 Cost *indexStartupCost,
Cost *indexTotalCost,
8232 Selectivity *indexSelectivity,
double *indexCorrelation,
8252 if (
index->tree_height < 0)
8254 if (
index->pages > 1)
8257 index->tree_height = 0;
8265 if (
index->tuples > 1)
8288 Cost *indexStartupCost,
Cost *indexTotalCost,
8289 Selectivity *indexSelectivity,
double *indexCorrelation,
8310 if (
index->tree_height < 0)
8312 if (
index->pages > 1)
8315 index->tree_height = 0;
8323 if (
index->tuples > 1)
8399 index->opcintype[indexcol],
8400 index->opcintype[indexcol],
8406 elog(
ERROR,
"missing support function %d for attribute %d of index \"%s\"",
8415 collation =
index->indexcollations[indexcol];
8439 for (
i = 0;
i < nentries;
i++)
8507 if (((
Const *) operand)->constisnull)
8646 Cost *indexStartupCost,
Cost *indexTotalCost,
8647 Selectivity *indexSelectivity,
double *indexCorrelation,
8654 numTuples =
index->tuples;
8668 spc_random_page_cost,
8680 if (!
index->hypothetical)
8767 &spc_random_page_cost,
8773 *indexCorrelation = 0.0;
8778 memset(&counts, 0,
sizeof(counts));
8816 elog(
ERROR,
"unsupported GIN indexqual type: %d",
8825 *indexStartupCost = 0;
8826 *indexTotalCost = 0;
8827 *indexSelectivity = 0;
8838 for (
i = 0;
i <
index->nkeycolumns;
i++)
8895 *indexStartupCost = 0;
8896 *indexTotalCost = 0;
8983 (numTuples / (
BLCKSZ / 3)));
9007 *indexTotalCost += *indexStartupCost +
9036 Cost *indexStartupCost,
Cost *indexTotalCost,
9037 Selectivity *indexSelectivity,
double *indexCorrelation,
9046 Cost spc_random_page_cost;
9062 &spc_random_page_cost,
9069 if (!
index->hypothetical)
9103 *indexCorrelation = 0;
9123 "no function provided to release variable stats with");
9154 elog(
ERROR,
"no function provided to release variable stats with");
9176 if (
sslot.nnumbers > 0)
9204 if (*indexCorrelation < 1.0e-10)
9214 *indexSelectivity =
selec;
9236 *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, 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)
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)
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)