diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-12-13 02:00:30 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-12-13 02:00:30 +0000 |
commit | 8d1d6019d4d85c51a4c414bb95a71f8897956218 (patch) | |
tree | 53c49d58547742a24d2487b85d224a8aa1063f21 /src/backend/parser/analyze.c | |
parent | f6bab284885a4594cfa8f199ba7458dca81059f3 (diff) |
Fix failure to ensure that a snapshot is available to datatype input functions
when they are invoked by the parser. We had been setting up a snapshot at
plan time but really it needs to be done earlier, before parse analysis.
Per report from Dmitry Koterov.
Also fix two related problems discovered while poking at this one:
exec_bind_message called datatype input functions without establishing a
snapshot, and SET CONSTRAINTS IMMEDIATE could call trigger functions without
establishing a snapshot.
Backpatch to 8.2. The underlying problem goes much further back, but it is
masked in 8.1 and before because we didn't attempt to invoke domain check
constraints within datatype input. It would only be exposed if a C-language
datatype input function used the snapshot; which evidently none do, or we'd
have heard complaints sooner. Since this code has changed a lot over time,
a back-patch is hardly risk-free, and so I'm disinclined to patch further
than absolutely necessary.
Diffstat (limited to 'src/backend/parser/analyze.c')
-rw-r--r-- | src/backend/parser/analyze.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 759dc64d940..4a539a1e1e8 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -17,7 +17,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.371 2008/01/01 19:45:50 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.371.2.1 2008/12/13 02:00:29 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -228,6 +228,55 @@ transformStmt(ParseState *pstate, Node *parseTree) } /* + * analyze_requires_snapshot + * Returns true if a snapshot must be set before doing parse analysis + * on the given raw parse tree. + * + * Classification here should match transformStmt(). + */ +bool +analyze_requires_snapshot(Node *parseTree) +{ + bool result; + + switch (nodeTag(parseTree)) + { + /* + * Optimizable statements + */ + case T_InsertStmt: + case T_DeleteStmt: + case T_UpdateStmt: + case T_SelectStmt: + result = true; + break; + + /* + * Special cases + */ + case T_DeclareCursorStmt: + /* yes, because it's analyzed just like SELECT */ + result = true; + break; + + case T_ExplainStmt: + /* + * We only need a snapshot in varparams case, but it doesn't seem + * worth complicating this function's API to distinguish that. + */ + result = true; + break; + + default: + /* utility statements don't have any active parse analysis */ + result = false; + break; + } + + return result; +} + +/* * transformDeleteStmt - * transforms a Delete Statement */ |