Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-04-09 Thread Andres Freund
Hi, On 2020-04-09 18:52:32 -0400, Tom Lane wrote: > Andres Freund writes: > > On 2020-04-09 16:56:03 -0400, Robert Haas wrote: > >> That seems like a fairly magical coding rule that will happen to work > >> in most practical cases but isn't really a principled approach to the > >> problem. > > >

Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-04-09 Thread Tom Lane
Andres Freund writes: > On 2020-04-09 16:56:03 -0400, Robert Haas wrote: >> That seems like a fairly magical coding rule that will happen to work >> in most practical cases but isn't really a principled approach to the >> problem. > I'm not sure it'd be that magical to only release resources at >

Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-04-09 Thread Andres Freund
Hi, On 2020-04-09 16:56:03 -0400, Robert Haas wrote: > [ belatedly responding ] > > On Sat, Feb 29, 2020 at 3:17 PM Andres Freund wrote: > > My preliminary conclusion is that it's simply not safe to do > > SnapshotResetXmin() from within InvalidateCatalogSnapshot(), > > PopActiveSnapshot(), Unre

Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-04-09 Thread Robert Haas
[ belatedly responding ] On Sat, Feb 29, 2020 at 3:17 PM Andres Freund wrote: > My preliminary conclusion is that it's simply not safe to do > SnapshotResetXmin() from within InvalidateCatalogSnapshot(), > PopActiveSnapshot(), UnregisterSnapshotFromOwner() etc. Instead we need > to defer the Snap

Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-04-07 Thread Andres Freund
Hi, Robert, Tom, it'd be great if you could look through this thread. I think there's a problem here (and it has gotten worse after the introduction of catalog snapshots). Both of you at least dabbled in related code. On 2020-02-29 12:17:07 -0800, Andres Freund wrote: > On 2020-02-28 22:10:52 -0

Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-03-28 Thread Andres Freund
Hi, On 2020-03-28 12:30:40 -0700, Andres Freund wrote: > On 2020-02-28 22:10:52 -0800, Andres Freund wrote: > > On 2020-02-28 21:24:59 -0800, Andres Freund wrote: > > So, um. What happens is that doDeletion() does a catalog scan, which > > sets a snapshot. The results of that catalog scan are then

Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-03-28 Thread Andres Freund
Hi, On 2020-02-28 22:10:52 -0800, Andres Freund wrote: > On 2020-02-28 21:24:59 -0800, Andres Freund wrote: > > Turns out that I am to blame for that. All the way back in 9.4. For > > logical decoding I needed to make ScanPgRelation() use a specific type > > of snapshot during one corner case of l

Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-02-29 Thread Andres Freund
Hi, On 2020-02-28 22:10:52 -0800, Andres Freund wrote: > So, um. What happens is that doDeletion() does a catalog scan, which > sets a snapshot. The results of that catalog scan are then used to > perform modifications. But at that point there's no guarantee that we > still hold *any* snapshot, as

Re: Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-02-28 Thread Andres Freund
Hi, On 2020-02-28 21:24:59 -0800, Andres Freund wrote: > Turns out that I am to blame for that. All the way back in 9.4. For > logical decoding I needed to make ScanPgRelation() use a specific type > of snapshot during one corner case of logical decoding. For reasons lost > to time, I didn't conti

Catalog invalidations vs catalog scans vs ScanPgRelation()

2020-02-28 Thread Andres Freund
Hi, While self reviewing a patch I'm about to send I changed the assertion in index_getnext_tid from Assert(TransactionIdIsValid(RecentGlobalXmin)) to instead test (via an indirection) Assert(TransactionIdIsValid(MyProc->xmin)) Without ->xmin being set, it's not safe to do scans. And checki