GetTransactionSnapshot() in enum.c

Lists: pgsql-hackers
From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: GetTransactionSnapshot() in enum.c
Date: 2013-08-19 12:29:38
Message-ID: 20130819122938.GB8558@alap2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

ISTM that we shouldn't use GetTransactionSnapshot() in enum.c but
GetLatestSnapshot() in <= 9.3 and NULL/GetCatalogSnapshot() > 9.3.

typecache.c's usage was converted to GetLatestSnapshot() but enum.c's
was not.

I don't seem to have full mental capacity right now, but I think the
current usage could cause problems with a range type index over a enum
column. Index predicates might also be problematic.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: GetTransactionSnapshot() in enum.c
Date: 2013-08-19 17:41:37
Message-ID: 22342.1376934097@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> ISTM that we shouldn't use GetTransactionSnapshot() in enum.c but
> GetLatestSnapshot() in <= 9.3 and NULL/GetCatalogSnapshot() > 9.3.

> typecache.c's usage was converted to GetLatestSnapshot() but enum.c's
> was not.

That was intentional, see the comments for commit
9ad45c18b6c8d03ce18a26223eb0d15e900c7a2c.

Possibly we should rethink this in HEAD given that we don't do SnapshotNow
scans anymore, but I'm disinclined to do so in back branches.

BTW, I notice that the MVCC-catalog-scans patch summarily asserts that
RenumberEnumType no longer poses any concurrency hazards. I doubt that's
true: isn't it still possible that pg_enum rows acquired through the
syscaches will have inconsistent enumsortorder values, if they were
read at different times? If you want to examine enumsortorder, you really
need to be comparing rows you know were read with the *same* snapshot.

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: GetTransactionSnapshot() in enum.c
Date: 2013-08-26 18:14:01
Message-ID: CA+TgmobvTjRj_doXxQ0wgA1a1JLYPVYqtR3m+Cou_ousabnmXg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Aug 19, 2013 at 1:41 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
>> ISTM that we shouldn't use GetTransactionSnapshot() in enum.c but
>> GetLatestSnapshot() in <= 9.3 and NULL/GetCatalogSnapshot() > 9.3.
>
>> typecache.c's usage was converted to GetLatestSnapshot() but enum.c's
>> was not.
>
> That was intentional, see the comments for commit
> 9ad45c18b6c8d03ce18a26223eb0d15e900c7a2c.
>
> Possibly we should rethink this in HEAD given that we don't do SnapshotNow
> scans anymore, but I'm disinclined to do so in back branches.
>
> BTW, I notice that the MVCC-catalog-scans patch summarily asserts that
> RenumberEnumType no longer poses any concurrency hazards. I doubt that's
> true: isn't it still possible that pg_enum rows acquired through the
> syscaches will have inconsistent enumsortorder values, if they were
> read at different times? If you want to examine enumsortorder, you really
> need to be comparing rows you know were read with the *same* snapshot.

Good point, I missed that. Here's a proposed comment patch.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment Content-Type Size
pg_enum_now.patch application/octet-stream 1.4 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: GetTransactionSnapshot() in enum.c
Date: 2013-08-26 20:31:21
Message-ID: 15314.1377549081@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Mon, Aug 19, 2013 at 1:41 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> BTW, I notice that the MVCC-catalog-scans patch summarily asserts that
>> RenumberEnumType no longer poses any concurrency hazards. I doubt that's
>> true: isn't it still possible that pg_enum rows acquired through the
>> syscaches will have inconsistent enumsortorder values, if they were
>> read at different times? If you want to examine enumsortorder, you really
>> need to be comparing rows you know were read with the *same* snapshot.

> Good point, I missed that. Here's a proposed comment patch.

Looks sane to me.

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: GetTransactionSnapshot() in enum.c
Date: 2013-08-28 17:24:52
Message-ID: CA+Tgmobzt30UE6uM4bO4=A-R9yJwW8tj7QiSwPEKVoLhquTn9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Aug 26, 2013 at 4:31 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Mon, Aug 19, 2013 at 1:41 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> BTW, I notice that the MVCC-catalog-scans patch summarily asserts that
>>> RenumberEnumType no longer poses any concurrency hazards. I doubt that's
>>> true: isn't it still possible that pg_enum rows acquired through the
>>> syscaches will have inconsistent enumsortorder values, if they were
>>> read at different times? If you want to examine enumsortorder, you really
>>> need to be comparing rows you know were read with the *same* snapshot.
>
>> Good point, I missed that. Here's a proposed comment patch.
>
> Looks sane to me.

Thanks for the review. Committed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company