提交 fd9d8c2f 编写于 作者: D Daniel Gustafsson

Remove default statistics control in join planning

Commit e0409357 moved to using default estimates rather
than interrogating the QEs for relations which lack statistics.
As an effect of this, the cdb_default_stats_used member was
hardcoded to false and the warnings for missing statistics did
never fire.

Rather than resurrecting the warnings, this removes the code
that attempts to figure out if the warnings at all apply since
it seems quite expensive to run that in the hot path of every
join query being planned.

Discussion: https://github.com/greenplum-db/gpdb/pull/5216Reviewed-by: NVenkatesh Raghavan <vraghavan@pivotal.io>
上级 14cb1039
......@@ -672,7 +672,6 @@ _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
WRITE_BOOL_FIELD(hypothetical);
WRITE_BOOL_FIELD(amoptionalkey);
WRITE_BOOL_FIELD(cdb_default_stats_used);
}
/*****************************************************************************
......
......@@ -2338,7 +2338,6 @@ _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
WRITE_BOOL_FIELD(hypothetical);
WRITE_BOOL_FIELD(amoptionalkey);
WRITE_BOOL_FIELD(cdb_default_stats_used);
}
#endif /* COMPILING_BINARY_FUNCS */
......
......@@ -112,27 +112,6 @@ make_one_rel(PlannerInfo *root, List *joinlist)
*/
set_base_rel_pathlists(root);
/*
* CDB: If join, warn of any tables that need ANALYZE.
*/
if (has_multiple_baserels(root))
{
Index rti;
RelOptInfo *brel;
RangeTblEntry *brte;
for (rti = 1; rti < root->simple_rel_array_size; rti++)
{
brel = root->simple_rel_array[rti];
if (brel &&
brel->cdb_default_stats_used)
{
brte = rt_fetch(rti, root->parse->rtable);
cdb_default_stats_warning_for_table(brte->relid);
}
}
}
/*
* Generate access paths for the entire join tree.
*/
......
......@@ -65,11 +65,7 @@ cdb_estimate_rel_size(RelOptInfo *relOptInfo,
Relation rel,
int32 *attr_widths,
BlockNumber *pages,
double *tuples,
bool *default_stats_used);
static void
cdb_default_stats_warning_for_index(Oid reloid, Oid indexoid);
double *tuples);
static void get_external_relation_info(Relation relation, RelOptInfo *rel);
......@@ -155,9 +151,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
relation,
rel->attr_widths - rel->min_attr,
&rel->pages,
&rel->tuples,
&rel->cdb_default_stats_used
);
&rel->tuples);
}
/*
......@@ -176,10 +170,6 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
ListCell *l;
LOCKMODE lmode;
/* Warn if indexed table needs ANALYZE. */
if (rel->cdb_default_stats_used)
cdb_default_stats_warning_for_table(relation->rd_id);
indexoidlist = RelationGetIndexList(relation);
/*
......@@ -379,17 +369,12 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
indexRelation,
NULL,
&info->pages,
&info->tuples,
&info->cdb_default_stats_used);
&info->tuples);
if (!info->indpred ||
info->tuples > rel->tuples)
info->tuples = rel->tuples;
if (info->cdb_default_stats_used &&
!rel->cdb_default_stats_used)
cdb_default_stats_warning_for_index(relation->rd_id, indexoid);
index_close(indexRelation, needs_longlock ? NoLock : lmode);
indexinfos = lcons(info, indexinfos);
......@@ -442,16 +427,13 @@ cdb_estimate_rel_size(RelOptInfo *relOptInfo,
Relation rel,
int32 *attr_widths,
BlockNumber *pages,
double *tuples,
bool *default_stats_used)
double *tuples)
{
BlockNumber relpages;
double reltuples;
double density;
BlockNumber curpages = 0;
*default_stats_used = false;
/* Rel not distributed? RelationGetNumberOfBlocks can get actual #pages. */
if (!relOptInfo->cdbpolicy ||
relOptInfo->cdbpolicy->ptype == POLICYTYPE_ENTRY)
......@@ -1222,94 +1204,3 @@ has_unique_index(RelOptInfo *rel, AttrNumber attno)
}
return false;
}
/*
* cdb_default_stats_warning_needed
*/
static bool
cdb_default_stats_warning_needed(Oid reloid)
{
Relation relation;
bool warn = true;
/* Find relcache entry. */
relation = relation_open(reloid, NoLock);
/* Keep quiet if temporary or system table. */
if (relation->rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
IsSystemClass(relation->rd_rel))
warn = false;
/* Warn at most once during lifetime of relcache entry. */
else if (relation->rd_cdbDefaultStatsWarningIssued)
warn = false;
/* Caller will issue warning. Set flag so warning won't be repeated. */
else
relation->rd_cdbDefaultStatsWarningIssued = true;
/* Close rel. Don't disturb the lock. */
relation_close(relation, NoLock);
return warn;
} /* cdb_default_stats_warning_needed */
/*
* cdb_default_stats_warning_for_index
*/
void
cdb_default_stats_warning_for_index(Oid reloid, Oid indexoid)
{
char *relname;
char *indexname;
/* Warn at most once during lifetime of relcache entry. Skip if temp. */
if (!cdb_default_stats_warning_needed(indexoid))
return;
/* Get name from catalog, not from relcache, in case it has been renamed. */
relname = get_rel_name(reloid);
indexname = get_rel_name(indexoid);
ereport(NOTICE,
(errmsg("Query planner will use default statistics for index \"%s\" "
"on table \"%s\"",
indexname ? indexname : "??",
relname ? relname : "??"),
errhint("To cache a sample of the table's actual statistics for "
"optimization, use the ANALYZE or VACUUM ANALYZE command.")
));
if (relname)
pfree(relname);
if (indexname)
pfree(indexname);
} /* cdb_default_stats_warning_for_index */
/*
* cdb_default_stats_warning_for_table
*/
void
cdb_default_stats_warning_for_table(Oid reloid)
{
char *relname;
/* Warn at most once during lifetime of relcache entry. Skip if temp. */
if (!cdb_default_stats_warning_needed(reloid))
return;
/* Get name from catalog, not from relcache, in case name has changed. */
relname = get_rel_name(reloid);
ereport(NOTICE,
(errmsg("Query planner will use default statistics for table \"%s\"",
relname ? relname : "??"),
errhint("To cache a sample of the table's actual statistics for "
"optimization, use the ANALYZE or VACUUM ANALYZE command.")
));
if (relname)
pfree(relname);
} /* cdb_default_stats_warning_for_table */
......@@ -550,7 +550,6 @@ typedef struct RelOptInfo
double tuples;
struct GpPolicy *cdbpolicy; /* distribution of stored tuples */
char relstorage; /* from pg_class.relstorage */
bool cdb_default_stats_used; /* true if ANALYZE needed */
struct Plan *subplan; /* if subquery */
List *subrtable; /* if subquery */
List *subrowmark; /* if subquery */
......@@ -637,7 +636,6 @@ typedef struct IndexOptInfo
bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
bool amhasgettuple; /* does AM have amgettuple interface? */
bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
bool cdb_default_stats_used; /* true if ANALYZE needed */
int num_leading_eq; /* CDB: always 0, except amcostestimate proc may
* set it briefly; it is transferred forthwith
* to the IndexPath (q.v.), then reset. Kludge.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册