Hi, On 2013-07-11 11:53:57 -0700, Jeff Davis wrote: > On Thu, 2013-07-11 at 10:28 +0200, Andres Freund wrote: > > There doesn't seem be an explicitly stated rule that we cannot use the > > syscaches outside of a transaction - but effectively that's required > > atm. > > Aren't there other things that already required that before the MVCC > catalog snapshot patch went in? For instance, if you get a syscache > miss, you have to load from the catalogs, meaning you need to acquire a > lock.
There are. Several. I am blaming it on conference induced haze. Or such. On 2013-07-11 15:09:45 -0400, Tom Lane wrote: > It never has been, and never will be, allowed to call the catcache code > without being in a transaction. What do you think will happen if the > requested row isn't in cache? A table access, that's what, and that > absolutely requires being in a transaction. Makes sense. I was confused because I thought I saw a get_database_name() and other users outside of a transaction but that turned out not looking closely enough. I'd like to add an Assert like in the attached patch making sure we're in a transaction. Otherwise it's far too easy not to hit an error during development because everything is cached - and syscache usage isn't always obvious from the outside to the naive or the tired. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 7fc205a..7863105 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -21,6 +21,7 @@ #include "access/sysattr.h" #include "access/tuptoaster.h" #include "access/valid.h" +#include "access/xact.h" #include "catalog/pg_operator.h" #include "catalog/pg_type.h" #include "miscadmin.h" @@ -1069,6 +1070,9 @@ SearchCatCache(CatCache *cache, SysScanDesc scandesc; HeapTuple ntp; + /* Make sure we're in a xact, even if this ends up being a cache hit */ + Assert(IsTransactionState()); + /* * one-time startup overhead for each cache */
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers