postgresql/src/backend/optimizer/path
Tom Lane a5fc46414d Avoid making commutatively-duplicate clauses in EquivalenceClasses.
When we decide we need to make a derived clause equating a.x and
b.y, we already will re-use a previously-made clause "a.x = b.y".
But we might instead have "b.y = a.x", which is perfectly usable
because equivclass.c has never promised anything about the
operand order in clauses it builds.  Saving construction of a
new RestrictInfo doesn't matter all that much in itself --- but
because we cache selectivity estimates and so on per-RestrictInfo,
there's a possibility of saving a fair amount of duplicative
effort downstream.

Hence, check for commutative matches as well as direct ones when
seeing if we have a pre-existing clause.  This changes the visible
clause order in several regression test cases, but they're all
clearly-insignificant changes.

Checking for the reverse operand order is simple enough, but
if we wanted to check for operator OID match we'd need to call
get_commutator here, which is not so cheap.  I concluded that
we don't really need the operator check anyway, so I just
removed it.  It's unlikely that an opfamily contains more than
one applicable operator for a given pair of operand datatypes;
and if it does they had better give the same answers, so there
seems little need to insist that we use exactly the one
select_equality_operator chose.

Using the current core regression suite as a test case, I see
this change reducing the number of new join clauses built by
create_join_clause from 9673 to 5142 (out of 26652 calls).
So not quite 50% savings, but pretty close to it.

Discussion: https://postgr.es/m/78062.1666735746@sss.pgh.pa.us
2022-10-27 14:42:18 -04:00
..
allpaths.c Fix confusion about havingQual vs hasHavingQual in planner. 2022-10-18 10:44:34 -04:00
clausesel.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
costsize.c Rename shadowed local variables 2022-10-05 21:01:41 +13:00
equivclass.c Avoid making commutatively-duplicate clauses in EquivalenceClasses. 2022-10-27 14:42:18 -04:00
indxpath.c Update some comments that should've covered MERGE 2022-10-24 12:52:43 +02:00
joinpath.c Fix incorrect row estimates used for Memoize costing 2022-05-16 16:07:56 +12:00
joinrels.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
meson.build meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
pathkeys.c Revert "Optimize order of GROUP BY keys". 2022-10-03 10:56:16 -04:00
tidpath.c Rename shadowed local variables 2022-10-05 21:01:41 +13:00