Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Yugo NAGATA <nagata@sraoss.co.jp>
Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>,
pgsql-hackers@postgresql.org,
"David G. Johnston" <david.g.johnston@gmail.com>,
Bruce Momjian <bruce@momjian.us>
Date: 2022-11-10T20:33:37Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- account-for-pipeline-in-PreventInTransactionBlock-1.patch (text/x-diff) patch
Yugo NAGATA <nagata@sraoss.co.jp> writes: > Tom Lane <tgl@sss.pgh.pa.us> wrote: >> Hmm. Maybe the right way to think about this is "if we have completed an >> EXECUTE, and not yet received a following SYNC, then report that we are in >> a transaction block"? But I'm not sure if that breaks any other cases. > Or, in that case, regarding it as an implicit transaction if multiple commands > are executed in a pipeline as proposed in [1] could be another solution, > although I have once withdrawn this for not breaking backward compatibility. I didn't like that patch then and I still don't. In particular, it's mighty weird to be issuing BeginImplicitTransactionBlock after we've already completed one command of the pipeline. If that works without obvious warts, it's only accidental. Attached is a draft patch along the lines I speculated about above. It breaks backwards compatibility in that PreventInTransactionBlock commands will now be rejected if they're a non-first command in a pipeline. I think that's okay, and arguably desirable, for HEAD but I'm pretty uncomfortable about back-patching it. I thought of a variant idea that I think would significantly reduce the risk of breaking working applications, which is to restrict things only in the case of pipelines with previous data-modifying commands. I tried to implement that by having PreventInTransactionBlock test if (GetTopTransactionIdIfAny() != InvalidTransactionId) but it blew up, because we have various (mostly partitioning-related) DDL commands that run PreventInTransactionBlock only after they've acquired an exclusive lock on something, and LogAccessExclusiveLock gets an XID. (That was always a horrid POLA-violating kluge that would bite us on the rear someday, and now it has. But I can't see trying to change that in back branches.) Something could still be salvaged of the idea, perhaps: we could adjust this patch so that the tests are like if ((MyXactFlags & XACT_FLAGS_PIPELINING) && GetTopTransactionIdIfAny() != InvalidTransactionId) Maybe that makes it a small enough hazard to be back-patchable. Another objection that could be raised is the same one I made already, that !IsInTransactionBlock() doesn't provide the same guarantee as PreventInTransactionBlock. I'm not too happy about that either, but given that we know of no other uses of IsInTransactionBlock besides ANALYZE, maybe it's okay. I'm not sure it's worth trying to avoid it anyway --- we'd just end up with a probably-dead backwards compatibility stub. regards, tom lane
Commits
-
Rethink handling of [Prevent|Is]InTransactionBlock in pipeline mode.
- f48aa5df4e03 11.19 landed
- ae47f8a9664a 14.7 landed
- 942cc240f959 13.10 landed
- 1cca4a75ffb8 12.14 landed
- 18431ee6f511 15.2 landed
- 20432f873140 16.0 landed
-
Doc: add comments about PreventInTransactionBlock/IsInTransactionBlock.
- fec80da849f3 11.19 landed
- e70cd16f2223 15.2 landed
- e613ace1f0d5 16.0 landed
- 8befa05d7889 14.7 landed
- 1949135e79e8 13.10 landed
- 17e9ecac0118 12.14 landed
-
Force immediate commit after CREATE DATABASE etc in extended protocol.
- f92944137cde 16.0 landed
- a0c632c1dea7 15.0 landed
- 9e3e1ac458ab 11.17 landed
- 968b89257b11 12.12 landed
- 964f42aa297b 10.22 landed
- 6c193c2ace32 13.8 landed
- 3e1297a63f76 14.5 landed