Re: MERGE ... WHEN NOT MATCHED BY SOURCE

Dean Rasheed <dean.a.rasheed@gmail.com>

From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-01-07T12:54:50Z
Lists: pgsql-hackers

Attachments

On Thu, 5 Jan 2023 at 13:21, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
>
> On Thu, 5 Jan 2023 at 11:03, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
> >
> > > +     /* Join type required */
> > > +     if (left_join && right_join)
> > > +             qry->mergeJoinType = JOIN_FULL;
> > > +     else if (left_join)
> > > +             qry->mergeJoinType = JOIN_LEFT;
> > > +     else if (right_join)
> > > +             qry->mergeJoinType = JOIN_RIGHT;
> > > +     else
> > > +             qry->mergeJoinType = JOIN_INNER;
> >
> > One of the review comments that MERGE got initially was that parse
> > analysis was not a place to "do query optimization", in the sense that
> > the original code was making a decision whether to make an outer or
> > inner join based on the set of WHEN clauses that appear in the command.
> > That's how we ended up with transform_MERGE_to_join and
> > mergeUseOuterJoin instead.  This new code is certainly not the same, but
> > it makes me a bit unconfortable.  Maybe it's OK, though.
> >
>
> Yeah I agree, it's a bit ugly. Perhaps a better solution would be to
> do away with that field entirely and just make the decision in
> transform_MERGE_to_join() by examining the action list again.
>

Attached is an updated patch taking that approach, allowing
mergeUseOuterJoin to be removed from the Query node, which I think is
probably a good thing.

Aside from that, it includes a few additional comment updates in the
executor that I'd missed, and psql tab completion support.

Regards,
Dean

Commits

  1. Add support for MERGE ... WHEN NOT MATCHED BY SOURCE.

  2. Reindex toast before its main relation in reindex_relation()