]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix FK-based join selectivity estimation for semi/antijoins.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 17 Dec 2016 20:28:54 +0000 (15:28 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 17 Dec 2016 20:28:54 +0000 (15:28 -0500)
commitf4f195d15c7cefb0d6435028c23b523d671c1ec7
tree5ce5fba3041916baef9ee333b0f3e0ce8fd91620
parent6c75fb6b3dbeda4dac19cee8f2d5cc7f38f362ee
Fix FK-based join selectivity estimation for semi/antijoins.

This case wasn't thought through sufficiently in commit 100340e2d.
It's true that the FK proves that every outer row has a match in the
inner table, but we forgot that some of the inner rows might be filtered
away by WHERE conditions located within the semijoin's RHS.

If the RHS is just one table, we can reasonably take the semijoin
selectivity as equal to the fraction of the referenced table's rows
that are expected to survive its restriction clauses.

If the RHS is a join, it's not clear how much of the referenced table
might get through the join, so fall back to the same rule we were
already using for other outer-join cases: use the minimum of the
regular per-clause selectivity estimates.  This gives the same result
as if we hadn't considered the FK at all when there's a single FK
column, but it should still help for multi-column FKs, which is the
case that 100340e2d is really meant to help with.

Back-patch to 9.6 where the previous commit came in.

Discussion: https://postgr.es/m/16149.1481835103@sss.pgh.pa.us
src/backend/optimizer/path/costsize.c