Re: BUG #18103: bugs of concurrent merge into when use different join plan

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, luajk(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Subject: Re: BUG #18103: bugs of concurrent merge into when use different join plan
Date: 2023-09-26 09:46:11
Message-ID: CAMbWs491AfSCzUh1oUPFt=PD4hkoCmhwLYKU=BDhTUv0jQyB_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Sep 21, 2023 at 7:49 PM Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
wrote:

> I don't feel that I have a good understanding of the EPQ mechanism,
> but src/backend/executor/README says:
>
> """
> It is also possible that there are relations in the query that are not
> to be locked (they are neither the UPDATE/DELETE target nor specified to
> be locked in SELECT FOR UPDATE/SHARE). When re-running the test query
> we want to use the same rows from these relations that were joined to
> the locked rows. For ordinary relations this can be implemented relatively
> cheaply by including the row TID in the join outputs and re-fetching that
> TID. (The re-fetch is expensive, but we're trying to optimize the normal
> case where no re-test is needed.) We have also to consider non-table
> relations, such as a ValuesScan or FunctionScan. For these, since there
> is no equivalent of TID, the only practical solution seems to be to include
> the entire row value in the join output row.
> """
>
> and this is not happening for MERGE.
>

On the face of it, that looks like a simple oversight in
> preprocess_rowmarks(), and changing it, as in the attached, fixes the
> reported issue.

Agreed. We need rowmarks for MERGE too. I found that the following
comment from plannodes.h is very useful in understanding this.

* When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely
* identify all the source rows, not only those from the target relations, so
* that we can perform EvalPlanQual rechecking at need.

To nitpick, there are some comments that may need to be updated to
include MERGE, such as the comments for ExecRowMark, RowMarkType and
PlanRowMark.

Thanks
Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Sorin Mircioiu 2023-09-26 10:23:48 PostgreSQL's processes blocking each other are not detected as deadlock
Previous Message Alexander Lakhin 2023-09-26 08:08:08 Re: BUG #18129: GiST index produces incorrect query results