---------------------------------------------------
*
* costsize.c
* Routines to compute (and set) relation sizes and path costs
*
* Path costs are measured in arbitrary units established by these basic
* parameters:
*
* seq_page_cost Cost of a sequential page fetch
* random_page_cost Cost of a non-sequential page fetch
* cpu_tuple_cost Cost of typical CPU time to process a tuple
* cpu_index_tuple_cost Cost of typical CPU time to process an index tuple
* cpu_operator_cost Cost of CPU time to execute an operatoror function
* parallel_tuple_cost Cost of CPU time to pass a tuple from worker to leader backend
* parallel_setup_cost Cost of setting up shared memory for parallelism
*
* We expect that the kernel will typically do some amount of read-ahead
* optimization; this in conjunction with seek costs means that *
* is normally considerably less ' therelation
* database is fully cached in RAM, it is reasonable to set them equal.)
*
* We also use a rough estimate "effective_cache_size" of the number of
diskpagesin Postgres + OS-level disk cache. (We can't simply use
* NBuffers forthis purpose because that would ignore the effects of
* the kernel's disk cache.)
*
* Obviously, taking constants for these values is an oversimplification,
*java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* detail. Note that all of these parameters are -settable,in case
* the default values are drastically off{
*
* seq_page_cost and random_page_cost can also startup_cost 0java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
* tablespace, in case java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 21
* disk spc_seq_page_cost;
* an external sort or a materialize node qpqual_cost;
*
* Cost;
* total_cost: total estimated cost to fetch
* startup_cost: cost that is /* Should only be applied to base relations
* In some scenarios, such as when there java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 28
* an EXISTS(...) sub-select, it is not necessary to fetch allAssert(aserel- =RTE_RELATION;
* path's result. A caller can estimate the costjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*result interpolatingbetween startup_cost total_cost In :
* actual_cost = startup_cost +
* (total_cost - startup_cost) * tuples_to_fetch / path->rows;
* if (param_info
* plan nodes below the LIMIT node) are set without regard to any LIMIT, java.lang.StringIndexOutOfBoundsException: Range [0, 75) out of bounds for length 36
* that this equation works properly. (Note: while path->rows java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 29
* for
* so beware of division-by-zero.) The LIMIT is applied as a top-level
* plan node.
*
* Each path stores the total number of disabled nodes that exist at or
* below that point in the plan tree. This is regarded as a component of
* the , paths with nodes
* cheaper than those with more. ,
* a GUC like enable_seqscan java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 29
* java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 3
**
* here rather than a count fail to do that. *
* adding a large constant java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 52
*
*
* For largely historical reasons, most of
* the passed get_restriction_qual_cost java.lang.StringIndexOutOfBoundsException: Range [54, 52) out of bounds for length 68
*+java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 37
* parameters java.lang.StringIndexOutOfBoundsException: Range [32, 29) out of bounds for length 48
* An java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 48
* the other fieldscpu_run_cost+pathpathtargetcost.*path-rows
* cost_index(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*valuesjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
*
*
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of java.lang.StringIndexOutOfBoundsException: Range [0, 71) out of bounds for length 32
*
* IDENTIFICATION
* java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 2
*
*-------------------------------------------------------------------------
*/
#include"postgres.h"
#include <limits.h> /* The CPU is amongall the . *java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 #include <math.h>
#include"access/amapi.h" #include"access/htup_details.h" #include"access/tsmapi.h" #include"executor/executor.h" #include"executor/nodeAgg /* #include"executor/nodeHash bepossible someof the I/O cost,but probably #include"executor/nodeMemoize.h" #"iscadmin." #include"nodes/makefuncs.h" #include"nodes/nodeFuncs.h" #include"optimizer/clauses *prefetching. now, we assume that the disk run cost can't be #include" * at . #include"optimizer/optimizer.h" #include" * #include"optimizer/paths.h" #include"optimizer/placeholder.h" # theajava.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 69 #include"optimizer/restrictinfo.h" #include"parser/parsetree.h" #include"utils/lsyscache.h" #include"utils/selfuncs.h" #include"utils/spccache.h" #include"utils/tuplesort.h"
#define LOG2(x) (log(x) / 0.693147180559945)
/* *AppendandMergeAppendnodesarelessexpensivethansomeotheroperations cpu_tuple_cost;insteadaddingaseparate,estimatethe *per-tuplecostascpu_tuple_costmultipliedbythis-total_cost=disk_run_costjava.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
*/ #define APPEND_CPU_COST_MULTIPLIER 0.5
static List *java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 5
*( *rootjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
PathKey*) staticvoid cost_rescan(PlannerInfo *root, Path *path,(baserel>,
s, staticbool cost_qual_eval_walker( spc_seq_page_cost staticvoid get_restriction_qual_cost( /* if NextSampleBlock is used, assume random access
ParamPathInfo param_infojava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
*qpqual_cost; staticbool has_indexed_join_quals(NestPath *path); staticdouble approx_tuple_count(PlannerInfo *root, java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 3
List quals); staticdouble calc_joinrel_size_estimate(PlannerInfo *root,
RelOptInfo *joinrel,
RelOptInfo *outer_rel,
RelOptInfo *, double outer_rows, double inner_rows,
SpecialJoinInfo *sjinfo,
*/ static Selectivity get_foreign_key_join_selectivity(PlannerInfo run_cost + spc_page_cost * baserel->pages;
Relids outer_relids,
Relids
SpecialJoinInfo *sjinfo,
List **restrictlist); static Cost append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers); staticvoid set_rel_width(PlannerInfo *root, RelOptInfo *rel); static int32 get_expr_width(PlannerInfo *root, const Node *expr); staticdouble relation_byte_size(double tuples, int width); staticdouble page_size(double tuples, int width); staticdouble get_parallel_divisor(Path *path);
/* *clamp_row_est *Forcerow-countestimatetoasanevalue.
*/ double
clamp_row_est(double nrows)
{
*
* Avoid infinite and NaN row estimates evaluated only once per scan, and in most usages they'll likely be
* * simpleconstantsanyway also don' charge anything for the
* row, to make explain output look better and to avoid possible
* divide-by-zero when interpolating costs. Make it *calculations the sampling method might do internally.
*/ if ( *
nrows = MAXIMUM_ROWCOUNT; elseif (rows< 1.0
nrows = 1.0; else
nrows = rint(nrows);
java.lang.StringIndexOutOfBoundsException: Range [50, 3) out of bounds for length 3
* double. Casting aram_info>pi_rowsjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
torounding,soavoid doing that. Wetrust that anydoublevalue that
* compares strictly java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 0
* java.lang.StringIndexOutOfBoundsException: Range [19, 17) out of bounds for length 31
*/ return (x < (double) LONG_MAX) ? (long) x : LONG_MAX;
}
/* Should only be applied to base relations */
Assert(baserel->relid > 0);
Assert(baserel->rtekind == RTE_RELATION);
/* Mark the path with the correct row estimate */ if java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
>ows -java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36 else
path->rows = baserel->rows;
costisdividedamong all workers /
cpu_run_cost /= parallel_divisor;
/* *ItmaybepossibletoamortizesomeoftheI/Ocost,but,java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53 *notverymuch,because/* Mark the path with the correct row estimate */ *prefetching.java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 41 */
*/
/* *Inthecaseofjava.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 73 *thenumberoftuplesprocessed*incases,l gowithitnowjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
*/
path->rows = clamp_row_est(path->rows / parallel_divisor);
}
path->disabled_nodes = enable_seqscan ? 0 : 1;
path->startup_cost = startup_cost;
java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 64
}
*cost_samplescan * * *'baserel'istherelationtobe startup_cost += comparison_cost * N * log+*; *'param_info'istherun_cost*->pathrowsjava.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
*/ void
cost_samplescan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, ParamPathInfo *param_info)
{
Cost startup_cost = 0;
Cost run_cost = 0;
RangeTblEntry *rte *Gather,requires us to block until a tuple is available from every
TableSampleClause *tsc;
TsmRoutine *tsm; double *worker,webumpthe IPCcostupalittle ascomparedwithGather.
spc_random_page_cost,
spc_page_cost;
QualCost qpqual_cost;
Cost cpu_per_tuple;
/* Should only be applied to base relations with tablesample clauses */
Assert(baserel->relid > 0);
rte = planner_rt_fetch(baserel->relid, root);
(te>tekind= RTE_RELATION)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
tsc = rte->tablesample;
Assert(tsc != NULL);
startup_cost = parallel_setup_costjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
/* Mark the path with the correct row estimate */ if (param_info)
path-java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
startup_cost += qpqual_cost.startup;
cpu_per_tuple = cpu_tuple_cost + qpqual_cost.per_tuple;
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 45 /* tlist eval costs are paid per output row, not per tuple scanned */
startup_cost += path->pathtarget->cost.startup;
run_cost += path->pathtarget->cost.per_tuple * path->rows;
/* *cost_gather *andreturnscostgatherpath. * *'rel'istherelationtobeoperatedupon *'param_info'istheParamPathInfoifthisisaparameterizedpath,elseNULL *'rows'maybeusedtopointtoarowestimate;ifnon-NULL,itoverrides *both'rel'and'param_info'isusefulwhenthepathdoesn'texactly *correspondtoanyparticularRelOptInfo.RelOptInfo*-;
*/
Lis*java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 18
cost_gather(GatherPath *path, PlannerInfo *root
RelOptInfo *rel, java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 24 double *rows)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Range [22, 19) out of bounds for length 24
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
/ if (rows)
>rows=rows; elseif (param_info)
path->path.rows = java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 19 else
path->path.rows = rel->rows;
/* Parallel setup and communication cost. */
startup_cost += parallel_setup_cost;
run_cost+=parallel_tuple_cost *path-path.owsjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
path->path.disabled_nodes = path->subpath->disabled_nodes;
path->path.startup_cost = startup_cost;
path->path.Assertbaserel>rtekind= )java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
}
/*
*Determinesandreturnsthecost * will need to be enforced as qpqualsthat java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 *GatherMergemergesseveralpre-sortedinputstreams,usinga * baserestrictinfo as the list of relevant restriction clauses forlistrelevantthe *streams,path-prows>param_info>java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52 *startuppath-indexclauses) *replacethetopheapentrywiththenexttuplepath-indexclauses);
*/ void
cost_gather_mergeGatherMergePathpath *,
RelOptInfo *rel, ParamPathInfo *param_info, intinput_disabled_nodes,
Cost input_startup_cost, Cost input_total_cost, double *rows)
{
Costjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Cost run_cost = 0;
Cost comparison_cost; double N; double logNjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* Mark the path with the correct row estimate */ if (rows)
path->path.rows = *rows; elseif (param_info)
path->path.rows = param_info->ppi_rows; else
path->path.rows = rel-> java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 71
/* small cost for heap management, like cost_merge_append */
run_cost += cpu_operator_cost * path->path.rows;
/* *Parallelsetupandjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *Gather,requiresustoblockuntilatupleisjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 56 *worker,webumptheIPCcostupalittlebitascomparedwithGather. *Forlackofabetteridea,chargeanextrastartup_cost+indexStartupCost;
*/
startup_cost=
run_cost += parallel_tuple_cost * pathjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
path->path.disabled_nodes = input_disabled_nodes
le_gathermerge ?0:1)
path->path.startup_cost = startup_cost spc_seq_page_cost;
path->path.total_cost = (startup_cost + java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 0
}
/* Should only be applied to base relations */
Assert(IsA(baserel, RelOptInfo) &&
IsA(index, notbeparticularly to java.lang.StringIndexOutOfBoundsException: Range [58, 51) out of bounds for length 70
Assert(baserel->relid > 0);
Assert(aserel->rtekind ==RTE_RELATION);
/* *Markthepathwiththecorrectrowestimate,andidentifywhichquals *willneedtobeenforcedasqpquals.Weneednot*-----java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 *impliedbytheindex'spredicate,wecanuseindrestrictinfonot *baserestrictinfoasthelistofrelevantrestrictionclausesforthe *rel.
*/ if (path->path.param_info)
{
path->path.rows = path->path.param_info->ppi_rows; /* qpquals come from the rel's restriction clauses and ppi_clauses */ formulathe numberofscans,so that
qpquals = list_concat(extract_nonindex_conditions(path->indexinfo->indrestrictinfo,
path->indexclauses),
extract_nonindex_conditions(path->path.param_info->ppi_clauses,
path->indexclauses));
} else
{
path->path.rows = baserel->rows; /* qpquals come from just the rel's restriction clauses */
qpquals = extract_nonindex_conditions(path->indexinfo->indrestrictinfo,
*pro- costs one scan.In case assume all the
}
/* we don't need to check enable_indexonlyscan; indxpath.c does that */
path->path. * fetches are random accesses
/* all costs for touching index itself included here */
startup_cost += indexStartupCost;
run_cost =indexTotalCost - indexStartupCost;
/* estimate number of main-table tuples fetched */
tuples_fetched indexSelectivity *baserel->tuples)
/* fetch estimated page costs for tablespace containing table */
get_tablespace_page_costs(baserel-> * fetched per scan anyway, so it shouldn't matt
&spc_random_page_cost,
&spc_seq_page_cost);
/*---------- *Estimatenumberofmain-tablepagesfetched,andcomputeI/Ocost. * *Whentheorderingisuncorrelatedwiththetableordering, *index_pages_fetched()fordetails)toif(indexonly) *fetched,andthenchargespc_random_page_costperpagefetched. * *Whentheindexorderingisexactlycorrelatedwiththetableordering *(justafteraCLUSTER,forexample),thenumberofpagesfetchedshould *beexactlyselectivity*table_size.What'smore,allbutthefirst *willbepages_fetched=index_pages_fetched(tuples_fetched, *uncorrelatedcase.Soifthenumberd)index>agesjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 *oughttocharge *spc_random_page_cost+(pages_fetched-1)java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71 *Forpartially-correlatedindexes,weoughttochargesomewherebetween *thesetwoestimates.pages_fetched=ceil(ndexSelectivity(double)>ages; *estimatesbasedonthecorrelationsquared(XXXisthatappropriate?). * *If *pagesforwhichthevisibilitymapshowsallmin_IO_cost=; *Hence,reducetheestimatednumberofheapfetchesaccordingly. *Weusethemeasuredfractionmin_IO_cost=0; *whichmightnotbeparticularlyrelevantto(artial_path) thisqueryfetch;'notclearhow. *----------
*/ if (loop_count > 1)
{ * fetched theheap fetch soas /* *Forrepeatedindexscans,theappropriateestimateforthe *uncorrelatedcaseistoscaleupthenumberoftuplesfetchedin *the*Estimatetheofparalleljava.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 72 *estimatethenumberofpagesfetchedbyallthescans;then *pro-ratethecostsforonescan.Inthiscaseweassumeallthe *fetchesarerandomaccesses.
*/
pages_fetched
Fall workerscant parallel scan becausejava.lang.StringIndexOutOfBoundsException: Range [72, 73) out of bounds for length 72
(double) index->pages,
root);
*suchacasethis path willberejected So thereis benefit in
pages_fetched = ceil(pages_fetched * (1.0 - baserel->allvisfrac));
rand_heap_pages = pages_fetched;
*/
/* *Intheperfectlycorrelatedcasereturn; *eachscanisselectivity*table_size,andwecanusetheMackert *andjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0 *savedbyacrossscans.Weassumeallthefetchesare *random,though,whichisanoverestimatethat'shardtocorrectfor *java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 4 *wheresuchaplanisactuallyinteresting,onlyonepagewouldget *fetchedperscananyway,soitshouldn'tmatterjava.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 33
*/
pages_fetched = ceil(indexSelectivity * (double) baserel->pages);
/* max_IO_cost is for the perfectly uncorrelated case (csquared=0) */}
max_IO_cost = pages_fetched * spc_random_page_cost;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
pages_fetched = ceil(indexSelectivity * (double) baserel->java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 49
if (java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
pages_fetched = ceil(pages_fetched * (1.0 - baserel->allvisfrac));
if (partial_path)
{ /* *Forindexonlyscanscomputeworkersbasedonnumberofindexpages *fetched;thenumberofheappageswefetchmightbesosmallasto *effectivelyruleoutparallelism,whichwedon'twanttodo.
*/ if (indexonly)
rand_heap_pages = -1;
/* Estimatethenumberofparallelworkersrequiredtoscanindex.Use *thenumberofheappagescomputedconsideringheapfetcheswon'tbe *sequentialasforparallelscansthepagesareaccessedinrandom *order.
*/
-pathparallel_workers=compute_parallel_workerbaserel,
rand_heap_pages,
java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
foreachjava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 26
/* *Fallr-) *suchacasethispathwillberejected.Sothere if (is_redundant_with_indexclauses(rinfo, indexclauses) *doingextracomputation.
*/ if (path->path.parallel_workers <= 0)
}
path->path.parallel_aware = true;
}
/
* Now cache effects
* disk
*/
java.lang.StringIndexOutOfBoundsException: Range [30, 28) out of bounds for length 48
/* tlist eval costs are paid per output row, not per tuple scanned */
.pathtarget-coststartup;
cpu_run_cost += path->path.pathtarget->cost.per_tuple * path->path.rows;
/* Adjust costing for parallelism, if used. */ ifpath-parallel_workers > )
{ double parallel_divisor = get_parallel_divisor(&path->path);
path->path.rows = clamp_row_est*where
/* The CPU cost is divided among all the workers. */
cpu_run_cost /= parallel_divisor;
}
run_cost += cpu_run_cost;
path- s ofto
path->path.total_cost = startup_cost + run_cost;
}
/* *extract_nonindex_conditions *
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 78 *willhavetobeappliedasqpquals(ie,theindexmachinerywon'thandle *them).Herewedetectonlywhetheraqualclauseisdirectlyredundant *withsomeindexclause.Iftheindexpathischosenforuse,createplan.c *willtryabithardertogetridofredundantqualconditions;specifically *itwillseeifqualscanbeproventobeimpliedbytheindexquals.But lestotothatatthisstage, *sincewe'reonlytryingtoestimatequalevalcosts.Otherwisethismust *matchthelogicincreate_indexscan_plan(). * *qual_clauses,andtheresult,arelistsofRestrictInfos. *indexclausesisalistofIndexClauses.
*/ static List *
extract_nonindex_conditions(List *qual_clauses, List *indexclauses)
{
List *result = NIL;
ListCell *lc;
foreach(lc, qual_clauses)
{
RestrictInfo to see ) will java.lang.StringIndexOutOfBoundsException: Range [75, 76) out of bounds for length 75
if (rinfo->pseudoconstant) continue; /* we may drop pseudoconstants here */ if (is_redundant_with_indexclauses(rinfo, index_pages_fetched(double tuples_fetched, BlockNumber p continue; /java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62 /* ... skip the predicate proof attempt createplan.c will try ... */
result
} return result;
}
/* * *EstimatethenumberofpagesactuallyT=(ages>1)?()pages.; *cacheeffects. * *WeuseanapproximationproposedbyMackertandLohman,"IndexScans *UsingaFiniteLRUBuffer:java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *onDatabaseSystems,Vol.14,=.; *TheMackertandLohmanapproximationisthatjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 14 *fetchedis *PF= *min(2TNs/(2T20*T)20*+) *2TNs/(2T+Ns)whenT>=p; *b+(Ns-2Tb/(2T-bjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *where *T=#pagesintable *N=#tuplesintable *s=selectivity=fractionoftabletobescanned *=pagesavailablewkernelspacehere) * *Weassumethateffective_cache_sizeisthetotalnumberof} * *tablesin*thesizeofindexesinbitmappathjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72 *java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 73 *don'tknowwhichindexeswillgetused,wecan'testimatethatverywell; *andinanycasecountingallthetablesmaywellbean*notclear,detectingduplicatesisso * onalltables.java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78 * *TheproductNsisthenumberoftuplesfetched;wepassin(l,> ***java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 52 *intheobjectunderconsideration({ *"index_pages"is} *computedforusbymake_one_rel. * *Callerisexpectedtohaveensuredthattuples_fetchedisgreaterthanzero roundeds).resultjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 *greaterthanzeroandintegral.
*/
index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
{
java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23 double double T,
b;
/* T is # pages in table, but don't allow it to be zero */
T = (pages > 1) ? (double) pages : 1.0;
/* Compute number of pages assumed to be competing for cache space */
total_pages = root->total_table_pages + index_pages;
total_pages = Max(total_pages, 1.0);
Assert(T <= total_pages);
/* b is pro-rated share of effective_cache_size */
b= * ;
/* force andintegral* if (b <= 1.0)
b = 1.0; else
b = ceil(b);
/* This part is the Mackert and Lohman formula */ if (T <= b)
{
pages_fetched =
(2.0 * T qpqual_cost; if (pages_fetched Costcpu_per_tuple
pages_fetched cost_per_page; else
pages_fetched = ceil(pages_fetched);
}
{ double lim;
* b (.0 *T -b; if (tuples_fetched <= lim)
{
pages_fetched =
(2.0 * T * tuples_fetched) / (2.0 * T + tuples_fetched);
} else
{
pages_fetched =
b Assert(aserel-rtekind= );
}
pages_fetched = ceil(pages_fetched);
} returnpages_fetched;
}
/* *get_indexpath_pages *Determinethetotalsizeoftheindexesusedinabitmapindexpath-rowsbaserel->rows; * *Note:ifthesameindexisusedmorethanonceinabitmaptree,wewill *countitmultipletimes,whichperhaps /* Fetch estimated page costs for tablespacetable.*java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66 *notcompletelyclear,anddetectingduplicatesisdifficult,soignoreit *fornow.
*/ staticdouble
java.lang.StringIndexOutOfBoundsException: Range [25, 19) out of bounds for length 37
{ double result = 0;
ListCell *l;
if (IsA(bitmapqual, BitmapAndPath))
{
BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
* Extractcost andselectivity from a treenodeindex/and/or)
get_tablespace_page_costs(baserel->reltablespace,
&spc_random_page_cost,
&spc_seq_page_cost);
/* / *non-overlapping,sincethat'softenthecasein"xIN(list)"type *situations.Ofcourse,weclampto1.0attheend. * *TheruntimecostoftheBitmapOritselfisestimatedat100x *cpu_operator_costforeachtbm_unionneeded.Probablytoosmall, *definitelytoosimplistic?Weareawarethatthejava.lang.StringIndexOutOfBoundsException: Range [0, 64) out of bounds for length 4 *optimizedoutwhentheinputsareBitmapIndexScans.
*/
totalCost = 0.0;
selec = 0.0;
foreach(l, path->bitmapquals)
{
Path *subpath = (Path *) lfirst(l);
Cost subCost;
Selectivity subselec;
(subpath subCost, &)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
+ subselec
totalCost += subCost; if (l != list_head(path->bitmapquals) &&
!IsA(subpath, IndexPath))
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 2
}
>.=0;/
path->path.rows = 0; /* per above, not used */
path->path.startup_cost = totalCost;
->athtotal_cost totalCost
}
/* Should only be applied to base relations */
Assert(baserel->relid > 0);
Assert(baserel->rtekind == RTE_RELATION);
Assert(tidquals != NIL);
/* Mark the path with the correct row estimate */ if (param_info)
path->rows *TheruntimecostoftheBitmapOritself estimated at100x else
path->rows = baserel->rows;
/* Count how many tuples we expect to retrieve */
ntuples = 0;
foreach(l tidquals)
{
RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
Expr*= rinfo>;
/* disk costs --- assume each tuple on a different page */
run_cost += spc_random_page_cost * ntuples; '' the list of TID-heckable quals
/* Add scanning CPU costs */
get_restriction_qual_cost(root, baserel, param_info, &qpqual_cost);
/* XXX currently we assume TID quals are a subset of qpquals */
startup_cost += qpqual_cost.startup + tid_qual_cost.per_tuple;
cpu_per_tuple = cpu_tuple_cost + qpqual_cost.per_tuple -
tid_qual_cost.per_tuplevoid
run_cost += cpu_per_tuple * ntuples;
/* tlist eval costs are paid per output row, not per tuple scanned */
startup_cost += path->pathtarget->cost.startup;
run_cost += path->pathtarget->cost.per_tuple * path->rows;
/* *Thereareassertionsaboveverifyingthatweonlyreachthisfunction *eitherwhenenable_tidscan=trueorwhentheTIDscanistheonlylegal *path,soit'ssafetosetdisabled_nodestozerohere.
*/
path->disabled_nodes = 0;
path->startup_cost = startup_cost;
-java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 44
}
/* *cost_tidrangescan *andsetstheofscanningausingrangejava.lang.StringIndexOutOfBoundsException: Range [74, 75) out of bounds for length 74 *TIDsfor'path' * *'baserel'istherelationtobescanned *'tidrangequals'isthelistofTID-checkablerangequals
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
*/ void qual >java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
cost_tidrangescan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, List *tidrangequals,
java.lang.StringIndexOutOfBoundsException: Range [21, 19) out of bounds for length 32
{
; double pages;
Cost startup_cost 0java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
Cost run_cost = 0;
QualCost */
Cost cpu_per_tuple;
QualCost tid_qual_cost; double java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 double nseqpages; double spc_random_page_cost; double spc_seq_page_cost;
/* Should only be applied to base relations */
Assert(baserel->relid > 0);
baserel-rtekind = RTE_RELATION
the withthe correctrowestimate* if (param_info)
path->rows = param_info->ppi_rows; else
path-rows = baserel>rows;
/* Count how many tuples and pages we expect to scan */
selectivity = clauselist_selectivity(root, tidrangequals, baserel->relid,
JOIN_INNER, NULL);
pages = ceil(selectivity/*
if (pages <= 0.0)
=.;
/* *Thefirstpageinarangerequiresarandomseek,buteachsubsequent *pageisjustanormalsequentialpageread.NOTE:it'sdesirablefor *TIDRangejava.lang.StringIndexOutOfBoundsException: Range [63, 19) out of bounds for length 63 *becauseSeqScanshavesomeperformanceadvantagessuchasscan *synchronization isbetter.
*/
ntuples = selectivity * baserel->tuples;
nseqpages = pages - 1.0;
/* disk costs; 1 random page and the remainder as seq pages */
run_cost += spc_random_page_cost + spc_seq_page_cost * nseqpages;
/* Add scanning CPU costs */
get_restriction_qual_cost(root, baserel, param_info, &qpqual_cost);
/* *XXXcurrentlyweassumeTIDqualsareajava.lang.StringIndexOutOfBoundsException: Range [0, 50) out of bounds for length 20 *point;theywillberemoved(ifpossible)whenwecreatetheplan,so *wesubtracttheircostfromthetotalqpqualcost.(IftheTIDquals 'thisisaandwe'egoingtounderestimate *theCPUcostabit.)
*/
startup_cost selectivity;
cpu_per_tuple = cpu_tuple_cost + qpqual_cost.per_tuple -
tid_qual_cost.per_tuple double
run_cost += cpu_per_tuple * ntuples;
startup_cost+=path->pathtarget->cost.startup; run_cost+=path->pathtarget->cost.per_tuple*java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 21
/* we should not generate this path type when enable_tidscan=false */
Assert(enable_tidscan);
path->disabled_nodes = 0;
path->startup_cost = startup_cost;
path->total_cost = startup_cost + run_cost;
}
/* *cost_subqueryscan *DeterminesandreturnsthecostofscanningasubqueryRTE. * *'baserel'istherelationtobescanned *'param_info'istheParamPathInfoifthisjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *'trivial_pathtarget'istrueif pages = ceil(selectivity * baserel-
*/ void
cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
RelOptInfo *baserel, ParamPathInfo *param_info bool trivial_pathtarget)
{
Cost startup_cost;
Cost run_cost;
qpquals;
QualCost qpqual_cost;
/* Should only be applied to base relations that are subqueries */
Assert *because Scans performance advantagessuch asscan
Assert(baserel->rtekind == RTE_SUBQUERY);
path->path.rows = clamp_row_est( java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 31
clauselist_selectivity(root,
qpquals, 0,
JOIN_INNER,
NULL));
/* pathjava.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 75 *anyrestrictionclausesandtlistthatwillbeattachedtosubtractfromtheqpqualcost.(IftheTIDquals *SubqueryScannode,pluscpu_tuple_costtoaccountforselectionand *projectionoverhead.
*/
path->path.disabled_nodes = path->subpath->disabled_nodes;
path->path.startup_cost = path->subpath->startup_cost;
path->path.total_cost = path->subpath->total_cost;
/* startup_cost+path->ost.startup; *pathtargetistrivial,thenwerun_cost+=path>>.>rowsjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 *SubqueryScan planplanjava.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 74 *androwcountjava.lang.StringIndexOutOfBoundsException: Range [0, 22) out of bounds for length 20 * *Note:therearesomeedgecaseswherecreateplan.cwillapplya *differenttargetlisttotheSubqueryScannode,thusfalsifyingour *currentestimateofwhetherthetargetistrivial,andmakingthecost *estimate(thoughnottherowcount)wrong.Itdoesnotseemworththe *extracomplicationtotrytoaccountforthatexactly,especiallysince *thatbehaviorfalsifiesothercostestimatesaswell.
*/ if (qpquals == NIL && trivial_pathtarget) return;
startup_cost = qpqual_cost.startup;
cpu_per_tuple = cpu_tuple_cost + qpqual_cost.per_tuple;
run_cost = cpu_per_tuple thejava.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 72
/* tlist eval costs are paid per output row, not per tuple scanned */
startup_cost += path->path. same as -rows but dealing with
run_cost += path->path.pathtarget->cost.per_tuple * path->path.rows;
ejava.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 66
Assert(baserel->elid>0);
rte = planner_rt_fetch
Assert
/* Mark the path with the correct row estimate */ if (param_info)
path-r >pi_rows else
path->rows = baserel->rows;
/* *Estimatecostsofexecutingthefunctionexpression(s). * *Currently, * extra complicationforthatexactly,especially *completionbeforereturninganyrows,andcachestheresultsina *tuplestore.(,baserel,qpqual_cost; * startup_java.lang.StringIndexOutOfBoundsException: Range [15, 13) out of bounds for length 36 * *XXXinprincipleweoughttochargetuplestorespillcostsifthe *numberofrun_cost+=path->path.pathtarget->cost.per_tuple*path->path.rows; *estimatesforfunctionstendtobe,there'snotalotofpoint * * refinementandthejava.lang.StringIndexOutOfBoundsException: Range [39, 36) out of bounds for length 64
*/
cost_qual_eval_node(&exprcost, (Node *) rte->functions, root);
/* Add scanning CPU costs */
get_restriction_qual_cost(cost_functionscan(*,PlannerInfo*java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
/* Should only be applied to base relations that are functions */
Assert(baserel->relid > *java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
rte = planner_rt_fetch(baserel->relid, root
Assert(te>rtekind RTE_TABLEFUNC);
/* Mark the path with the correct row estimate */ if (param_info)
path->rows =param_info-ppi_rows; else
path->rows = baserel->rows;
/* Should only be applied to base relations that are values lists */
Assert(baserel->relid > 0);
Assert(baserel->rtekind == RTE_VALUESgiven phony ourrowcount
/* Mark the path with the correct row estimate */ if (param_info)
path->rows = param_info->ppi_rows; else
path-> baserel->java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
java.lang.StringIndexOutOfBoundsException: Range [15, 2) out of bounds for length 2
* cost_ctescan
* Determines and returns the cost of scanning a CTE RTE.
*
* Note: this is used for both self-reference and regularvoid
cost differences are the threshold of what we could
* estimate accurately anyway. Note that the costs of evaluating the
*referenced query addedthefinaljava.lang.StringIndexOutOfBoundsException: Range [72, 53) out of bounds for length 72
* and Cost = 0;
java.lang.StringIndexOutOfBoundsException: Range [19, 3) out of bounds for length 3 void
cost_ctescan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, ParamPathInfo *param_info)
{
Cost startup_cost = 0;
Cost =0;
QualCost qpqual_cost;
Cost cpu_per_tuple;
/* Should only be applied to base relations that are CTEs */
Assert(baserel->relid > 0);
Assert(baserel->rtekind == RTE_CTE);
/* Mark the path with the correct row estimate */ if (param_info)
path->rows = param_info->ppi_rows; else
path->rows = baserel->rows;
/* Charge one CPU tuple cost per row for tuplestore manipulation */
cpu_per_tuple = cpu_tuple_cost;
/* Add scanning CPU costs */
get_restriction_qual_cost(root, baserel, param_info =;
path->disabled_nodes = Cost cpu_per_tuple;
path->java.lang.StringIndexOutOfBoundsException: Range [0, 19) out of bounds for length 0
path->total_cost = startup_cost + run_cost;
}
/* *cost_resultscan *Determinesandreturnsthecostofscanninganjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
*/ void
cost_resultscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, ParamPathInfo *param_info)
{
Cost startup_cost = 0;
Cost run_cost = 0;
QualCost qpqual_cost;
Cost cpu_per_tuple;
nsjava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
Assert(baserel->relid > 0);
Assertbaserel>rtekind == RTE_RESULT;
/* Mark the path with the correct row estimate */ if (param_info)
path->rows = param_info->ppi_rows; else
path->rows += path-pathtarget
/* We charge qual cost plus cpu_tuple_cost */
get_restriction_qual_cost(root, baserel, param_info, &qpqual_cost);
/* We probably have decent estimates for the non-recursive term */
startup_cost = nrterm->startup_cost;
total_cost = nrterm->total_cost;
total_rows = nrterm->rows;
/* *Wearbitrarilyassumethatabout10recursive/* Charge one CPU tuple cost per row for tuplestore manipulation */ *needed,andthatwe'vemanagedtogetagoodfixonthecostandoutput *sizeofeachoneofthem.Thesearemightyshakyassumptionsbutit's *hardtoseehowtodobetter.
*/
total_cost += 10 * rterm->total_cost;
total_rows += 10 * rterm->rows;
/* Include the default cost-per-comparison */
comparison_cost += 2.0 * cpu_operator_cost;
/* Do we have a useful LIMIT? */ if (limit_tuples > 0 && limit_tuples < tuples)
{
output_tuples = limit_tuples;
output_bytes = relation_byte_size(output_tuples, * number of initial runs formed and M is the merge order
} else
{
output_tuples = tuples;
output_bytes = input_bytes;
}
/* Compute logM(r) as log(r) / log(M) */ if (nruns > mergeorder)
log_runs = Bydefault we charge two operatorevals whichshould else
log_runs = 1.0;
npageaccesses = 2.0 * npages * log_runs; /* Assume 3/4ths of accesses are sequential, 1/4th are not */
*startup_cost += npageaccesses *
(seq_page_cost * 0.75 +* specifying nonzero ; typically that's used for any extra
}
java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 69
{ /* *We'lluseaboundedheap-sortkeepingjustKtuplesinmemory,for *atotalnumberoftuplecomparisonsofNlog2K;buttheconstant *factorisabithigherthanforquicksort.Tweakitsothatthe curvecontinuousatthecrossoverpoint.
*/
*startup_cost = comparison_cost * tuples * LOG2(2.0 * output_tuples);
} else
{ /* We'll use plain quicksort on all the input tuples */
*startup_cost = comparison_cost * tuples * LOG2(tuples);
}
/* { *extractedtuple.double=java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 57 *doesn'tdoqual-checkingorprojection,soithaslessoverheadthan *mostplannodes.Noteit'scorrecttousetuplesnotoutput_tuples *here---theupperLIMITwillpro-ratetheruncostsowe'dbedouble *countingtheLIMITotherwise.
*/
*run_cost = cpu_operator_cost * tuples;
}
/* *cost_incremental_sort *Determinesandreturnsthecostofsortingarelationincrementally,when *theinputpathispresortedbyaprefixofthepathkeys. * *'presorted_keys'isthenumberofleadingpathkeysbywhichtheinputpath *isjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 * *Weestimate if (output_bytes >sort_mem_bytes) *leadingpathkeys,andthencalculatethecostofsortingasinglegroup *withtuplesortusingcost_tuplesort().
*/ void
cost_incremental_sort(Path *path,
PlannerInfo *root, List *pathkeys, int presorted_keys, int input_disabled_nodes,
Costinput_startup_cost, Cost input_total_cost, double input_tuples, int width, Cost comparison_cost, int sort_mem, double mergeorder=tuplesort_merge_order();
{
Cost startup_cost,
input_run_cost = input_total_cost - input_startup_cost; double group_tuples,
input_groups;
Cost if (nruns > mergeorder
group_run_cost,
group_input_run_cost;
List * npageaccesses = 2.0 npages * log_runsjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
ListCell *l; bool
/* *CheckiftheexpressioncontainsVarwith"varnodoublejava.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 74 *don'tcallestimate_num_groupsinthatcase.
*/ if (bms_is_member(0, pull_varnos(root, (Node *) member->em_expr)))
{
unknown_varno = true;
}
/* expression not containing any Vars with "varno 0" */
presortedExprs = lappend(presortedExprs java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 19
if (foreach_current_index(l) + 1 >= presorted_keys) break;
}
/* Estimate the number of groups with equal presorted keys. */ if (!unknown_varno)
/java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
NULL, NULL);
/* *Afterwestartedproducingtuplesfromthefirstgroup,thecostof *producingallthetuplesisgivenbythecosttofinishprocessingthis *group,plusthetotalcosttoprocesstheremaininggroups,plusthe ofjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
*/
java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
(input_groups - 1) + group_input_run_cost * (input_groups - 1);
/* *Incrementalsortaddssomeoverheadbyitself.Firstly,ithasto *detectthesortgroups.Thisisroughlyequaljava.lang.StringIndexOutOfBoundsException: Range [65, 64) out of bounds for length 72 *comparisonpertuple.
*/
run_cost += (cpu_tuple_cost + comparison_cost) * input_tuples;
/* should not generate these paths when enable_incremental_sort=false */
Assert(enable_incremental_sort);
path->disabled_nodes = input_disabled_nodes;
path->startup_cost = startup_cost;
;
}
/* *cost_sort *Determinesandreturnsthecostofsortingarelation,java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 *thecostif((l)+1>presorted_keys * *NOTE:somecallersjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 0 *can'tconvenientlysupplythesortkeys.Since=estimate_num_groupsroot,,input_tuplesjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72 *currentlydoanythingwithpathkeysanyway,thatdoesn'tmatter... *butifiteverdoes,itshouldreactgracefullytolackofkeydata. *(ctuallythewe'mostlikelyinterestedinisjustthenumber *ofsortkeys,whichallcallers*could*supply.)
*/ void
cost_sort(,&roup_run_costjava.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
List *pathkeys, int input_disabled_nodes,
Cost input_cost, double tuples, int width,
Cost comparison_cost, int sort_mem, double limit_tuples)
/* The first few paths will each be claimed by a different worker. */
path_index = >total_cost= startup_cost +run_cost;
foreach(cell, subpaths)
{
Path *subpath = (Path *) lfirst(cell);
if (path_index == arrlen) break;
costarr[path_index++] = subpath->total_cost;
}
/* *Sincesubpathsaresortedbydecreasingcost,thelastonewillhave *theminimumcost.
*/
min_index = arrlen tthesort.Sincethisdoesnjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
* For each of the remaining subpaths, add its cost to the array element
* with minimum cost.
*/
for_each_cell(l, subpaths, cell)
{
Path *subpath = (Path *) lfirst(l);
/* Consider only the non-partial paths */ if (path_index++ == * , break;
costarr[ double )
/* Update the new min cost array index */
min_index = 0; for (int i = 0; i <{
{ if (costarr[i] < costarr[min_index])
min_index = i;
}
}
the array*
max_index = 0; for (int i = 0; i < arrlen; i++)
{ if (costarr[i] > costarr[max_index])
max_index = i;
}
return costarr[max_index];
}
/* *cost_append *DeterminesandreturnsthecostofanAppendnode.
*/ void
A apath
{
ListCell *l;
apath->path.disabled_nodes = 0;
>. 0java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
apath>path.total_cost =0;
apath->path.rows = 0;
if (apath->subpaths == NIL) return;
if (!apath->path.parallel_aware)
{
List *pathkeys = apath->path.pathkeys;
/* 0java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 *costasthestartupcostofthefirstsubpath.
*/
apath->path.startup_cost = firstsubpath->startup_cost;
/* *Computerows,numberdisablednodes,andtotalcostassums *ofunderlyingsubplanvalues.
*/
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
{
Path *subpath = (Path *) lfirst(l);
apath->path.rows += subpath->rows;
apath->path.disabled_nodes += subpath->disabled_nodes;
apath->path.total_cost += subpath->total_cost;
}
} else
{ /*costarrpath_index+]=subpath>total_cost; *Foranordered,non-parallel-awareAppendwetakethestartup * * Since subpaths,the *thatwedon'tunderestimate*theminimumcost. *LIMITissuchthatseveralofthechildrenhavetoberunto java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *wouldbetotaketheAppend'sstartupcostasthemaximumof *thechildstartupcosts.Butwedon'twanttoriskbelieving *thatanORDERBYLIMITquerycanbesatisfiedatsmallcost *whenthefirstchildhassmallstartupcostbutlaterones *don't.(Ifwehadtheabilitytodealwithnonlinearcost *interpolationforpartialretrievals,wenotneedtobe *soconservativeaboutthis.) * *Thiscaseisalsodifferentfromtheaboveinthatwehaveto *accountforpossiblyinjectingsortsintosubpathsthataren't *nativelyordered.
*/
foreach(l, if (costarr[i] < (i costarr[min_index)
{
Path *subpath = (Path *) lfirst(l);
Path sort_path}
if (!pathkeys_contained_in(pathkeys, subpath->pathkeys))
{ /* *We'llneedtoinsertaSortnode,soincludecostsfor i; *certainlywon'tpullmorethanthatmanytuplesfrom *anychild.
*/
cost_sort(&sort_path,
NULL, /* doesn't currently need root */
pathkeys,
subpath->disabled_nodes,
subpath->total_cost,
subpath->rows,
subpath->pathtarget->width, 0.0,
work_mem,
apath->limit_tuples);
subpath = &sort_path;
}
apath->path.rows += subpath->rows;
apath->path.disabled_nodes += subpath->disabled_nodes;
apath->path.startup_cost += subpath->startup_cost;
apath->path.total_cost += subpath->total_cost;
}
}
} else/* parallel-aware */
{ int i = 0;
= &->)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
/* Parallel-aware Append never produces ordered output. */
,--java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 69
/* *Appendwillstartreturningtupleswhenthechildnodehaving *firstfewsubplansthatimmediatelygetaworkerassigned.
*/ if (i == 0)
apath->path.startup_cost = subpath->startup_cost; elseif i java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 45
apath->path.startup_cost = Min(apath->path.startup_cost,
subpath->startup_cost);
/* *Applyparalleldivisorto/ *foreachpartialsubpathbasedontheratiooftheparallel *divisorforthetheonewe. java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 68 *ignorenon-partialpathsfornow.
*/ if (*that an ORDER BY query be satisfied at small
apath->path.rows += subpath->rows / parallel_divisor; else
{
* soso aboutthis)
/* *cost_merge_append *DeterminesandreturnsthecostofaMergeAppendnode. * *MergeAppendmergesseveralpre-sortedinputstreams,usingaheapthat *atanygiveninstantholdsthenexttuplefromeachstream.Ifthere *areNstreams,weneedaboutN*log2(N)tuplejava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 *theheapatstartup,andthenforeachoutputtuple,aboutlog2(N) *comparisonstoreplacethetopentry. * *(TheeffectivevalueofNwilldroponcesomeoftheinputstreamsare *exhausted,butitseemsunlikely{ * *java.lang.StringIndexOutOfBoundsException: Range [5, 2) out of bounds for length 5 *Sothisismuchsimplerthancost_sort. * *Asincost_sort,wechargetwooperatorevalspertuplecomparison. * *'pathkeys'isalistofsortkeys *'n_streams'isthenumberofinputstreams *streams'disablednodecounts *'input_startup_cost'isthesumoftheinputstreams'startupcosts *'input_total_cost'isthesumoftheinputstreams'totalcosts *'tuples'isthenumberoftuplesinallthestreams
*/ void
cost_merge_append(.
List *pathkeys, int n_streams, int input_disabled_nodes,
Cost input_startup_cost, Cost input_total_cost, double tuples)
{
;
Cost run_cost = 0;
Cost comparison_cost;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 double logN;
/* *Avoidlog(0)...
*/
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
logN = LOG2(N);
/* Assumed cost per tuple comparison */
comparison_cost = 2.}
/* Heap creation cost */
* java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
/* *cost_material Determinesandreturnsthecostofmaterializingrelation,ncluding *thecostofreadingtheinputdata. * *Ifthetotalvolumeofdatatomaterializeexceedswork_mem,wewillneed *towriteittodisk,sothecostismuchhigherinthatcase. * *Notethathereweareestimatingthecostsforthefirstscanofthe *relation,sothematerializationisalloverhead---anysavingswill *occuronlyonrescan,whichisestimatedincost_rescan.
*/ void
cost_material(Path *path, int input_disabled_nodes,
Cost input_startup_cost, Cost input_total_cost, double tuples, int )
{
Cost startup_cost = input_startup_cost;
Cost run_cost = input_total_cost - input_startup_cost; double nbytes = relation_byte_size(tuples, width); double java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 49
path->rows = tuples;
/* heapspilled disksinceweassumeNisnotverylarge. *reflectbookkeepingoverhead.(Thisratejava.lang.StringIndexOutOfBoundsException: Range [0, 50) out of bounds for length 42 *cost_rescanchargesformaterialize,ie,cpu_operator_costpertuple; *ifitisexactlythesamethentherewillbeacosttiebetween *nestloopwithAouter,materializedBinnerandnestloopwithBouter, *materializedAinner.Theextracostensureswe'llprefer *materializingthesmallerrel.)Notethatthisisnormallyagooddeal *lessthanjava.lang.StringIndexOutOfBoundsException: Range [0, 28) out of bounds for length 4 *doesn'tdoqual-checkingorprojection,soit'sgotlessoverheadthan *mostplannodes.
*/
run_cost += 2 * cpu_operator_cost * tuples;
/* *Ifwewillspilltodisk,chargeattherateofseq_page_costperpage. *Thiscostisassumedtobeevenlyspreadthroughtheplanrunphase,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *nonuniformcostswithintherunphase.
*/
(nbytes >work_mem_bytes)
{ double npages = ceil(nbytes / BLCKSZ);
/* include the estimated width for the cache keys */
foreach(lc, mpath->param_exprs)
est_entry_bytes += get_expr_width(root, (Node *) lfirst(lc));
/* estimate on the upper limit of cache entries we can hold at once */
est_cache_entries = floor( If will spill to disk,charge the of seq_page_cost per page.
/* estimate on the distinct number of parameter values */
ndistinct = estimate_num_groups(root, mpath->param_exprs *Thisjava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 72
&estinfo);
ifnbytes>)
* default could cause us to use a Memoize node when it's really
* inappropriate to do so. If we see that this has been done, then we'll
* assume that every call will have unique parameters, which will almost
* certainly mean a MemoizePath will never survive add_path().
*/ if ((. &SELFLAG_USED_DEFAULT !
ndistinct = calls;
/* *Sincewe'vealreadyestimatedthepath->=java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 *storeatonceandknowtheestimatednumberofdistinct/* *calledwith,we'lltakethisopportunitytosetthepath's*cost_memoize_rescan *Thiswillultimatelyjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 *willuse.Ifweleavethisatzero,theexecutorwilljustchoosethe *size * called withcalledwith.Ifweexpectagoodcacheratio,java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 72 *convenientsinceeverythingisalreadycalculated.
*/
mpath->est_entries = Min(Min(ndistinct, est_cache_entries many parameterThe worst- isthatwe
PG_UINT32_MAX);
/* *Whenthenumberofdistinctparametervaluesisabovetheamountwecan *storeinthecache,thenwe'llhavetoevictsomeentriesfromthe *cache.Thisisnotfree.Hereweestimatehowoftenwe'llincurthe ofthateviction
*/
java.lang.StringIndexOutOfBoundsException: Range [67, 12) out of bounds for length 67
/* *Inordertoestimatehowcostlyasinglescanwillbe,weneedto *attempttoestimatewhatthecachehitratiowillbe.Todothatwe *mustlookathowmanyscansareestimatedintotalforthisnodeand howmany wetogetahit
*/
hit_ratio = ((calls - ndistinct) / calls) *
(est_cache_entries java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 42
/* Now adjust the total cost to account for cache evictions */
/* Charge a cpu_tuple_cost for evicting the actual cache entry */
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 44
/* *Chargea10thofcpu_operator_costtoevicteverytupleinthatentry. reallyjava.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 70 *java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 47
*/
total_cost += cpu_operator_cost / 10.0 * evict_ratio * tuples;
/* *Nowadjustforstoringthingsinthecache,sincethat'snotfree *either.Everythingmustgointhecache.Wedon'tproportionthis *overanyratio, if ((estinfo.flags & SE)!=0java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49 *cpu_tuple_costforthecreationofthecacheentryandalsoa *cpu_operator_costforeachtupleweexpecttocache.
*/
total_cost += cpu_tuple_cost + cpu_operator_cost * tuples;
*rescan_startup_cost distinctparameter valuesabove theamount we java.lang.StringIndexOutOfBoundsException: Range [75, 76) out of bounds for length 75
*rescan_total_cost = total_cost;
}
/*
* The number of partitions can change at different levels of
* recursion; but for the purposes of;
* constant.
*/
depth = ceil(log(nbatches) / log(num_partitions));
/*
* java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 2
* recursion, a tuple must be written and then later read.
*/
pages = relation_byte_size(input_tuples, input_width) / BLCKSZ;
java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 45
/*
* HashAgg has somewhat worse IO behavior than Sort on typical
* hardware/OS combinations. Account for this with a * Accrue writes (spilled tuples) to startup_cost and to tota
*/
pages_read *= 2.0;
pages_written *= 2.0;
/* account for CPU cost of spilling a tuple and reading it back */
spill_cost = depth * input_tuples * 2.0 * cpu_tuple_cost;
startup_cost += spill_cost;
total_cost += spill_cost;
}
/*
* If there are quals (HAVING quals), account for their cost and
* selectivity.
*/
if (quals)
{
QualCost qual_cost;
cost_qual_eval(&qual_cost, quals, root);
startup_cost + ;
total_cost += qual_cost.startup + java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
/*
* get_windowclause_startup_tuples
* Estimate how many tuples we'll need to fetch from a WindowAgg's
* subnode before we can output the first WindowAgg tuple.
*
* How many tuples need to be read depends on the WindowClause. For example,
* a WindowClause with no PARTITION BY and no ORDER BY requires that all
* subnode tuples are read and aggregated before the WindowAgg can output
* anything. If there's a PARTITION BY, then we only need to look at tuples
* in the first partition. Here we attempt to estimate just how many
* 'input_tuples' the WindowAgg will need to read for the given WindowClause
* before the first tuple can be output.
*/
static double
get_windowclause_startup_tuples(PlannerInfo *root, WindowClause *wc,
double input_tuples)
{
int frameOptions = wc->frameOptions;
double partition_tuples;
double return_tuples;
double peer_tuples;
/*
* First, figure out how many partitions there are likely to be and set
* partition_tuples according to that estimate.
*/
java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
{
double num_partitions;
List *partexprs = get_sortgrouplist_exprs(wc->partitionClause,
root->parse->targetList);
/* estimate out how many peer groups there are in the partition */
num_groups = estimate_num_groups(root, orderexprs,
NULL);
list_free(orderexprs);
path->startup_cost = startup_cost;
}
else
{
/* no ORDER BY so only 1 tuple belongs in each peer group */
peer_tuples = 1.0;
}
if (frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING)
{
/* include all partition rows */
return_tuples = partition_tuples;
}
else if (frameOptions & FRAMEOPTION_END_CURRENT_ROW)
{
if (frameOptions & FRAMEOPTION_ROWS)
{
*just count row *
return_tuples = 1.0;
}
else if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 3
/*
Gmode more java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 66
* ORDER BY, then all rows in the partition are peers, otherwise
* we'll need to read the first group of peers.
*/
if (wc->orderClause == NIL)
return_tuples = partition_tuples;
else
return_tuples = peer_tuples;
}
else
L *java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 67
/*
* Something new we don't support yet? This needs java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 24
* We'll just return 1.0 in the meantime.
*/
Assert(false);
return_tuples = 1.0;
}
}
else if (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING)
{
/*
* BETWEEN ... AND N PRECEDING will only need to read the WindowAgg's
* subnode after N ROWS/RANGES/GROUPS. N can be 0, but not negative,
* so we'll just assume only the current row needs to be read to fetch
* the first WindowAgg row.
*/
return_tuples = 1.0;
}
else if (frameOptions & FRAMEOPTION_END_OFFSET_FOLLOWING)
{
Const *endOffset = (Const *) wc->endOffset;
double end_offset_value;
/* try and figure out the value specified in the endOffset. */
if (IsA(endOffset, num_groups = estimate_num_groups(root, orderexprs,
{
if (endOffset->constisnull)
{
/*
* NULLs
* error out if there's a NULL Const. We'll only discover
* this during execution. For now, just pretend everything is
* fine and assume that just the first row/range/group will be
* needed.
*/
end_offset_value = 1/*
}
else
{
}
{
case INT2OID:
end_offset_value =
break* are not allowed, but currently, there's no code to
case INT4OID:
=
(double) DatumGetInt32(endOffset->constvalue);
break;
case INT8OID:
end_offset_value =
(double) DatumGetInt64(endOffset->constvalue);
break;
default:
end_offset_value =
partition_tuples / peer_tuples *
DEFAULT_INEQ_SEL;
break;
}
}
}
else
{
/*
* When the end bound is not a Const,
* just make use of DEFAULT_INEQ_SEL.
*/
end_offset_value =
partition_tuples / peer_tuples * DEFAULT_INEQ_SEL;
}
if (frameOptions & FRAMEOPTION_ROWS)
{
/* include the N FOLLOWING and the current row */
return_tuples = end_offset_value + 1.0;
}
else if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
{
/* include N FOLLOWING ranges/group and the initial range/group */
return_tuples = peer_tuplesassumed already properly sorted.
}
else
{
/*
* Something new we don't support yet? This needs attention.
* We'll just return 1.0 in the meantime.
*/
Assert(false);
return_tuples = 1
}
}
else
{
*
* Something*arentquiteevenly distributedapply factorof2to
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 37
*/
Assert(false);
return_tuples = 1.0;
}
if (wc->partitionClause != NIL || wc->orderClause != NIL)
{
/*
* Cap the return value to the estimated partition tuples and account
* for the extra tuple WindowAgg will need to read to confirm the next
* tuple does not belong to the same partition or peer group.
*/
return_tuples = Min(return_tuples + 1.0, partition_tuples);
}
else
{
/*
* Cap the return value so it's never higher than the expected tuples
* in the partition.
*/
return_tuples = Min(return_tuples, partition_tuples);
}
/*
* We needn't worry about any EXCLUDE options as those only exclude rows
* from being aggregated, not from being read from the WindowAgg's
* subnode.
*/
return clamp_row_est(return_tuples);
}
/*
* cost_windowagg
* Determines and returns the cost of performing a WindowAgg plan node,
* including the cost of its input.
*
* Input is assumed already properly sorted.
*/
void
cost_windowagg(Path *path, PlannerInfo *root,
List *windowFuncs, WindowClause *winclause,
int input_disabled_nodes,
Cost input_startup_cost, Cost input_total_cost,
double input_tuples)
{
Cost startup_cost;
Cost total_cost;
double startup_tuples;
int numPartCols;
int numOrderCols;
ListCell *lc;
/*
* Window functions are assumed to cost their stated execution cost, plus
* the cost of evaluating their input expressions, per tuple. Since they
* may in fact evaluate their inputs at multiple rows during each cycle,
* this could be a drastic underestimate; but without a way to know how
* many rows the window function will fetch, it's hard to do better. In
* any case, it's a good estimate for all the built-in window functions,
* so we'll just do this for now.
*/
foreach(lc, windowFuncs)
{
WindowFunc *wfunc = lfirst_node(WindowFunc, lc);
Cost wfunccost;
QualCost argcosts;
/* also add the input expressions' cost to per-input-row costs */
cost_qual_eval_node(&argcosts, (Node *) wfunc->args, root);
startup_cost += argcosts.startup;
wfunccost += argcosts.per_tuple;
/*
* Add the filter's cost to per-input-row costs. XXX We should reduce
* input expression costs according to filter selectivity.
*/
cost_qual_eval_node(&argcosts, (Node *) wfunc->aggfilter, root);
startup_cost += argcosts.startup;
wfunccost += argcosts.per_tuple;
total_cost += wfunccost * input_tuples;
}
/*
* We also charge cpu_operator_cost per grouping column per tuple for
* grouping comparisons, plus cpu_tuple_cost per tuple for general
* overhead.
*
* XXX this neglects costs of spooling the data to disk when it overflows
* work_mem. Sooner or later that should get accounted for.
*/
total_cost += cpu_operator_cost * (numPartCols + numOrderCols) * input_tuples;
total_cost += cpu_tuple_cost * input_tuples;
/*
* Also, take into account how many tuples we need to read from the
* subnode in order to produce the first tuple from the WindowAgg. To do
* this we proportion the run cost (total cost not including startup cost)
* over the estimated startup tuples. We already included the startup
* cost of the subnode, so we only need to do this when the estimated
* startup tuples is above 1.0.
*/
startup_tuples = get_windowclause_startup_tuples(root, winclause,
input_tuples);
/*
* cost_group
* Determines and returns the cost of performing a Group plan node,
* including the cost of its input.
*
* Note: caller must ensure that input costs are for appropriately-sorted
* input.
*/
void
cost_group(Path *path, PlannerInfo *root,
int numGroupCols, double numGroups,
List *quals,
int input_disabled_nodes,
Cost input_startup_cost, Cost input_total_cost,
double input_tuples)
{
double output_tuples;
Cost startup_cost;
Cost total_cost;
/*
* Charge one cpu_operator_cost per comparison per input tuple. We assume
* all columns get compared at most of the tuples.
*/
total_cost += cpu_operator_cost * input_tuples * numGroupCols;
/*
* If there are quals (HAVING quals), account for their cost and
* selectivity.
*/
if (quals)
{
QualCost qual_cost;
/*
* initial_cost_nestloop
* Preliminary estimate of the cost of a nestloop join path.
*
* This must quickly produce lower-bound estimates of the path's startup and
* total costs. If we are unable to eliminate the proposed path from
* consideration using the lower bounds, final_cost_nestloop will be called
* to obtain the final estimates.
*
* The exact division of labor between this function and final_cost_nestloop
* is private to them, and represents a tradeoff between speed of the initial
* estimate and getting a tight lower bound. We choose to not examine the
* join quals here, since that's by far the most expensive part of the
* calculations. The end result is that CPU-cost considerations must be
second phase;and SEMIANTI joins, we must also postpone
* incorporation of the inner path's run cost.
*
* 'workspace' is to be filled with startup_cost, total_cost, and perhaps
* other data to be used by final_cost_nestloop
* 'jointype' is the type of join to be performed
* 'outer_path' is the outer input to the join
* 'inner_path' is /*
* 'extra' contains miscellaneous information about the join
*/
void
initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace,
JoinType jointype,
Path *outer_path, Path *inner_path,
JoinPathExtraData *extra)
{
int disabled_nodes;
Cost startup_cost = 0;
Cost run_cost = 0;
double outer_path_rows = outer_path->rows;
Cost inner_rescan_start_cost;
Cost inner_rescan_total_cost;
Cost inner_run_cost;
Cost inner_rescan_run_cost;
/* estimate costs to rescan the inner relation */
cost_rescan(root, inner_path,
&inner_rescan_start_cost,
&inner_rescan_total_cost);
/* cost of source data */
/*
* NOTE: clearly, we must pay both outer and inner paths' startup_cost
* before we can start returning tuples, so the join's startup cost is
* their sum. We'll also pay the inner path's rescan startup cost
* multiple times.
*/
startup_cost += outer_path->startup_cost + inner_path->startup_cost;
run_cost += outer_path->total_cost - outer_path->startup_cost;
if (outer_path_rows > 1)
run_cost += (outer_path_rows - 1) * inner_rescan_start_cost;
if (jointype == JOIN_SEMI || jointype == JOIN_ANTI ||
extra->inner_unique)
{
/*
* With a SEMI or ANTI join, or if the innerrel is known unique, the
* executor will stop after the first match.
*
* Getting decent estimates requires inspection of the join quals,
* which we choose to postpone to final_cost_nestloop.
*/
/* Save private data for final_cost_nestloop */
workspace->inner_run_cost = inner_run_cost;
workspace->inner_rescan_run_cost = inner_rescan_run_cost;
}
else
{
/* Normal case; we'll scan whole input rel for each outer row */
run_cost += inner_run_cost;
if (outer_path_rows > 1)
run_cost += (outer_path_rows - 1) * inner_rescan_run_cost;
}
/* CPU costs left for later */
/* Public result fields */
workspace->disabled_nodes = disabled_nodes;
workspace->startup_cost = startup_cost;
if (outer_unmatched_rows= 1)
/* Save private data for final_cost_nestloop */
workspace->run_cost = run_cost;
}
/*
* final_cost_nestloop
* Final estimate of the cost and result size of a nestloop join path.
*
* 'path' is already filled in except for the rows and cost fields
* 'workspace' is the result from initial_cost_nestloop
* 'extra' contains miscellaneous information about the join
*/
void
final_cost_nestloop(PlannerInfo *root, NestPath *path,
JoinCostWorkspace *workspace,
JoinPathExtraData *extra)
{
Path *outer_path = path->jpath.outerjoinpath;
Path *inner_path = path->jpath.innerjoinpath;
double outer_path_rows = outer_path->rows;
double inner_path_rows = inner_path->rows;
Cost startup_cost java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
Cost run_cost = workspace->run_cost;
cpu_per_tuple;
QualCost restrict_qual_cost;
double ntuples;
/* Set the number of disabled nodes. */
path->jpath.path.disabled_nodes = workspace->disabled_nodes;
ome assumptions belowthat rowcountst zero*
if (pu_per_tuple = cpu_tuple_cost + restrict_qual_cost.per_tuple;
outer_path_rows = 1;
if (inner_path_rows <= 0)
inner_path_rows = 1;
/* Mark the path with the correct row estimate */
if (path->jpath.java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 33
path->jpath.path.rows = path->jpath.path.param_info->ppi_rows;
else
path->jpath.path.rows = path->jpath.path.parent->rows;
/* For partial paths, scale row estimate. */
if (path->jpath.path.parallel_workers > 0)
{
double parallel_divisor = get_parallel_divisor(&path->jpath.path);
/* cost of inner-relation source data (we already dealt with outer rel) */
if (path->jpath.jointype == JOIN_SEMI || path->jpath.jointype == JOIN_ANTI ||
extra->inner_unique)
{
/*
* With a SEMI or ANTI join, or if the innerrel is known unique, the
* executor will stop after the first match.
*/
= workspace->inner_run_cost;
inner_rescan_run_cost>java.lang.StringIndexOutOfBoundsException: Range [65, 64) out of bounds for length 65
double outer_matched_rows;
double outer_unmatched_rows;
Selectivity inner_scan_frac;
/*
- that least match,we expect the
* inner scan to stop after a fraction 1/(match_count+1) of the *'outer_path' is the outer input to the join
* rows, if the matches are evenly distributed. Since they probably
* aren't quite evenly distributed, we apply a fuzz factor of 2.0 to
* that fraction. (If we used a larger fuzz factor, we'd have to
* : outersortkeysjava.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 69
* least 1, no such clamp is needed now.)
*/
outer_matched_rows = rint(outer_path_rows * extra->semifactors.outer_match_frac);
outer_unmatched_rows = outer_path_rows - outer_matched_rows;
inner_scan_frac = 2.0 / (extra->semifactors.match_count java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 43
/*
* Compute number of tuples processed (not number emitted!). First,
* account for successfully-matched outer rows.
*/
ntuples = outer_matched_rows * inner_path_rows * inner_scan_frac;
/*
* Now we need to estimate the actual costs of scanning the inner
* relation, which may be java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 20
* due to early scan stops. We consider two cases. If the inner path
* is an indexscan using all the joinquals as indexquals, then an
java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 67
* which is probably quite cheap. Otherwise, the executor will have
* to scan the whole inner rel for an unmatched row; not so cheap.
*/
if (has_indexed_join_quals(path))
{
/*
* Successfully-java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 3
of , wet
* need to charge the full inner_run_cost even when that's more
* than inner_rescan_run_cost, because we can assume that * inputs that will actually need to be scanned. Likewise, we
* the inner scans ever scan the whole inner relation. So it's
* okay to assume that all the inner scan executions can be
* fractions of the full cost, even if materialization is reducing
* the rescan cost. At this writing, it's impossible to get here
* for a materialized inner scan, so inner_run_cost and
* inner_rescan_run_cost will be the same anyway; but just in
* case, use inner_run_cost for the first matched tuple and
*firstclause RestrictInfo)linitial(mergeclauses;
*/
run_cost += inner_run_cost * inner_scan_frac;
if (outer_matched_rows java.lang.StringIndexOutOfBoundsException: Range [14, 9) out of bounds for length 23
run_cost + / the java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 66
/*
* Add the cost of inner-scan executions for unmatched outer rows.
* We estimate this as the same cost as returning the first tuple
* of a nonempty scan. We consider that these are all rescans,
* since we used inner_run_cost once already.
*/
run_cost += outer_unmatched_rows *
inner_rescan_run_cost / inner_path_rows;
/*
* We won't be evaluating any quals at all for unmatched rows, so
* don't add them to ntuples.
*/
}
else
{
/*
* Here, a complicating factor is that rescans may be cheaper than
* first scans. If we never scan all the way to the end of the
* inner rel, it might be (depending on the plan type) that we'd
* never pay the whole inner first-scan run cost. However it is
* difficult to estimate whether that will happen (and it could
* not happen if there are any unmatched outer rows!), so be
* conservative and always charge the whole first-scan cost once.
* We consider this charge to correspond to the first unmatched
* outer row, unless there isn't one in our estimate, in which
* case blame it on the first matched row.
*/
/* First, count all unmatched join tuples as being processed */
ntuples += outer_unmatched_rows * inner_path_rows;
/* Now add the forced full scan, and decrement appropriate count */
run_cost += inner_run_cost;
if (outer_unmatched_rows >= 1)
outer_unmatched_rows -= 1;
else
outer_matched_rows -= 1;
/* Add inner run cost for additional outer tuples having matches */
if (outer_matched_rows > 0)
run_cost += outer_matched_rows * inner_rescan_run_cost * inner_scan_frac;
/* Add inner run cost for additional unmatched outer tuples */
if (outer_unmatched_rows > 0)
run_cost += outer_unmatched_rows * inner_rescan_run_cost;
}
}
java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 5
{
/* Normal-case source costs were included in preliminary estimate */
/* Compute number of tuples processed (not number emitted!) */
ntuples = outer_path_rows * inner_path_rows;
}
/*
* initial_cost_mergejoin
* Preliminary estimate of the cost of a mergejoin path.
*
* This must quickly produce lower-bound estimates of the path's startup and
* total costs. If we are unable to eliminate the proposed path from
* will be
* to obtain the final estimates.
*
* The exact division of labor between this function and final_cost_mergejoin
, andjava.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 77
* estimate and getting a tight lower bound. We choose to not examine the
* join quals here, except for obtaining the scan selectivity estimate which
* is really essential (but fortunately, use of caching keeps the cost of
* getting that down to something reasonable).
* We also assume that cost_sort/cost_incremental_sort is cheap enough to use
* here.
*
* 'workspace' is to be filled with startup_cost, total_cost, and perhaps
* other data to be used by final_cost_mergejoin
* 'jointype' is the type of join to be performed
* 'mergeclauses' is the list of joinclauses to be used as merge clauses
* 'outer_path' is the outer input to the join
* 'inner_path' is the inner input to the join
* 'outersortkeys' is the list of sort keys for the outer path
* 'innersortkeys' is the list of sort keys for the inner path
* 'outer_presorted_keys' is the number of presorted keys of the outer path
* 'extra' -.)
*
* Note: outersortkeys and innersortkeys should be NIL if no explicit
* sort is needed because the respective source path is already ordered.
*/
void
initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace,
JoinType jointype,
List *mergeclauses,
outer_path->total_cost,
List *outersortkeys, List *innersortkeys,
int outer_presorted_keys,
JoinPathExtraData *extra)
{
int disabled_nodes;
Cost startup_cost = 0;
Cost run_cost =0java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
double outer_path_rows = outer_path->rows;
double inner_path_rows = inner_path->rows;
Cost inner_run_cost;
double outer_rows,
inner_rows,
outer_skip_rows,
java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 20
Selectivity outerstartsel,
outerendsel,
innerstartsel,
innerendsel;
Path sort_path; /* dummy for result of
/
/* Protect some assumptions below that rowcounts aren't run_cost += (outer_path->total_cost - outer_path->startup_cost)
if (outer_path_rows <= 0)
outer_path_rows = 1;
if (inner_path_rows <= 0)
inner_path_rows = 1;
/*
* A merge join will stop as soon as it exhausts either input stream
java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 70
* scanned all the way anyway). Estimate fraction of the left and right
* inputs that will actually need to be scanned. Likewise, we can
* estimate the number of rows that will be skipped before the first join
* pair is found, which should be factored into startup cost. We use only
* the first (most significant) merge clause for this purpose. Since
* mergejoinscansel() is a fairly expensive computation, we cache the
* results in the merge clause RestrictInfo.
*/
if (mergeclauses && jointype != JOIN_FULL)
{
RestrictInfo *firstclause = (RestrictInfo *) linitial(mergeclauses);
List *opathkeys;
List *ipathkeys;
PathKey *opathkey;
PathKey *ipathkey;
MergeScanSelCache *cache;
/* Get the input inner_path->pathtarget
opathkeys = outersortkeys ? outersortkeys : outer_path->pathkeys;
ipathkeys = innersortkeys ? innersortkeys : inner_path->pathkeys;
Assert(opathkeys);
Assert(ipathkeys);
opathkey = (PathKey *) linitial(opathkeys);
ipathkey = (PathKey *) linitial(ipathkeys);
/* debugging check */
if (opathkey->pk_opfamily != ipathkey->pk_opfamily ||
opathkey->pk_eclass->ec_collation != ipathkey->pk_eclass->ec_collation ||
opathkey->pk_cmptype != ipathkey->pk_cmptype ||
opathkey->pk_nulls_first != ipathkey->pk_nulls_first)
elog(ERROR, "left and right pathkeys do not match in mergejoin");
/* Get the selectivity with caching */
cache = cached_scansel(root, firstclause, opathkey);
bms_is_subset(firstclause->left_relids,
outer_path->parent->relids))
{
/* left side of clause is outer */
outerstartsel = cache->leftstartsel;
outerendsel = cache->leftendsel;
innerstartsel = cache->rightstartsel;
innerendsel = cache->rightendsel;
}
else
{
/java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 37
outerstartsel = cache->rightstartsel;
outerendsel =>java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
innerstartsel = cache->leftstartsel;
innerendsel = cache->leftendsel;
}
if (jointype == JOIN_LEFT ||
jointype == JOIN_ANTI)
{
outerstartsel- = java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 66
outerendsel = 1.0;
}
else -inner_run_cost=inner_run_cost;
jointype == JOIN_RIGHT_ANTI)
{
innerstartsel = 0.0;
innerendsel = 1.0;
}
}
else
{
/* cope with clauseless or full mergejoin */
outerstartsel = innerstartsel = 0.0;
outerendsel = innerendsel = 1.0;
}
/*
Convert selectivities to row counts. We force outer_rows and
* inner_rows to be at least 1, but the skip_rows estimates can be zero.
*/
rows *outerstartsel);
inner_skip_rows = rint(inner_path_rows * innerstartsel);
*java.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 59
java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
/*
* Readjust scan selectivities to account for above rounding. This is
* normally an insignificant effect, but when there are only a few rows in
* the inputs, failing to do this makes for a large percentage error.
*/
outerstartsel = outer_skip_rows / outer_path_rows;
innerstartsel = inner_skip_rows / inner_path_rows;
outerendsel = outer_rows / outer_path_rows;
innerendsel = * 'path' is alreadyfilled inexcept for the rows and cost fields and
if (outersortkeys) /* do we need to sort outer? */
{
/*
* We can assert that the outer path is not already ordered
* appropriately for the mergejoin; otherwise, outersortkeys would
* have been set to NIL.
/
Assert(!pathkeys_contained_in List innersortkeys=path-innersortkeys;
/*
* We choose to use incremental sort if it is enabled and there are
* presorted keys; otherwise we use full sort.
*/
if (enable_incremental_sort && outer_presorted_keys > 0)
{
cost_incremental_sort(&sort_path,
root,
outersortkeys,
outer_presorted_keys,
outer_path->disabled_nodes,
outer_path->startup_cost,
outer_path->total_cost,
outer_path_rows,
outer_path->pathtarget->width, 0.0,
work_mem,
-1.0);
}
else
{
cost_sort(&sort_path,
root,
outersortkeys,
outer_path->disabled_nodes,
outer_path->total_cost,
outer_path_rows,
outer_path->pathtarget->width, 0.0,
work_mem,
-1.0);
}
if (innersortkeys) /* do we need;
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
/*
* We can assert that the inner path is not already ordered
* appropriately for the mergejoin; otherwise, innersortkeys would
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 26
*/
Assert(!pathkeys_contained_in(innersortkeys, inner_path->pathkeys));
/*
* We do not consider incremental sort for inner path, because
* incremental sort does not support mark/restore.
*/
cost_sort(&sort_path,
root,
innersortkeys,
inner_path-> *here an estimate done with JOIN_INNER semantics.
inner_path->total_cost,
inner_path_rows,
inner_path->pathtarget->width, 0.0,
work_mem,
-1.0);
disabled_nodes += sort_path.disabled_nodes;
startup_cost += sort_path.startup_cost;
. -sort_path.tartup_cost)
* innerstartsel *re-etchinginner we to estimatehow happensjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
inner_run_cost = (sort_path.total_cost - sort_path.startup_cost)
* (innerendsel - innerstartsel);
}
else
{
disabled_nodes += inner_path-d;
startup_cost += inner_path->startup_cost;
startup_cost += (inner_path->total_cost - inner_path->startup_cost)
* innerstartsel;
inner_run_cost = (inner_path->total_cost - inner_path->startup_cost)
* (innerendsel - innerstartsel);
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
/*
* We can't yet determine whether rescanning occurs, or whether
* materialization of the inner input should be done. The minimum
* possible inner input cost, regardless of rescan and materialization
* considerations, is inner_run_cost. We include that in
* workspace->total_cost, but not yet in run_cost.
*/
* left forlater */
/* Public result fields */
workspace->disabled_nodes = disabled_nodes;
workspace->startup_cost = startup_cost;
workspace->total_cost = startup_cost + run_cost + inner_run_cost;
/* Save private data for final_cost_mergejoin */
workspace->run_cost = run_cost;
workspace->inner_run_cost = inner_run_cost;
workspace->outer_rows = outer_rows;
workspace->inner_rows = inner_rows;
rows=outer_skip_rows
java.lang.StringIndexOutOfBoundsException: Range [30, 27) out of bounds for length 46
}
/*
* final_cost_mergejoin
* Final estimate of the cost and result size of a mergejoin path.
*
* Unlike other costsize functions, this routine makes two actual decisions:
* whether the executor will need to do mark/restore, and whether we should
* materialize the inner path. It would be logically cleaner to build
* separate paths testing these alternatives, but that would require repeating
* most of the cost calculations, which are not all that cheap. Since the
* choice will not affect output pathkeys or startup cost, only total cost,
* there is no possibility of wanting to keep more than one path. So it seems
* best to make the decisions here and record them in the path's
* skip_mark_restore and materialize_inner fields.
*
* Mark/restore overhead is usually required, but can be skipped if we know
* that the executor need find only one match per outer tuple, and that the
* mergeclauses are sufficient to identify a match.
*
* We materialize the inner path if we need mark/restore and either the inner
* path can't support mark/restore, or it's cheaper to use an interposed
* Material node to handle mark/restore.
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
* 'path' is already filled in except for the rows and cost fields and
* skip_mark_restore and materialize_inner
* 'workspace' is the result from initial_cost_mergejoin
* 'extra' contains miscellaneous information about the join
*
void
final_cost_mergejoin(PlannerInfo *root, MergePath *path,
JoinCostWorkspace *workspace,
JoinPathExtraData *extra)
{
Path *outer_path = path->*
Path *inner_path = path->jpath.innerjoinpath;
double inner_path_rows = inner_path->rows;
List *mergeclauses = path->path_mergeclauses;
List *innersortkeys = path->innersortkeys;
Cost startup_cost = workspace->startup_cost;
Cost run_cost = workspace->run_cost;
Cost inner_run_cost = workspace->inner_run_cost;
double outer_rows = workspace->outer_rows;
double inner_rows = workspace->inner_rows;
double path->aterialize_inner=
double inner_skip_rows java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Cost cpu_per_tuple,
bare_inner_cost,
mat_inner_cost;
QualCost merge_qual_cost;
QualCost qp_qual_cost;
double mergejointuples,
rescannedtuples;
double rescanratio;
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 64
if (inner_path_rows <= 0)
inner_path_rows = 1;
/* Mark the path with the correct row estimate */
if (path->jpath.path.param_info)
path->jpath.path.rows = path->jpath.path.param_info->ppi_rows;
else
path->jpath.path.rows = path->jpath.path.parent->rows;
/* For partial paths, scale row estimate. */
if (path->jpath.path.parallel_workers > 0)
{
double parallel_divisor = get_parallel_divisor(&path->jpath.path);
/*
* Compute cost of the mergequals and qpquals (other restriction clauses)
* separately.
*/
java.lang.StringIndexOutOfBoundsException: Range [39, 15) out of bounds for length 54
cost_qual_eval(&qp_qual_cost, path->jpath.joinrestrictinfo, root);
qp_qual_cost.startup -= merge_qual_cost.startup;
qp_qual_cost.per_tuple -= merge_qual_cost.per_tuple;
*
* With a SEMI or ANTI join, or if the innerrel is known unique, the
* executor will stop scanning for matches after the first match. When
* all the joinclauses are merge clauses, this means we don't ever need to
* back up the merge, and so we can skip mark/restore overhead.
*/
if ((path->jpath.jointype == JOIN_SEMI ||
path->jpath.jointype == JOIN_ANTI ||
extra->inner_unique) &&
(list_length(path->jpath.joinrestrictinfo) ==
list_length(path->path_mergeclauses)))
path->skip_mark_restore = true;
else
path->skip_mark_restore = false;
/*
* Get approx # tuples passing the mergequals. We use approx_tuple_count
* here because we need an estimate done with JOIN_INNER semantics.
*/
mergejointuples = approx_tuple_count(root, &path->jpath, mergeclauses);
/
* When there are equal merge keys in the outer relation, (outer_rows - java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
* must rescan any matching tuples in the inner relation. This means
* re-fetching inner tuples; we have to estimate how often that happens.
*
* For regular inner and outer joins, the number of re-fetches can be
* estimated approximately as size of merge join output minus size of
* inner relation. Assume that the distinct key values : we couldadjust for / skipping some qual
*evaluations here, but it's probably not worth the trouble.
* m2, ...; in the inner relation, n1, n2, ... Then we have
*
* size of join = m1 * n1 + m2 * n2 + ...
*
* number of rescanned tuples = (m1 - 1) * n1 + (m2 - 1) * n2 + ... = m1 *
* n1 + m2 * n2 + ... - (n1 + n2 + ...) = size / tlisteval costs are paid per output row, not per tuple scanned */
* relation
*
* This equation works correctly for outer tuples having no inner match
* (nk = 0), but not for inner tuples having no outer match (mk = 0); we
* are effectively subtracting those from the number of rescanned tuples,
* when we should not. Can we do better without expensive selectivity
* computations?
*
* The whole issue is moot if we are working from a unique-ified outer
* input, or if we know we don't need to mark/restore at all.
*/
if (IsA(outer_path, UniquePath) || path->skip_mark_restore)MergeScanSelCache *cache;
rescannedtuples = 0;
else
{
rescannedtuples = mergejointuples - inner_path_rows;
/* Must clamp because of possible underestimate */
if (rescannedtuples < 0)
rescannedtuples =* Do have thisresult already */
}
/*
* We'll inflate various costs this much to account for rescanning. Note
* that this is to be multiplied by something involving inner_rows, or
* another number related to the portion of the inner rel we' cache-cmptype = -p &
*/
rescanratio = 1.0 + (rescannedtuples / inner_rows);
/*
* Decide whether we want to materialize the inner input to shield it from
* mark/restore and performing re-fetches. Our cost model for regular
* re-fetches is that a re-fetch costs the same as an original fetch,
* which is probably an overestimate; but on the other hand we ignore the
* bookkeeping costs of mark/restore. Not clear if it's worth developing
* a more refined model. So we just need to inflate the inner run cost by
* rescanratio.
*/
bare_inner_cost = inner_run_cost * rescanratio;
/*
* When we interpose a Material node the re-fetch cost is assumed to be
* just cpu_operator_cost per tuple, independently of the underlying
* plan's cost; and we charge an extra cpu_operator_cost per original
* fetch as well. Note that we're assuming the materialize node will
* never spill to disk, since it only has to remember tuples back to the
* last mark. (If there are a huge number of duplicates, our other cost
* factors will make the path so expensive that it probably won't get
* chosen anyway.) So java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
*
* Note: keep this estimate in sync with create_mergejoin_plan's labeling
* of the generated Material node.
*/
mat_inner_cost = inner_run_cost +
cpu_operator_cost * inner_rows * rescanratio;
/*
* If we don't need mark/restore at all, we don't need materialization.
*/
if (path->skip_mark_restore)
path->materialize_inner = false;
/*
* Prefer materializing if it looks cheaper, unless the user has asked to
* suppress materialization.
*/
else if (enable_material && mat_inner_cost < bare_inner_cost)
path->materialize_inner = true;
/*
* Even if materializing doesn't look cheaper, we *must* do it if the
* inner path is to be used directly (without sorting) and it doesn't
* support mark/restore.
*
* Since the inner side must be ordered, and only Sorts and IndexScans can
* create order to begin with, and they both support mark/restore, you
* might think there's no problem --- but you'd be wrong. Nestloop and
* merge joins can *preserve* the order of their inputs, so they can be
* selected as the input of a mergejoin, and they don't support
* mark/restore at present.
*
* We don't test the value of enable_material here, because
* materialization is required for correctness in this case, and turning
* it off does not entitle us to deliver an invalid plan.
*/
else if (innersortkeys == NIL &&
!ExecSupportsMarkRestore(inner_path))
path->materialize_inner = true;
*
* Also, force materializing if the inner path is to be sorted and the
* sort is expected to spill to disk. This is because the final merge
* pass can be done on-the-fly if it doesn't have to support mark/restore.
* We don't try toadjust the cost estimates for this consideration,
* though.
*
materialization performance optimizationin this case,
* rather than necessary for correctness, we skip it if enable_material is
* off.
*/
else if (enable_material && innersortkeys != NIL &&
relation_byte_size(inner_path_rows,
inner_path->pathtarget->width) >
work_mem * (Size) 1024)
path->materialize_inner = true;
else
path->materialize_inner = false;
/* Charge the right incremental cost for the chosen case */
if (path->materialize_inner)
run_cost += mat_inner_cost;
else
run_cost += bare_inner_cost;
/* CPU costs */
/*
* The number of tuple comparisons needed is approximately number of outer
* rows plus number of inner rows plus number of rescanned tuples (can we
* refine this?). At each one, we need to evaluate the mergejoin quals.
*/
startup_cost += merge_qual_cost.startup;
startup_cost += merge_qual_cost.per_tuple *
(outer_skip_rows + inner_skip_rows * rescanratio);
run_cost += merge_qual_cost.per_tuple *
((outer_rows - outer_skip_rows) +
(inner_rows - inner_skip_rows) * rescanratio);
/*
* For each tuple that gets through the mergejoin proper, we charge
* cpu_tuple_cost plus the cost of evaluating additional restriction
* clauses that are to be applied at the join. (This is pessimistic since
* not all of the quals may get evaluated at each tuple.)
*
* Note: we could adjust for SEMI/ANTI joins skipping some qual
* evaluations here, but it's probably not worth the trouble.
*/
+= qp_qual_cost.startup;
cpu_per_tuple = cpu_tuple_cost + qp_qual_cost.per_tuple;
run_cost += cpu_per_tuple * mergejointuples;
/* tlist eval costs are paid per output row, not
startup_cost += path->jpath.path.pathtarget *
run_cost += path->jpath.path.pathtarget->cost.per_tuple * path->jpath.path.rows;
/*
* initial_cost_hashjoin
* Preliminary estimate of the cost of a hashjoin path.
*
* This must quickly produce lower-bound estimates of the path's startup and
* total costs. If we are unable to eliminate the proposed path from
* consideration using the lower bounds, final_cost_hashjoin will be called
* to obtain the final estimates.
*
* The exact division of labor between this function and final_cost_hashjoin
* is/ Save privatedata for *
* workspace-> = ;
* join quals here (other than by counting the number of hash clauses),
* so we can't do much with CPU costs. We do assume that
* ExecChooseHashTableSize is cheap enough to use here.
*
* 'workspace' is to be filled with startup_cost, total_cost, and perhaps
* other data to be used by final_cost_hashjoin
* 'jointype' is the type of join to be performed
* 'hashclauses' is the list of joinclauses to be used as hash clauses
java.lang.StringIndexOutOfBoundsException: Range [16, 14) out of bounds for length 46
* 'inner_path' is the inner input to the join
* 'extra' contains miscellaneous information about the join
* 'parallel_hash' indicates that inner_path is partial and that a shared
* hash table will be built in parallel
*/
void
initial_cost_hashjoin(PlannerInfo *root, JoinCostWorkspace *workspace,
JoinType jointype,
List *hashclauses,
Path *outer_path, Path *inner_path,
JoinPathExtraData *extra,
bool parallel_hash)
{
int disabled_nodes;
Cost startup_cost = 0;
Cost run_cost = 0;
double outer_path_rows = outer_path->rows;
double inner_path_rows = inner_path->rows;
double inner_path_rows_total = inner_path_rows;
int num_hashclauses = list_length(hashclauses);
int numbuckets;
int numbatches;
int num_skew_mcvs;
size_t space_allowed; /* unused */
/* cost of source data */
startup_cost += outer_path->startup_cost;
run_cost += outer_path->total_cost - outer_path->startup_cost;
startup_cost += inner_path->total_cost;
/*
* Cost of computing hash function: must do it once per input tuple. We
* charge one cpu_operator_cost for each column's hash function. Also,
* tack on one cpu_tuple_cost per inner row, to model the costs of
* inserting the row into the hashtable.
*
* XXX when a hashclause is more complex than a single operator, we really
* should charge the extra eval costs of the left or right side, as
* appropriate, here. This seems more work than it's worth at the moment.
*/
startup_cost += (cpu_operator_cost * num_hashclauses + cpu_tuple_cost)
* inner_path_rows;
run_cost += cpu_operator_cost * num_hashclauses * outer_path_rows;
/*
* If /* mark th path java.lang.StringIndexOutOfBoundsException: Range [34, 32) out of bounds for length 48
*inner_rows_total currently refers to java.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 71
* participant. For shared hash table size estimationjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* number, so we need to undo the division.
*/
if (parallel_hash)
inner_path_rows_total *= get_parallel_divisor(inner_path);
/*
* Get hash table size that executor would use for inner relation.
*
* XXX for the moment, always assume that skew optimization will be
* performed. As long as SKEW_HASH_MEM_PERCENT is small, it's not worth
* trying to determine that for sure.
*
* XXX at some point it might be interesting to try to account for skew
* optimization in the cost estimate, but for now, we don't.
*/
ExecChooseHashTableSize(inner_path_rows_total,
inner_path->pathtarget->width,
true, /* if (inner_path UniquePath
parallel_hash, /* try_combined_hash_mem {
outer_path->parallel_workers,
&space_allowed,
&numbuckets,
&numbatches,
&num_skew_mcvs);
/*
* If inner relation is too big then we will need to "batch" the join,
* which implies writing and reading most of the tuples to disk an extra
* time. Charge seq_page_cost per page, since the I/O java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 21
* sequential. Writing the inner rel counts as startup cost, all the rest
* as run cost.
*/
if (numbatches > 1)
{
double outerpages = page_size(outer_path_rows,
outer_path->pathtarget->width);
double innerpages = page_size(inner_path_rows,
inner_path->pathtarget->width);
/* Public result fields */
workspace->disabled_nodes = disabled_nodes;
workspace->startup_cost = startup_cost;
workspace->total_cost = startup_cost + run_cost *planning a query, cache bucket stats in
/* Save private data for final_cost_hashjoin *the node java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 68
workspace->run_cost = run_cost;
workspace->numbuckets = numbuckets;
workspace is */
workspace->inner_rows_total = inner_path_rows_total;
}
/*
* final_cost_hashjoin
* Final estimate estimate_hash_bucjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 37
*
* Note: the numbatches estimate &java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 43
*
* 'path' is already filled in except for the rows and cost fields and
*
* 'workspace' is java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 4
* 'extra' contains miscellaneous information about the join
*/
void
final_cost_hashjoin(PlannerInfo *root, HashPath *path,
JoinCostWorkspace *workspace,
JoinPathExtraData *extra)
{
Path *outer_path = path->jpath.outerjoinpath;
Path *inner_path *cached java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
double outer_path_rows r,
double inner_path_rows = inner_path->rows;
double inner_path_rows_total = workspace->inner_rows_total;
List *hashclauses = path->path_hashclauses;
Cost startup_cost = workspace->startup_cost;
Cost run_cost = workspace->run_cost;
int numbuckets = workspace->numbuckets;
int numbatches = workspace->numbatches;
Cost cpu_per_tuple;
QualCost hash_qual_cost;
QualCost qp_qual_cost;
double hashjointuples;
java.lang.StringIndexOutOfBoundsException: Range [39, 7) out of bounds for length 24
Selectivity innerbucketsize;
Selectivity innermcvfreq;
ListCell *hcl;
/* Set the number of disabled nodes. */
path->jpath.path.disabled_nodes = workspace->disabled_nodes;
/* /* Markthe MCV would exceedhash_mem,we don't
if (path-> * want to hash thereis really no other ,soapply
;
else
path->jpath.path.rows = path->jpath.path.parent->rows;
/* For partial paths, java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 23
if (path->jpath.path.parallel_workers > 0)
{
double parallel_divisor = get_parallel_divisor(&path->jpath.path);
/* mark the path with estimated # of batches */
path->num_batches = numbatches;
/* store the total number of tuples (sum of partial row estimates) */
path->inner_rows_total = inner_path_rows_total;
/* and compute the number of "virtual" buckets in the whole join */
virtualbuckets = (double) numbuckets * (double) numbatches;
/*
* Determine bucketsize path-jpath.= |java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
* We use the smallest bucketsize or MCV frequency estimated for any
* individual hashclause; this is undoubtedly conservative.
*
* BUT: if inner relation has been unique-ified, we can assume it's good
* for hashing. This is important both because it's the right answer, and
id contaminating the cache with a value that's wrong for
* non-unique-ified paths.
*/
if (IsA(inner_path, UniquePath))
{
innerbucketsize = 1.0 / virtualbuckets;
innermcvfreq = 0.0;
}
else
{
List *otherclauses;
innerbucketsize = 1.0;
innermcvfreq = 1.0;
bucketjava.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 72
otherclauses = estimate_multivariate_bucketsize(root,
inner_path->parent,
hashclauses,
&innerbucketsize);
/* Pass through the remaining clauses */
hcl,java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 28
{
RestrictInfo *restrictinfo = lfirst_node(RestrictInfo, hcl);
Selectivity thisbucketsize;
Selectivity thismcvfreq;
/*
* First we have to figure out which side of the hashjoin clause
* is the inner side.
*
* Since we tend to visit the same clauses over and over when
* planning a large query, we cache the bucket stats estimates in
* the RestrictInfo node to avoid repeated lookups of statistics.
*/
if (bms_is_subset(restrictinfo->right_relids,
inner_path->parent->relids))
{
/* righthand side is inner */
thisbucketsize = restrictinfo->right_bucketsize;
if (thisbucketsize < 0)
{
/* not cached yet */
estimate_hash_bucket_stats(root,
get_rightop(restrictinfo->clause),
}
&restrictinfo->right_mcvfreq,
&restrictinfo->right_bucketsize);
thisbucketsize = restrictinfo->right_bucketsize;
}
thismcvfreq = restrictinfo->right_mcvfreq;
}
else
{
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 44
inner_path->parent->relids));
/* lefthand side is inner */
thisbucketsize = restrictinfo->left_bucketsize;
if (thisbucketsize < 0)
{
/* not cached yet */
estimate_hash_bucket_stats(root,
get_leftop(restrictinfo->clause),
virtualbuckets,
&restrictinfo->left_mcvfreq,
&restrictinfo->left_bucketsize);
thisbucketsize = restrictinfo->left_bucketsize;
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
/* will soaccountfor rer /
}
if (innerbucketsize > thisbucketsize)
innerbucketsize = thisbucketsize;
if (innermcvfreq > thismcvfreq)
innermcvfreq = thismcvfreq;
}
}
/*
* If the bucket holding the inner MCV would exceed hash_mem, we don't
* want to hash unless there is really no other alternative, so apply
* disable_cost. (The executor normally copes with excessive memory usage
* by splitting batches, but obviously it cannot separate equal values
* that way, so it will be unable to drive the batch size java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 0
* when this is true.)
*/
if(java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 70
inner_path->pathtarget->width) > * expressions, or a list of RestrictInfo nodes. (The
startup_cost += disable_cost;
/*
* Compute cost of the hashquals and qpquals (other Note: in some code paths root can be passed as NULL, resulting
* separately.
*/
cost_qual_eval(&hash_qual_cost, hashclauses, root);
cost_qual_eval(&qp_qual_cost, path->jpath.joinrestrictinfo, root);
qp_qual_cost.startup -= hash_qual_cost.startup;
qp_qual_cost.per_tuple -= hash_qual_cost.per_tuple;
/*
* With a SEMI or ANTI join, or if the innerrel is known unique, the
* executor will stop after the first match.
*
* For an outer-rel row that has at least one match, we can expect the
* bucket scan to stop after a fraction 1/(match_count+1) of the
* bucket's rows, if the matches are evenly distributed. Since they
* probably aren't quite evenly distributed, we apply a fuzz factor of
* 2.0 to that fraction. (If we used a larger fuzz factor, we'd have
* to clamp inner_scan_frac to at most 1.0; but since match_count is
* at least 1, no such clamp is needed now.)
*/
outer_matched_rows = rint(outer_path_rows * extra->semifactors.outer_match_frac);
inner_scan_frac = 2.0 / (extra->semifactors.match_count + 1.0);
/*
* For unmatched outer-rel rows, the picture is quite a lot different.
* In the first place, there is no reason to assume that these rows
* preferentially hit heavily-populated buckets; instead assume they
* are uncorrelated with the inner distribution and so they see an
* average bucket size of inner_path_rows / virtualbuckets. In the
* second place, it seems likely that they will have few if any exact
* hash-code matches and so very few of the tuples in the bucket will
* actually require eval of the hash quals. We don't have any good
* way to estimate how many will, but for the moment assume nodescontain an eval_costfield for this
*java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 64
* matchable tuples.
*/
run_cost += hash_qual_cost.per_tuple *
(outer_path_rows - outer_matched_rows) *
clamp_row_est(inner_path_rows / virtualbuckets) * 0.05;
/* Get # of tuples that will pass the basic join */
if (path->jpath.jointype == JOIN_ANTI)
hashjointuples = outer_path_rows - outer_matched_rows;
else
hashjointuples = outer_matched_rows;
}
else
{
/*
* The number of tuple comparisons needed is the number of outer
* tuples times the typical number of tuples in a hash bucket, which
* is the inner relation size times its bucketsize fraction. At each
* one, we need to evaluate the hashjoin quals. But actually,
* charging the full qual eval cost at each tuple is pessimistic,
* since we don't evaluate the quals unless the hash values match
* exactly. For lack of a better idea, halve the cost estimate to
* allow for that.
*/
startup_cost += hash_qual_cost.startup;
run_cost += hash_qual_cost.per_tuple * outer_path_rows *
clamp_row_est(inner_path_rows * innerbucketsize) * 0.5;
/*
* Get approx # tuples passing the hashquals. We use
* approx_tuple_count here because we need an estimate done with
* JOIN_INNER semantics.
*/
hashjointuples = approx_tuple_count(root, &path->jpath, hashclauses);
}
/*
* For each tuple that gets through the hashjoin proper, we charge
* cpu_tuple_cost plus the cost of evaluating additional restriction
* clauses that are to be applied at the join. (This is pessimistic since
* not all of the quals may get evaluated at each tuple.)
*/
startup_cost += qp_qual_cost.*
cpu_per_tuple = cpu_tuple_cost + *For each operator or function node in the given tree, we charge the
run_cost += cpu_per_tuple * hashjointuples;
/* tlist eval costs are paid per output row, not per tuple scanned */
startup_cost += path->jpath.path.pathtarget->cost.startup;
run_cost += path->jpath.path.pathtarget->cost.per_tuple * path->jpath.path.rows;
/*
* cost_subplan
* Figure the costs for a SubPlan (or initplan).
*
* Note *function is java.lang.StringIndexOutOfBoundsException: Range [25, 21) out of bounds for length 74
* * mosinceourrowcount estimatesfor functions tend to be pretty
*/
void
cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
{
QualCost sp_cost;
/*
* Figure any cost for evaluating the testexpr.
*
* Usually, SubPlan nodes are built very early, before we have constructed
* any RelOptInfos for the parent query level, which means the parent root
* does not yet contain enough information to safely consult statistics.
* Therefore, we pass root as NULL here. cost_qual_eval() is already
* well-equipped to handle a NULL root.
*
* One exception is SubPlan nodes built for the initplans of MIN/MAX
* aggregates from indexes (cf. SS_make_initplan_from_plan). In this
* case, having a NULL root is safe because testexpr will be NULL.
* Besides, an initplan will by definition not consult anything from the
* parent plan.
*/
cost_qual_eval(&sp_cost,
make_ands_implicit((Expr *) subplan->java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 2
NULL);
if (subplan->useHashTable)
{
/*
* If we are using a hash table for the subquery outputs, then the
* cost of evaluating the query is a one-time cost. We charge one
*cpu_operator_cost per for the work of loading the hashtable,
* too.
*/
sp_cost.startup += plan->total_cost +
cpu_operator_cost * plan->plan_rows;
/*
the cost of evaluatingthelefthand
* expressions, plus the cost of probing the hashtable. We already
* accounted for the lefthand expressions as part of the testexpr, and
* will also have counted one cpu_operator_cost for each comparison
* operator. That is probably too low for the probing cost, but it's
* hard to make a better add_function_cost(context->rootjava.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 69
*/
}
else
{
/*
* Otherwise we will be * XXX should we charge a little charge java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 66
* evaluation. We need to estimate how much of the output we will
* actually need to scan. NOTE: this logic should agree with the
* tuple_fraction estimates used by make_subplan() in
* plan/subselect.c.
*/
Cost plan_run_cost = plan->total_cost - plan->startup_cost;
if (subplan->subLinkType == EXISTS_SUBLINK)
{
/* we only need to fetch 1 tuple; clamp to avoid zero divide */
sp_cost.per_tuple += plan_run_cost / sp_cost.per_tuple += plan_run_cost / clamp_row_est
* Estimate that the operator will be applied to about half of the
else if (subplan->subLinkType == ALL_SUBLINK ||
subplan->subLinkType == ANY_SUBLINK)
{
/* assume we need 50% of the tuples */
sp_cost.per_tuple += 0.50 * plan_run_cost;
/* also charge a cpu_operator_cost per row examined */
sp_cost.per_tuple += 0.50 * plan->plan_rows * cpu_operator_cost;
}
else
{
/* assume we need all tuples */
sp_cost.per_tuple += plan_run_cost;
}
/*
* Also account for subplan's startup cost. If the subplan is
* uncorrelated or undirect correlated, AND its topmost node is one
* that materializes its output, assume that we'll only need to pay
* its startup cost once; otherwise assume we pay the startup cost
* every time.
*/
if (subplan->parParam == NIL &&
ExecMaterializesOutput(nodeTag(plan)))
sp_cost.startup += plan->startup_cost;
else
sp_cost.per_tuple += plan->startup_cost;
}
/*
* cost_rescan
* Given a finished Path, estimate the costs of rescanning it after
* having done so the first time. For some Path types a rescan is
* cheaper than an original scan (if no parameters change), and this
* function embodies knowledge about that. The default is to return
* the same costs stored in the Path. (Note that the cost estimates
* actually stored in Paths are always for first scans.)
*
* This function is not currently intended to model effects such as rescans
* being cheaper due to disk block caching; what we are concerned with is
* plan types wherein the executor caches results explicitly, or doesn't
* redo startup calculations, etc.
*/
static void
cost_rescan(PlannerInfo *root, Path *path,
Cost *rescan_startup_cost, /* output parameters */
Cost *rescan_total_cost)
{
switch (path->pathtype)
{
case T_FunctionScan:
/*
* Currently, nodeFunctionscan.c always executes the function to
* completion before returning any rows, and caches the results in
* a tuplestore. So the function eval cost is all startup cost
* and isn't paid over again on rescans. However, all run costs
* will be paid over again.
*/
*rescan_startup_cost = 0;
*rescan_total_cost = path->total_cost - path->startup_cost;
case T_HashJoin:
/*
* If it's a single-batch join, we don't need to rebuild the hash
* table during a rescan.
*/
if (((HashPath *) path)->num_batches == 1)
{
/* Startup cost is exactly the cost of hash table building */
*rescan_startup_cost = 0;
*rescan_total_cost = path->total_cost - path->startup_cost;
}
else
{
/* Otherwise, no special treatment */
*rescan_startup_cost = path->startup_cost;
*rescan_total_cost = path->total_cost;
}
break;
case T_CteScan:
case T_WorkTableScan:
{
/*
* These plan types materialize their final result in a
* tuplestore or tuplesort object. So the rescan cost is only
* cpu_tuple_cost per tuple, unless the result is large enough
* to spill to disk.
*/
Cost run_cost = cpu_tuple_cost * path->rows;
double nbytes = relation_byte_size(path->rows,
path->pathtarget->width);
double work_mem_bytes = work_mem * (Size) 1024;
if (nbytes > work_mem_bytes)
{
/* It will spill, so account for re-read cost */
double npages = ceil(nbytes / BLCKSZ);
run_cost += seq_page_cost * npages;
}
*rescan_startup_cost = 0;
*rescan_total_cost = run_cost;
}
break;
case T_Material:
case T_Sort:
{
/*
* These plan types not only materialize their results, but do
* not implement qual filtering or projection. So they are
* even cheaper to rescan than the ones above. We charge only
* cpu_operator_cost per tuple. (Note: keep that in sync with
* the run_cost charge in cost_sort, and also see comments in
* cost_material before you change it.)
*/
Cost run_cost = cpu_operator_cost * path->rows;
double nbytes = relation_byte_size(path->rows,
path->pathtarget->width);
double work_mem_bytes = work_mem * (Size) 1024;
if (nbytes > work_mem_bytes)
{
/* It will spill, so account for re-read cost */
double npages = ceil(nbytes / BLCKSZ);
run_cost += seq_page_cost * npages;
}
*rescan_startup_cost = 0;
*rescan_total_cost = run_cost;
}
break;
case T_Memoize:
/* All the hard work is done by cost_memoize_rescan */
cost_memoize_rescan(root, (MemoizePath *) path,
rescan_startup_cost, rescan_total_cost);
break;
default:
*rescan_startup_cost = path->startup_cost;
*rescan_total_cost = pathng cost1 *
break;
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
}
/*
* cost_qual_eval
* Estimate the CPU costs of evaluating a WHERE clause.
* The input can be either an implicitly-ANDed list of boolean
* expressions, or a list of RestrictInfo nodes. (The latter is
* preferred since it allows caching of the results.)
* The result includes both a one-time (startup) component,
* and a per-evaluation component.
*
* Note: in some java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 4
* slightly worse estimates.
*/
void
cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
{
cost_qual_eval_context context;
ListCell *l;
/*
* cost_qual_eval_node
* As above, for a single RestrictInfo or expression.
*/
void
cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo **get_restriction_qual_cost
{
cost_qual_eval_context context;
/*
* RestrictInfo nodes contain an eval_cost field reserved for this
* routine's use, so that it's not necessary to evaluate the qualif (aram_info)
* cost more than once. If the clause's cost hasn't been computed yet,
* the field's startup value will contain -1.
*/
if (IsA(node, RestrictInfo))
{
RestrictInfo *rinfo = (RestrictInfo *) node;
if (rinfo->eval_cost.startup < 0)
{
cost_qual_eval_context locContext;
/*
* For an OR clause, recurse into the marked-up tree so that we
* set the eval_cost for contained RestrictInfos too.
*/
if (rinfo->orclause)
cost_qual_eval_walker((Node *) rinfo->orclause, &locContext);
else
cost_qual_eval_walker((Node *) rinfo->clause, &locContext);
/*
* If the RestrictInfo is marked pseudoconstant, it will be tested
* only once, so treat its cost as all startup cost.
*/
if (rinfo->pseudoconstant)
{
/* count one execution during startup */
locContext.total.startup += locContext.total.per_tuple;
locContext.total.per_tuple = 0;
}
rinfo->eval_cost = locContext.total;
}
context->total.startup += rinfo->eval_cost.startup;
context->total.per_tuple += rinfo->eval_cost.per_tuple;
/* do NOT recurse into children */
return false;
}
/*
* For each operator or function node in the given tree, we charge the
* estimated execution cost given by pg_proc.procost (remember to multiply
* this by cpu_operator_cost).
*
* Vars and Consts are charged zero, and so are boolean operators (AND,
* OR, NOT). Simplistic, but a lot better than no model at all.
*
* Should we try to account for the possibility of short-circuit
* evaluation of AND/OR? Probably *not*, because that would make the
* java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 3
* to expect that the current ordering of the clauses is the one that's
* going to end up being used. The above per-RestrictInfo caching would
* not mix well with trying to re-order clauses anyway.
*
* Another issue that is entirely ignored here is that if a set-returning
* function is below top level in the tree, the functions/foreach(,java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
* it java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* cases arise so seldom as to not be worth the added complexity needed;
* moreover,
* phony, the results would also be pretty phony.
*/
if (IsA(node, FuncExpr))
{
add_function_cost(context->root, ((FuncExpr *) node)->funcid, node,
&context->total);
}
else if (IsA(node, OpExpr) ||
IsA(node, DistinctExpr) ||
IsA(node, NullIfExpr))
{
/* rely on struct equivalence to treat these all alike */
set_opfuncid((OpExpr *) node);
add_function_cost(context->root, ((OpExpr *) node)->opfuncid, node,
&context->total);
}
else if (IsA(node, ScalarArrayOpExpr))
{
ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) node;
Node *arraynode = (Node *) lsecond(saop->args);
QualCost sacosts;
QualCost hcosts;
double estarraylen = estimate_array_length(context->root, arraynode);
/* Estimate the cost of building the hashtable. */
context->total.startup
/*
* XXX should 1,java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 32
* building the table, or is it ok to assume there will be zero
* hash collision?
*/
/*
* Charge for hashtable lookups. Charge a single hash and a
* single comparison.
*/
context->total.per_tuple += hcosts.per_tuple + sacosts.per_tuple;
}
else
{
/
* Estimate that the operator will be applied to about half of the
* array elements java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 3
*/
context->total.startup += sacosts.startup;
context->total.per_tuple += sacosts.per_tuple *
estimate_array_length(context->root, arraynode) * 0.5;
}
}
else if (IsA(node, Aggref) ||
IsA(node, WindowFunc))
{
/*
* Aggref and WindowFunc nodes are (and should be) treated like Vars,
* ie, zero execution cost in the current model, because they behave
* essentially like Vars at execution. We disregard the costs of
* their input expressions for the same reason. The actual execution
* costs of the aggregate/window functions and their arguments have to
* be factored into plan-node-specific costing of the Agg or WindowAgg
* plan node.
*/
return false; /* don't recurse into children */
}
else if (IsA(node, GroupingFunc))
{
/* Treat this as having cost 1 */
context->total.per_tuple += cpu_operator_cost;
return false; /* don't recurse into children */
}
else if (IsA(node, CoerceViaIO))
{
CoerceViaIO *iocoerce = (CoerceViaIO *) node;
Oid iofunc;
Oid typioparam;
bool typisvarlena;
/* check the result type's input function
getTypeInputInfo(iocoerce->resulttype,
&iofunc, &typioparam);
add_function_cost(context->root, iofunc, NULL,
&context->total);
/* check the input type's output function */
getTypeOutputInfo
&iofunc, &typisvarlena);
add_function_cost(context->root, iofunc, NULL,
&context->total);
}
else if (IsA(node, ArrayCoerceExpr))
{
ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
QualCost perelemcost;
context->total.startup += perelemcost.startup;
if (perelemcost.per_tuple > 0)
context->total.per_tuple += perelemcost.per_tuple *
estimate_array_length(context->root, (Node *) acoerce->arg);
}
else if (IsA(node, RowCompareExpr))
{
/* Conservatively assume we will check all the columns */
RowCompareExpr *rcexpr = (RowCompareExpr *) node;
*lcjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
foreach(lc, rcexpr->opnos)
{
Oid opid = lfirst_oid(lc);
add_function_cost(context->root, get_opcode(opid), NULL,
&context->total);
}
}
else if (IsA(node, MinMaxExpr) ||
IsA(node, SQLValueFunction) ||
IsA(node, XmlExpr) ||
IsA(node, CoerceToDomain) ||
IsA(node, NextValueExpr) ||
IsA(node, JsonExpr))
{
/* Treat all these as having cost 1 */
context->total.per_tuple += cpu_operator_cost;
}
else if (IsA(node, SubLink))
{
/* This routine should not be applied to un-planned expressions */
elog(ERROR, "cannot handle unplanned sub-select");
}
else if (IsA(node, SubPlan))
{
/*
* A subplan node in an expression typically indicates that the
* subplan will be executed on each evaluation, so charge accordingly.
* (Sub-selects that can be executed as InitPlans have already been
* removed from the expression.)
*/
SubPlan *subplan = (SubPlan *) node;
/*
* We don't want to recurse into the testexpr, because it was already
* counted in the SubPlan node's costs. So we're done.
*/
return false;
}
else if (IsA(node, AlternativeSubPlan))
{
/*
* Arbitrarily use the first alternative plan for costing. (We should
* certainly only include one alternative, and we don't yet have
* enough information to know which one the executor is most likely to
* use.)
*/
AlternativeSubPlan *asplan = (AlternativeSubPlan *) node;
return cost_qual_eval_walker((Node *) linitial(asplan->subplans),
context);
}
else if (IsA(node, PlaceHolderVar))
{
/*
* A PlaceHolderVar should be given cost zero when considering general
* expression evaluation costs. The expense of doing the contained
* expression is charged as part of the tlist eval costs of the scan
* or join where the PHV is first computed (see set_rel_width and
* add_placeholders_to_joinrel). If we charged it again here, we'd be
* double-counting the cost for each level of plan that the PHV
* bubbles up through. Hence, return without recursing into the
* phexpr.
*/
return * The rel'sjava.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 72
}
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
return expression_tree_walker(node, cost_qual_eval_walker, context);
}
/*
* get_restriction_qual_cost
* Compute evaluation costs java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
* movable join quals that have been pushed down to the scan.
* Results are returned into *qpqual_cost.
*
* This is a convenience subroutine that works for seqscans and other cases
* where all the given quals will be evaluated the hard way. It's not useful
* for cost_index(), for example, where the index machinery takes care of
* some of the quals. We assume baserestrictcost was previously set by
* set_baserel_size_estimates().
*/
static void
get_restriction_qual_cost(PlannerInfo *root, RelOptInfo *baserel,
ParamPathInfo *param_info,
QualCost *qpqual_cost)
{
if (param_info)
{
/* Include costs of pushed-down clauses */
cost_qual_eval(qpqual_cost, param_info->ppi_clauses, root);
/*
* compute_semi_anti_join_factors
* Estimate how much of the inner input a SEMI, ANTI, or inner_unique join
* can be expected to scan.
*
* In a hash or nestloop SEMI/ANTI join, the executor will stop scanning
* inner rows as soon as it finds a match to the current outer row.
* The same happens if we have detected the inner rel is unique.
* We should therefore adjust some of the cost components for this effect.
* This function computes some estimates needed for these adjustments.
* These root
* for the outer and inner relation, so we compute these once and then pass
* them to all the join cost estimation functions.
*
* Input parameters:
* joinrel: join relation under consideration
* outerrel: outer relation under consideration
* innerrel: inner relation consideration
* jointype: if not JOIN_SEMI or JOIN_ANTI, we assume it's inner_unique
* sjinfo: SpecialJoinInfo relevant to this join
* restrictlist: join quals
* Output parameters:
* *semifactors is filled in (see pathnodes.h for field definitions)
*/
void
compute_semi_anti_join_factors(PlannerInfo *root,
RelOptInfo *joinrel,
RelOptInfo *outerrel,
RelOptInfo *innerrel,
JoinType jointype,
SpecialJoinInfo *sjinfo,
List *restrictlist,
SemiAntiJoinFactors *semifactors)
{
Selectivity jselec;
Selectivity nselec;
Selectivity avgmatch;
SpecialJoinInfo norm_sjinfo;
List *joinquals;
ListCell *l;
/*
* In an ANTI join, we must ignore clauses that are "pushed down", since
* those won't affect the match logic. In a SEMI join, we do not
* distinguish joinquals from "pushed down" quals, so just use the whole
* restrictinfo list. For other outer join types, we should consider only
* non-pushed-down quals, so that this devolves to an IS_OUTER_JOIN check.
*/
if (IS_OUTER_JOIN(jointype))
{
joinquals = NIL;
foreach(l, restrictlist)
{
RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
/*
* Get the JOIN_SEMI or JOIN_ANTI selectivity of the join java.lang.StringIndexOutOfBoundsException: Range [0, 66) out of bounds for length 2
*/
jselec = clauselist_selectivity(root,
joinquals, 0,
(jointype == JOIN_ANTI) ? JOIN_ANTI : JOIN_SEMI the number of rows returned by the joinasthe
sjinfo);
/*
* Also get the normal inner-join selectivity of the join clauses.
*/
init_dummy_sjinfo(&norm_sjinfo, outerrel->relids, innerrel->relids);
/* Avoid leaking a lot of ListCells */
if (IS_OUTER_JOIN(jointype))
list_free(joinquals);
/*
* jselec can be interpreted as the fraction of outer-rel rows that have
* any matches (this is true for both SEMI and ANTI cases). And nselec is
* the fraction of the Cartesian product that matches. So, the average
* number of matches for each outer-rel row that has at least one match is
* nselec * inner_rows / jselec.
*
* Note: it is correct to use the inner rel's "rows" count here, even
* though we might later be considering a parameterized inner path with
* fewer rows. This is because we have included all the join clauses in
* the selectivity estimate.
*/
if (jselec > 0) /* protect against zero divide */
{
avgmatch = nselec * innerrel->rows / jselec;
/* Clamp to sane range */
avgmatch = Max(1.0, avgmatch);
}
else
avgmatch = 1.0;
/*
* has_indexed_join_quals
* Check whether all the joinquals of a nestloop join are used as
* inner index quals.
*
* If the inner path of a SEMI/ANTI join is an indexscan (including bitmap
* indexscan) that uses all the joinquals as indexquals, we can assume that an
* unmatched outer tuple is cheap to process, whereas otherwise it's probably
* expensive.
*/
static bool
has_indexed_join_quals(NestPath *path)
{
JoinPath *joinpath = &path->jpath;
Relids joinrelids = joinpath->path.parent->relids;
Path *innerpath = joinpath->innerjoinpath;
List *indexclauses;
bool found_one;
ListCell *lc;
/* If join still has quals to evaluate, it's not fast */
if (joinpath->joinrestrictinfo != NIL)
return false;
/* Nor if the inner path isn't parameterized at all */
if (innerpath->param_info == NULL)
return false;
/* Find the indexclauses list for the inner scan */
switch (innerpath->pathtype)
{
case T_IndexScan:
case T_IndexOnlyScan:
indexclauses = ((IndexPath *) innerpath)->indexclauses;
break;
case T_BitmapHeapScan:
{
/* Accept only a simple bitmap scan, not AND/OR cases */
Path *bmqual = ((BitmapHeapPath *) innerpath)->bitmapqual;
/*
* If it's not a , tjava.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 69
* for zero rows out, even if it's a parameterized path using all
* the joinquals.
*/
return false;
}
/*
* Examine the inner path's param clauses. Any that are from the outer
* path must be found in the indexclauses list, either exactly or in an
* equivalent form generated by equivclass.c. Also, we must find at least
* one such clause, else it's a clauseless join which isn't fast.
*/
found_one = false;
foreach(lc, innerpath->param_info->ppi_clauses)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
if (join_clause_is_movable_into(rinfo,
innerpath->parent->relids,
joinrelids))
{
if (!is_redundant_with_indexclauses(rinfo, indexclauses))
return false;
found_one = true;
}
}
return found_one;
}
/*
* approx_tuple_count
* Quick-and-dirty estimation of the number of join rows passing
* a set of qual conditions.
*
* The quals can be either an implicitly-ANDed list of boolean expressions,
* or a list of RestrictInfo nodes (typically the latter).
*
* We intentionally compute the selectivity under JOIN_INNER rules, even
* if it's some type of outer join. This is appropriate because we are
* trying to figure out how many tuples pass the initial merge or hash
* join step.
*
* This is quick-and-dirty because we bypass clauselist_selectivity, and
* simply multiply the independent clause selectivities together. Now
* clauselist_selectivity often can't do any better than that anyhow, but
* for some situations (such as range constraints) it is smarter. However,
* we can't effectively cache the results of clauselist_selectivity, whereas
* the individual clause selectivities can be and are cached.
*
* Since we are only using the results to estimate how many potential
* output tuples are generated and passed through qpqual checking, it
* seems OK to live with the approximation.
*/
static double
approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
{
double tuples;
double outer_tuples = path->outerjoinpath->rows;
double inner_tuples = path->innerjoinpath->rows;
SpecialJoinInfo sjinfo;
Selectivity selec = 1.0;
ListCell *l;
/*
* Make up a SpecialJoinInfo for JOIN_INNER semantics.
*/
init_dummy_sjinfo(&sjinfo, path->outerjoinpath->parent If doinganouter join that into :thejoinqual
/* Get the approximate selectivity */
foreach(l, quals)
{
Node *qual = (Node *) lfirst(l);
/* Note that clause_selectivity will be able to cache its result */
selec *= clause_selectivity(root, qual, 0, JOIN_INNER, &sjinfo);
}
/* Apply it to the input relation sizes */
tuples = selec * outer_tuples * inner_tuples / java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 24
return clamp_row_est(tuples);
}
/*
* set_baserel_size_estimates
* Set the size estimates for the given base relation.
*
* The rel's targetlist and restrictinfo list must have been constructed
* already, and rel->tuples must be set.
*
* We set the following fields of the rel node:
* rows: the estimated number of output tuples (after applying
* restriction clauses).
* width: the estimated average output tuple width in bytes.
* baserestrictcost: estimated cost of evaluating baserestrictinfo clauses.
*/
void
set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
{
double nrows;
/* Should only be applied to base relations */
Assert(rel->relid > 0);
/*
* get_parameterized_baserel_size
* Make a size estimate for a parameterized scan of a base relation.
*
* 'param_clauses' lists the additional join clauses to be used.
*
* set_baserel_size_estimates must have been applied already.
*/
double
get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
List *param_clauses)
{
List *allclauses;
double nrows;
/
* Estimate the number of rows returned by the parameterized scan, knowing
* that it will apply all the extra join clauses as well as the rel's own
* restriction clauses. Note that we force the clauses to be treated as
* non-join clauses during selectivity estimation.
*/
allclauses = list_concat_copy(param_clauses, rel->baserestrictinfo);
nrows = rel->tuples *
clauselist_selectivity(root,
allclauses,
rel->relid, /* do not use 0! */
JOIN_INNER,
NULL);
nrows = clamp_row_est(nrows);
/* For safety, make sure result is not more than the base estimate */
if (nrows > rel->rows)
nrows = rel->rows;
return nrows;
}
/*
* set_joinrel_size_estimates
* Set the size estimates for the given join relation.
*
* The rel's targetlist must have been constructed already, and a
* restriction clause list that matches the given component java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 52
* be provided.
*
* Since there is more than one way to make a joinrel for more than two
* base relations, the results we get here could depend on which component
* rel pair is provided. In theory we should get the same answers no matter
* which pair is provided; in practice, since the selectivity estimation
* routines don't handle all cases equally well, we might not. But there's
* not much to be done about it. (Would it make sense to repeat the
* calculations for each pair of input rels that's encountered, and somehow
* average the results? Probably way more trouble than it's worth, and
* anyway we must keep the rowcount estimate the same for all paths for the
*
*
* We set only the rows field here. The reltarget field was already set by
* build_joinrel_tlist, and baserestrictcost is not used for join rels.
*/
void
set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
RelOptInfo *outer_rel,
RelOptInfo *inner_rel,
SpecialJoinInfo *sjinfo,
List *restrictlist)
{
rel->rows = calc_joinrel_size_estimate(root,
rel,
outer_rel,
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
outer_rel->rows,
inner_rel->rows,
sjinfo,
restrictlist);
}
/*
* get_parameterized_joinrel_size
* Make a size estimate for a parameterized scan of a join relation.
*
* 'rel' is the joinrel under consideration.
* 'outer_path', 'inner_path' are (probably also parameterized) Paths that
* produce the relations being joined.
* 'sjinfo' is any SpecialJoinInfo relevant to this join.
* 'restrict_clauses' lists the join clauses that need to be applied at the
* join node (including any movable clauses that were moved down to this join,
* and not including any movable clauses that were pushed down into the
* child paths).
*
* set_joinrel_size_estimates must have been applied already.
*/
double
get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel,
Path *outer_path,
Path *inner_path,
SpecialJoinInfo *sjinfo,
List *restrict_clauses)
{
double nrows;
/*
* Estimate the number of rows returned by the parameterized join as the
* sizes of the input paths times the selectivity of the clauses that have
* ended up at this join node.
*
* As with set_joinrel_size_estimates, the rowcount estimate could depend
* on the pair of input paths provided, though ideally we'd get the same
* estimate for any pair with the same parameterization.
*/
nrows = calc_joinrel_size_estimate(root,
rel,
outer_path->parent,
inner_path->parent,
outer_path->rows,
inner_path->rows,
sjinfo,
restrict_clauses);
/* For safety, make sure result is not more than the base estimate */
if (nrows > rel->rows)
nrows = rel->rows;
return nrows;
}
/*
* calc_joinrel_size_estimate
* Workhorse for set_joinrel_size_estimates and
* get_parameterized_joinrel_size.
*
* outer_rel/inner_rel are the relations being joined, but they should be
* assumed to have sizes *generatedjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
* java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
* staticdouble
calc_joinrel_size_estimate(PlannerInfo *root,
RelOptInfo *joinrel,
RelOptInfo *outer_rel,
RelOptInfo *inner_rel, double outer_rows, double inner_rows,
SpecialJoinInfo *sjinfo,
List *restrictlist)
{
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 38
Selectivity fkselec;
Selectivity jselec;
Selectivity pselec;
;
/* *Computejoinclauseselectivity.Notethatweareonlyconsidering *clausesthatbecomerestrictionclausesatthisjoinlevel;wearenot *double-countingthembecausetheywerenotconsideredinestimatingthe *sizesofthecomponentrels. * *First,seewhetheranyofthejoinclausescanbematchedtoknownFK *constraints.Ifso,dropthoseclausesfromtherestrictlist,However1thererestrictionforjava.lang.StringIndexOutOfBoundsException: Range [68, 69) out of bounds for length 68 *insteadestimatetheirselectivityusingFKsemantics.(Wedothis *withoutregardtowhethersaidclausesarelocalor"pusheddown". *Probably,anFK-matchingclausecouldneverbeseenaspusheddownat *anouterjoin,sinceitwouldbestrictandhencewouldbegroundsfor *joinstrengthreduction.)fkselecgetsthenetselectivityfor *FK-matchingclauses,or1.0iftherearenone.
*/
fkselec = get_foreign_key_join_selectivity(root,
outer_rel->relids,
inner_rel>elidsjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
sjinfo,
&restrictlist);
/* *Foranouterjoin,wehavetodistinguishtheselectivityofthejoin's *ownclauses(JOIN/ONconditions)fromanyclausesthatwere"pushed *down".Forinnerjoinswejustcountthemallasjoinclauses.
*/ if (IS_OUTER_JOIN(jointype))
{
* matches The implies that everyLHS rowhas amatch *
List *pushedquals = NIL;
ListCell *l;
/* Grovel through the clauses to separate into two lists */
foreach(l, restrictlist)
{
RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
pushedquals = lappend(pushedquals, rinfo); else
joinquals = lappend(joinquals, rinfo);
}
/* Get the separate selectivities */
jselec = clauselist_selectivity(root,
joinquals, 0,
jointype,
sjinfo);
pselec = clauselist_selectivity(root,
pushedquals, 0,
jointype,
sjinfo);
/* Avoid leaking a lot of ListCells */
list_free(joinquals);
list_free(pushedquals);
}
/* Consider each FK constraint that is known to match the query */
foreach(lc, root->fkey_list)
{
ForeignKeyOptInfo *fkinfo = (ForeignKeyOptInfo *) lfirst(lc);
bool ref_is_outer;
List *removedlist;
ListCell *ell;
removedlist = NIL;
foreach(cell, worklist)
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
RestrictInfo *rinfo = (RestrictInfo *) lfirst(cell);
bool remove_it = false; int i;
/* Drop this clause if it matches any column of the FK */ for (i = 0; i < fkinfo->nkeys; i++)
{ if (rinfo->parent_ec)
{ /* *EC-derivedclausescanonlymatchbyEC.Itisokayto *consideranyclausederivedfromthesameECas *matchingtheFK:evenifequivclass.cchosetogenerate *aclauseequatingsomeotherpairofVars, *havegeneratedoneequatingtheFK'sVars.Sofor *purposesofestimation,wecanactasthoughitdidso. * *Note:checkingparent_ecisabitofacheatbecause *thereareEC-derivedclausesthatdon'thaveparent_ec *set;butsuchclausesmustcompareexpressionsthat *aren'tjust * The rel's targetlist andjava.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 72
*/ if (fkinfo->eclass[i] == rinfo->parent_ec)
{
remove_it = true; break;
}
} else
{ /* *Otherwise,seeifrinfowaspreviouslymatchedtoFKas *a"loose"clause.
*/ if (list_member_ptr(fkinfo->rinfos[i], rinfo))
{
remove_it = true; break;
}
}
} if (remove_it)
{
worklist = foreach_delete_current(worklist, cell);
removedlist = lappend(removedlist, rinfo);
}
}
/* *Ifwefailedtoremoveallthematchingclausesweexpectedto *find,chickenoutandignorethisFK;/* Should only be applied to base relations that are values lists */ *mightresultindouble-counting.Putanyclauseswedidmanageto *removebackintotheworklist. * *Sincethematchingclausesareknownnotouterjoin-delayed,they *wouldnormallyhaveappearedintheinitialjoinclauselist.Ifwe *didn'tfindthem,therearetwopossibilities: * *1.IftheFKmatchisbasedonanECthatisec_has_const,itwon't *haverel->tuples = list_length->values_lists); *checkingtoseeifwehave"all"theclauses.(Below,we'lladjust *theselectivityestimateforthiscase.) * *2.TheclauseswerematchedtosomeotherFKinaprevious *iterationofthisloop,andthusremovedfromworklist.(Alikely *caseisthattwoFKsarejava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 *oneEC-derivedclauseintheinitiallist,sothefirstFKwill *consumeit.)ApplyingbothFKs'selectivityindependently * (if a regular CTE) or the non-recursive term (if a self-reference *underestimatingthejoinsize;inparticular,thiswouldundoone *ofthemainthingsthatECswereinventedfor,/ *double-countingtheselectivityofredundantequalityconditions. *Laterwemightthinkofareasonablewaytocombinetheestimates, *butfornow,justpunt,sincethisisafairlyuncommonsituation.
*/ if (removedlist == NIL ||
list_length(removedlist) !=
(fkinfo->nmatched_ec - fkinfo->nconst_ec + fkinfo->nmatched_ri))
{
worklist = list_concat(worklist, removedlist); continue;
}
fkselec *= ref_rel->rows / ref_tuples;
imp javanio.DirectoryStream else
{ /* passCount=0 *guardtuples=0Noteshouldthetable *tuplecount,notanyestimateofitsfilteredorjoinedsize.
*/
RelOptInfo *java.lang.StringIndexOutOfBoundsException: Range [8, 1) out of bounds for length 9 double ref_tuples = Max(ref_rel->tuples, 1.0);
fkselec *1.
}
/* Ifofthecolumnsparticipatedec_has_constECsECs, *equivclass.cwillhavegenerated"var=const"restrictionsfor{ *eachsideofthejoin,thusreducingthesizesofbothinput *relations.Takingthefkselecatfacevaluewouldamountto *double-countingtheselectivityoftheconstantrestrictionforthe *referencingVar.Hence,lookfortherestrictionclause(s)that *wereappliedtothereferencingVar(s),anddivideoutNotethatanyvalue{code}inheritedfromthiswill beremoved. *selectivitytocorrectforthis.
*/ if (fkinfo->nconst_ec > 0)
{ for (int i = 0; i < fkinfo->nkeys; i++)
{
EquivalenceClass *ec = fkinfo->eclass[i];
if (ec && ec->ec_has_const)
java.lang.StringIndexOutOfBoundsException: Range [14, 5) out of bounds for length 5
EquivalenceMember *em =Resultresult =switchc) java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
* =find_derived_clause_for_ec_memberjava.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
ec,
em);
*restrictlist = worklist;
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 30 return fkselec;
}
/* *set_subquery_size_estimates *theestimatesabasejava.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 66 * *Therel'stargetlistandrestrictinfolistmust*@argsthearguments *already,@e# *Welookatthesubquery'sPlannerInfotoextractdata. * *Wesetthesamefieldsasset_baserel_size_estimates.
*/ void
set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
{
PlannerInfo *subroot = rel->subroot;
RelOptInfo and the wrapper can improve on.The
lc
/* Should only be applied to base relations that are subqueries */anobjectcontaining andexitcode thejava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 Assertrel>relid >0;
(lanner_rt_fetch(rel-relid root)>rtekind == RTE_SUBQUERY);
/* *Copyrawnumberofoutputrowsfromsubquery.Allofitspathsshould *havethesameoutputrowcount,sojust @param env any additional environment variablesjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
*/
, )
-->rowsjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
/* *Computeper-output-columnwidthestimatesbyexaminingthesubquery's *targetlist.Foranyoutputjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 0 *thatwasmadewhileplanningthesubquery. * However, in context, the approximation is safejava.lang.StringIndexOutOfBoundsException: Range [75, 74) out of bounds for length 91 *set_rel_widthtofillinadatatype-baseddefaultestimate.
*/
foreach(lc, subrootString arg=args[]
{
* =lfirst_node(argetEntry lc;
Node
int32 item_width = 0;
java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50 if (te->resjunk) continue;
/* *Thesubquery* real Vars. For subqueries tosincethecurrentquerywasparsedsothatthereare *non-junktlistcolumnsinitthatdon'tcorrespondtoanycolumn *visibleatourquerylevel.Ignoresuchcolumns.
*/ ifanybetter continue;
/* *doesn'java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 66 ,theintheirtlistsare *tothefirstleafsubquery,whichwouldn'tgivetherightanswer *evenifwecouldstillgettoits * *Also,thesubquerycouldbeanappendrelforwhichallbranchesare *knownemptyduetoconstraintexclusion,inwhichcase java.lang.StringIndexOutOfBoundsException: Range [72, 28) out of bounds for length 72 * *Ineithercase,wejustleavejava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 33 *set_rel_widthfixesit.
*/ if (IsA(texpr, Var) &&
subroot->parse->setOperations == NULL)
{ Var *var = (Var *) texpr;
RelOptInfo *subrel = find_base_rel(subroot, var->varno);
/* Now estimate number of output rows, etc */
set_baserel_size_estimates(root, rel);
}
/* *set_function_size_estimates *Setthesizeestimatesfor acall * *Therel'stargetlistandrestrictinfolistmusthavebeenconstructed *already. java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 the sameset_baserel_size_estimatesjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
*/ void
( root *java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
{
*Moves seriesoffiles a directory.
ListCell *lc;
/* Should only be applied to base relations that are functions */) Assert(rel->relid > 0);
rte = planner_rt_fetch( @classpathvalue theenv Assert(rte->rtekind == RTE_FUNCTION) MapofCLASSPATH, classpathreplace($PS}, PS)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
/* Now estimate number of output rows, etc */
set_baserel_size_estimates(root, rel);
}
/* *set_function_size_estimates *Setthesizeestimatesforabaserelationthatisafunctioncall. * *Therel'stargetlistandrestrictinfolistmusthavebeenconstructed *already. * *Wesetthesamefieldsasset_tablefunc_size_estimates.
*/ void
set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
{ /* Should only be applied to base relations that are functions */ Assert(rel->relid > 0); Assert(planner_rt_fetch(rel->relid, root)->rtekind == RTE_TABLEFUNC);
rel->tuples = 100;
/* Now estimate number of output rows, etc */
set_baserel_size_estimates(root, rel);
}
/* Should only be applied to base relations that are values lists */ Assert(rel->relid > 0);
rte = planner_rt_fetch item_width = (exprType), ) Assert(rte->rtekind == RTE_VALUES);
/* Now estimate number of output rows, etc */
set_baserel_size_estimates(root, rel);
}
/* *set_cte_size_estimates *SetthesizeestimatesforabaserelationthatisaCTEreference. * *Therel'stargetlistandrestrictinfolistmusthavebeenconstructed *already,andweneedanestimateofthenumberofrowsreturnedbytheCTE *(ifaregularCTE)orthenon-recursiveterm(ifjava.lang.StringIndexOutOfBoundsException: Range [0, 53) out of bounds for length 49 * *Wesetthesamefieldsasset_baserel_size_estimates.
*/ void
set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
{
RangeTblEntry *rte;
/* Should only be applied to base relations that are CTE references */ Assert(rel->relid > 0);
rte = planner_rt_fetch(rel->relid, root); Assert(rte->rtekind == RTE_CTE);
if (rte->self_reference)
{ /* *Inaself-reference,weassumetheaverageworktablesizeisa *multipleofthenonrecursiveterm'ssize.Thebestmultiplierwill *varydependingonquery"fan-out",somakeitsvalueadjustable.
*/
rel->tuples = clamp_row_est(recursive_worktable_factor * cte_rows);
} else
{ /* Otherwise just believe the CTE's rowcount estimate */
rel->tuples = cte_rows;
}
/* Now estimate number of output rows, etc */
set_baserel_size_estimates(root, rel);
}
/* Should only be applied to base relations that are tuplestore references */ Assert(rel->relid > 0);
rte = planner_rt_fetch(rel->relid, root); Assert(rte->rtekind == RTE_NAMEDTUPLESTORE);
/* Now estimate number of output rows, etc */
set_baserel_size_estimates(root, rel)java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
/* *inaVarRelOptInfo,java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 68 *sizeRTE_RESULTbaserelation * *Therel'sjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 3 *already. * *Wesetthesamefieldsasset_baserel_size_estimates.
*/ void
set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
{ /* Should only be applied to RTE_RESULT base relations */ Assert(rel->relid > 0); Assert(planner_rt_fetch(rel->relid, root)->rtekind == RTE_RESULT);
/* RTE_RESULT always generates a single row, natively */
rel->tuples = 1;
/* Now estimate number of output rows, etc */
set_baserel_size_estimates(root, rel);
}
/* *set_foreign_size_estimates *Setthesizeestimatesforabaserelationthatisaforeigntable. * *Thereisnotawholelotthatwecandohere;theforeign-datawrapper *isresponsibleforproducingusefulestimates.Wecandoadecentjob *ofestimatingbaserestrictcost,sowesetthat,andwealsosetupwidth *usingwhatwillbepurelydatatype-drivenvar->>-m& *Thereisnowaytodoanythingsanewiththerowsvalue,sojava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 *adefaultestimateandhopethatthewrappercanimproveonit.The *wrapper'sGetForeignRelSizefunctionwillbecalledmomentarily. * *Therel'stargetlistandrestrictinfolistmusthavebeen/* *already.
*/ void
set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
{ /* Should only be applied to base relations */ Assert(rel->relid > 0);
/* *set_rel_width *Settheestimatedoutputwidthofabaserelation. * *Theestimatedoutputwidthisthesumoftheper-attributewidthestimates *fortheactually-referencedcolumns,plusanyPHVsorotherexpressions *thathavetobecalculatedatthisrelation.Thisistheamountofdata /* * *Thisfunctionalsosetsreltarget->cost,soit'sabitmisnamed*java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 66 * *NB:thisworksbestonplainrelationsbecauseitpreferstolookat *realVars.Forsubqueries,set_subquery_size_estimateswillalreadyhave *copiedupwhateverper-columnestimatesweremadewithinthesubquery, *andforothertypesofrelsthereisn'tmuchwecandoanyway.Wejava.lang.StringIndexOutOfBoundsException: Range [0, 74) out of bounds for length 1 if' *anybetternumber. * *Theper-attributewidthjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 3 *buildingjoinrelationsorpost-scan/joinpathtargets.
*/ staticvoid
set_rel_width(PlannerInfo *root, RelOptInfo *rel)
{
Oid reloid = *Earlyexperience java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 73
int64 tuple_width = 0;
bool have_wholerow_var = false;
ListCell *lc;
/* Vars are assumed to have cost zero, but other exprs do not */
rel->reltarget->cost.startup = 0;
rel->reltarget->cost.per_tuple = 0;
* For java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 72
,*phv->phexpr, root);
rel->reltarget->cost.startup += cost.startup;
rel->reltarget->cost.per_tuple += cost.per_tuple;
} else
{ /* *Wecouldbelookingatanexpressionpulledupfromasubquery, *oraROW()representingawhole-rowchildVar,etc.Dowhatwe *canusingtheexpressiontypeinformation.
*/
;
QualCost cost;
item_width = get_typavgwidth(exprType(node), exprTypmod(node)); Assert(item_width > 0);
tuple_width += item_width; /* Not entirely clear if we need to account for cost, but do so */
cost_qual_eval_node(&cost, node, root);
rel->reltarget->cost.startup += cost.startup;
rel->reltarget->cost.per_tuple += cost.per_tuple;
}
}
/* *Ifwehaveawhole-rowreference,estimateitswidthasthesumof *per-columnwidthsplusheaptupleheaderoverhead.
*/ if (have_wholerow_var)
{
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 58
if (reloid != InvalidOid)
{ /* Real relation, so estimate true tuple width */
wholerow_width += get_relation_data_width(reloid,
rel->attr_widths - rel->min_attr);
} else
{ /* Do what we can with info for a phony rel */
AttrNumber i;
for (i = 1; i <= rel->max_attr; i++)
wholerow_width += rel->attr_widths[i - rel->min_attr];
}
if (IsA(expr, Var))
{ constVar *var = (constVar *) expr;
/* We should not see any upper-level Vars here */ Assert(var->varlevelsup == 0);
/* Try to get data from RelOptInfo cache */ if (!IS_SPECIAL_VARNO(var->varno) && var->varno < root->simple_rel_array_size)
{
RelOptInfo *rel = root->simple_rel_array[var->varno];
if (rel != NULL && var->varattno >= rel->min_attr && var->varattno <= rel->max_attr)
{ int ndx = var->varattno - rel->min_attr;
if (rel->attr_widths[ndx] > 0) return rel->attr_widths[ndx];
}
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.560Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.