On Fri, Mar 17, 2017 at 6:49 PM, Thomas Munro <thomas.mu...@enterprisedb.com> wrote: > Right. If I temporarily hack neqjoinsel() thus: > > result = 1.0 - result; > + > + if (jointype == JOIN_SEMI) > + result = 1.0; > + > PG_RETURN_FLOAT8(result); > }
I was looking into this problem. IMHO, the correct solution will be that for JOIN_SEMI, neqjoinsel should not estimate the equijoin selectivity using eqjoinsel_semi, instead, it should calculate the equijoin selectivity as inner join and it should get the selectivity of <> by (1-equijoin selectivity). Because for the inner_join we can claim that "selectivity of '=' + selectivity of '<>' = 1", but same is not true for the semi-join selectivity. For semi-join it is possible that selectivity of '=' and '<>' is both are 1. something like below ---------------------------- @@ -2659,7 +2659,13 @@ neqjoinsel(PG_FUNCTION_ARGS) SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) PG_GETARG_POINTER(4); Oid eqop; float8 result; + if (jointype = JOIN_SEMI) + { + sjinfo->jointype = JOIN_INNER; + } /* * We want 1 - eqjoinsel() where the equality operator is the one * associated with this != operator, that is, its negator. We may need something similar for anti-join as well. -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers