why does enum_endpoint call GetTransactionSnapshot()?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: why does enum_endpoint call GetTransactionSnapshot()?
Date: 2015-02-14 21:42:08
Message-ID: CA+TgmoZvyu-_McgPYiH=AjpPDCRfPRA9vrcKv_Z26Nqyk0UNiw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The comments say say that we must use "an" MVCC snapshot here, but
they don't explain why it should be one retrieved via
GetTransactionSnapshot() rather than GetActiveSnapshot() or
GetLatestSnapshot() or GetCatalogSnapshot(). The comments also refer
the reader to catalog/pg_enum.c for more details, but the only
information I can find in pg_enum.c just says that if reading multiple
values for the same enum, the same snapshot should be used for all of
them. That's not an issue here, since we're only reading one value.
The behavior can't be chalked up to a desire for MVCC compliance,
because it updates the transaction snapshot mid-query:

rhaas=# create type color as enum ('red');
CREATE TYPE
rhaas=# select distinct enum_last(NULL::color) from
generate_series(1,1000000) g;
enum_last
-----------
red
(1 row)
rhaas=# select distinct enum_last(NULL::color) from
generate_series(1,1000000) g;
-- while this is running, do "alter type color add value 'green';" in
another window
enum_last
-----------
red
green
(2 rows)

I think this is probably a holdover from before the death of
SnapshotNow, and that we should just pass NULL to
systable_beginscan_ordered() here, the same as we do for other catalog
accesses. Barring objections, I'll go make that change.

If there's some remaining reason for doing it this way, we should add
comments explaining what it is.

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2015-02-14 22:06:48 Re: INSERT ... ON CONFLICT {UPDATE | IGNORE} 2.0
Previous Message Robert Haas 2015-02-14 21:14:00 Re: restrict global access to be readonly