diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-10-01 19:30:38 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-10-01 19:30:38 -0400 |
commit | 477023e9420c6bf72cd21ff9a415b568700de8e3 (patch) | |
tree | f02ed963eade881561970fe3273376f2a8dbf5aa /src/backend | |
parent | d1844c21b0991bcc0824a411378b70e14ee531a4 (diff) | |
download | postgresql-477023e9420c6bf72cd21ff9a415b568700de8e3.tar.gz postgresql-477023e9420c6bf72cd21ff9a415b568700de8e3.zip |
Fix some more problems with nested append relations.
As of commit a87c72915 (which later got backpatched as far as 9.1),
we're explicitly supporting the notion that append relations can be
nested; this can occur when UNION ALL constructs are nested, or when
a UNION ALL contains a table with inheritance children.
Bug #11457 from Nelson Page, as well as an earlier report from Elvis
Pranskevichus, showed that there were still nasty bugs associated with such
cases: in particular the EquivalenceClass mechanism could try to generate
"join" clauses connecting an appendrel child to some grandparent appendrel,
which would result in assertion failures or bogus plans.
Upon investigation I concluded that all current callers of
find_childrel_appendrelinfo() need to be fixed to explicitly consider
multiple levels of parent appendrels. The most complex fix was in
processing of "broken" EquivalenceClasses, which are ECs for which we have
been unable to generate all the derived equality clauses we would like to
because of missing cross-type equality operators in the underlying btree
operator family. That code path is more or less entirely untested by
the regression tests to date, because no standard opfamilies have such
holes in them. So I wrote a new regression test script to try to exercise
it a bit, which turned out to be quite a worthwhile activity as it exposed
existing bugs in all supported branches.
The present patch is essentially the same as far back as 9.2, which is
where parameterized paths were introduced. In 9.0 and 9.1, we only need
to back-patch a small fragment of commit 5b7b5518d, which fixes failure to
propagate out the original WHERE clauses when a broken EC contains constant
members. (The regression test case results show that these older branches
are noticeably stupider than 9.2+ in terms of the quality of the plans
generated; but we don't really care about plan quality in such cases,
only that the plan not be outright wrong. A more invasive fix in the
older branches would not be a good idea anyway from a plan-stability
standpoint.)
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/optimizer/path/equivclass.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c index d89feb34b32..e0bdbe87a7f 100644 --- a/src/backend/optimizer/path/equivclass.c +++ b/src/backend/optimizer/path/equivclass.c @@ -902,7 +902,12 @@ generate_base_implied_equalities_no_const(PlannerInfo *root, * of the EC back into the main restrictinfo datastructures. Multi-relation * clauses will be regurgitated later by generate_join_implied_equalities(). * (We do it this way to maintain continuity with the case that ec_broken - * becomes set only after we've gone up a join level or two.) + * becomes set only after we've gone up a join level or two.) However, for + * an EC that contains constants, we can adopt a simpler strategy and just + * throw back all the source RestrictInfos immediately; that works because + * we know that such an EC can't become broken later. (This rule justifies + * ignoring ec_has_const ECs in generate_join_implied_equalities, even when + * they are broken.) */ static void generate_base_implied_equalities_broken(PlannerInfo *root, @@ -914,7 +919,8 @@ generate_base_implied_equalities_broken(PlannerInfo *root, { RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(lc); - if (bms_membership(restrictinfo->required_relids) != BMS_MULTIPLE) + if (ec->ec_has_const || + bms_membership(restrictinfo->required_relids) != BMS_MULTIPLE) distribute_restrictinfo_to_rels(root, restrictinfo); } } |