I wrote: > ... Here is a sketch of what I think is a better way: > ... > It's possible that we could reduce the cost of matching non-EC join > quals as well, with some trick along the line of pre-matching non-EC > RestrictInfos to FK items. I'm unsure that that is worth the trouble > though.
After further thought, I believe that may well be worth doing. That is, someplace after deconstruct_jointree(), examine all the FKs and match their columns not only to ECs but to non-EC joinclauses, which we could find by trawling the joininfo list for either subject relation. We'd end up with a EC pointer and/or a list of non-EC RestrictInfos for each FK column. The thing that makes this attractive is that at the end of this matching, we would know exactly whether each FK is matched to the query as a whole: either all its columns have matches, or they don't. It's not necessary to re-determine that for each joinrel pair that includes the FK's two subject relations. So the per-join-relation work would reduce to scanning the FK list once to find the matched FK(s) that connect relations on opposite sides of the join. Once we've found such an FK, identifying which join qual list items should be dropped in favor of applying the FK's selectivity is also really easy: we just check the column markings. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers