diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-03-03 17:39:58 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-03-03 17:39:58 -0500 |
commit | 2b78d101d1d6b1d8533a7b7aeff4d82b10a915f8 (patch) | |
tree | 72f853c8e4b9cf21b5c24eb0eb4481b067f36e89 /src/backend/access | |
parent | 891869c352160e480d4afdc2a3443035c2560282 (diff) | |
download | postgresql-2b78d101d1d6b1d8533a7b7aeff4d82b10a915f8.tar.gz postgresql-2b78d101d1d6b1d8533a7b7aeff4d82b10a915f8.zip |
Fix SQL function execution to be safe with long-lived FmgrInfos.
fmgr_sql had been designed on the assumption that the FmgrInfo it's called
with has only query lifespan. This is demonstrably unsafe in connection
with range types, as shown in bug #7881 from Andrew Gierth. Fix things
so that we re-generate the function's cache data if the (sub)transaction
it was made in is no longer active.
Back-patch to 9.2. This might be needed further back, but it's not clear
whether the case can realistically arise without range types, so for now
I'll desist from back-patching further.
Diffstat (limited to 'src/backend/access')
-rw-r--r-- | src/backend/access/transam/xact.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 9a9724574be..e62286f9f98 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -570,6 +570,27 @@ GetCurrentSubTransactionId(void) return s->subTransactionId; } +/* + * SubTransactionIsActive + * + * Test if the specified subxact ID is still active. Note caller is + * responsible for checking whether this ID is relevant to the current xact. + */ +bool +SubTransactionIsActive(SubTransactionId subxid) +{ + TransactionState s; + + for (s = CurrentTransactionState; s != NULL; s = s->parent) + { + if (s->state == TRANS_ABORT) + continue; + if (s->subTransactionId == subxid) + return true; + } + return false; +} + /* * GetCurrentCommandId |