Re: [HACKERS] <> join selectivity estimate question - Mailing list pgsql-hackers

From Dilip Kumar
Subject Re: [HACKERS] <> join selectivity estimate question
Date
Msg-id CAFiTN-uLYwPAeEnm3-jbJ4dunKuQtjE5n=Wf_8b+OJ-i1BjMbA@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] <> join selectivity estimate question  (Thomas Munro <thomas.munro@enterprisedb.com>)
Responses Re: [HACKERS] <> join selectivity estimate question  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On Fri, Mar 17, 2017 at 6:49 PM, Thomas Munro
<thomas.munro@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



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] TAP backpatching policy
Next
From: Dilip Kumar
Date:
Subject: Re: [HACKERS] POC: Sharing record typmods between backends