Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7706710

Browse files
committed
Don't make FK-based selectivity estimates in inheritance situations.
The foreign-key-aware logic for estimation of join sizes (added in commit100340e) blindly tried to apply the concept to rels that are actuallyparents of inheritance trees. This is just plain wrong so far as thereferenced relation is concerned, since the inheritance scan may wellproduce lots of rows that are not participating in the constraint. It'swrong for the referencing relation too, for the same reason; although onthat end we could conceivably detect whether all members of the inheritancetree have equivalent FK constraints pointing to the same referenced rel,and then proceed more or less as we do now. But pending somebody writingcode to do that, we must disable this, because it's producing completelysilly estimates when there's an FK linking the heads of inheritance trees.Per bug #14404 from Clinton Adams. Back-patch to 9.6 where the newestimation logic came in.Report: <20161028200412.15987.96482@wrigleys.postgresql.org>
1 parentda8f3eb commit7706710

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

‎src/backend/optimizer/util/plancat.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ get_relation_info_hook_type get_relation_info_hook = NULL;
5353

5454

5555
staticvoidget_relation_foreign_keys(PlannerInfo*root,RelOptInfo*rel,
56-
Relationrelation);
56+
Relationrelation,boolinhparent);
5757
staticboolinfer_collation_opclass_match(InferenceElem*elem,RelationidxRel,
5858
List*idxExprs);
5959
staticint32get_rel_data_width(Relationrel,int32*attr_widths);
@@ -408,7 +408,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
408408
}
409409

410410
/* Collect info about relation's foreign keys, if relevant */
411-
get_relation_foreign_keys(root,rel,relation);
411+
get_relation_foreign_keys(root,rel,relation,inhparent);
412412

413413
heap_close(relation,NoLock);
414414

@@ -433,7 +433,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
433433
*/
434434
staticvoid
435435
get_relation_foreign_keys(PlannerInfo*root,RelOptInfo*rel,
436-
Relationrelation)
436+
Relationrelation,boolinhparent)
437437
{
438438
List*rtable=root->parse->rtable;
439439
List*cachedfkeys;
@@ -448,6 +448,15 @@ get_relation_foreign_keys(PlannerInfo *root, RelOptInfo *rel,
448448
list_length(rtable)<2)
449449
return;
450450

451+
/*
452+
* If it's the parent of an inheritance tree, ignore its FKs. We could
453+
* make useful FK-based deductions if we found that all members of the
454+
* inheritance tree have equivalent FK constraints, but detecting that
455+
* would require code that hasn't been written.
456+
*/
457+
if (inhparent)
458+
return;
459+
451460
/*
452461
* Extract data about relation's FKs from the relcache. Note that this
453462
* list belongs to the relcache and might disappear in a cache flush, so
@@ -488,6 +497,9 @@ get_relation_foreign_keys(PlannerInfo *root, RelOptInfo *rel,
488497
if (rte->rtekind!=RTE_RELATION||
489498
rte->relid!=cachedfk->confrelid)
490499
continue;
500+
/* Ignore if it's an inheritance parent; doesn't really match */
501+
if (rte->inh)
502+
continue;
491503
/* Ignore self-referential FKs; we only care about joins */
492504
if (rti==rel->relid)
493505
continue;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp