From: Bruce Momjian <bruce@momjian.us>
To: Dave Cramer <davecramer@postgres.rocks>
Cc: Glen Huang <heyhgl@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Is replacing transactions with CTE a good idea?
Date: Mon, 5 Apr 2021 14:18:21 -0400
Message-ID: <20210405181821.GA12174@momjian.us> (raw)
In-Reply-To: <CADK3HHKiQRpzhM70PE0BbCj9Xjoa8B4qkVfQo8G5oUNkwK2sHA@mail.gmail.com>
References: <CADK3HHLzbbn0EQg_rgL8iiro-LZT6fG7rHdp_WW5uB36aJKspQ@mail.gmail.com>
<7CFF1F8C-E83D-4A68-AD89-6DD3FE2E2493@gmail.com>
<CADK3HHJ5m_dJsSsW8sLK+M9RfVWV0x42o0r8E4H1O4PtmBemiQ@mail.gmail.com>
<20210401193929.GA18029@momjian.us>
<CADK3HHKcZ09TLNNUvcm_++NwDQeHR=J=Qx=oZwayP5e0ZDweTw@mail.gmail.com>
<20210404131231.GA1730@momjian.us>
<CADK3HHKiQRpzhM70PE0BbCj9Xjoa8B4qkVfQo8G5oUNkwK2sHA@mail.gmail.com>
On Sun, Apr 4, 2021 at 10:02:20AM -0400, Dave Cramer wrote:
> On Sun, 4 Apr 2021 at 09:12, Bruce Momjian <bruce@momjian.us> wrote:
> > OK, that makes sense, but I think it is wrong minded to think that this
> > absolves one of taking isolation into account.
> >
> > When you make the first read you will still have to deal with all of the
> > isolation issues
>
> I have no idea what you are saying above. Why is a SELECT-only CTE not
> the same as a repeatable-read SELECT-only multi-statement transaction?
> Are you saying that a SELECT in a CTE doesn't do SELECT FOR UPDATE?
>
>
> No, but where is this documented ?
Well, every query runs with a single snapshot, even WITH queries. We do
document how non-SELECT WITH visibility is handled:
https://www.postgresql.org/docs/13/sql-select.html
The primary query and the WITH queries are all (notionally) executed at
the same time. This implies that the effects of a data-modifying
statement in WITH cannot be seen from other parts of the query, other
than by reading its RETURNING output. If two such data-modifying
statements attempt to modify the same row, the results are unspecified.
A key property of WITH queries is that they are normally evaluated only
once per execution of the primary query, even if the primary query
refers to them more than once. In particular, data-modifying statements
are guaranteed to be executed once and only once, regardless of whether
the primary query reads all or any of their output.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: bruce@momjian.us, davecramer@postgres.rocks, heyhgl@gmail.com
Subject: Re: Is replacing transactions with CTE a good idea?
In-Reply-To: <20210405181821.GA12174@momjian.us>
References: <CADK3HHLzbbn0EQg_rgL8iiro-LZT6fG7rHdp_WW5uB36aJKspQ@mail.gmail.com> <7CFF1F8C-E83D-4A68-AD89-6DD3FE2E2493@gmail.com> <CADK3HHJ5m_dJsSsW8sLK+M9RfVWV0x42o0r8E4H1O4PtmBemiQ@mail.gmail.com> <20210401193929.GA18029@momjian.us> <CADK3HHKcZ09TLNNUvcm_++NwDQeHR=J=Qx=oZwayP5e0ZDweTw@mail.gmail.com> <20210404131231.GA1730@momjian.us> <CADK3HHKiQRpzhM70PE0BbCj9Xjoa8B4qkVfQo8G5oUNkwK2sHA@mail.gmail.com> <20210405181821.GA12174@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox