From c117838597b1a28f6f0feb4a41adff1a7e5e0bc9 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 2 Jun 2011 14:46:22 -0400 Subject: [PATCH] Disallow SELECT FOR UPDATE/SHARE on sequences. We can't allow this because such an operation stores its transaction XID into the sequence tuple's xmax. Because VACUUM doesn't process sequences (and we don't want it to start doing so), such an xmax value won't get frozen, meaning it will eventually refer to nonexistent pg_clog storage, and even wrap around completely. Since the row lock is ignored by nextval and setval, the usefulness of the operation is highly debatable anyway. Per reports of trouble with pgpool 3.0, which had ill-advisedly started using such commands as a form of locking. In HEAD, also disallow SELECT FOR UPDATE/SHARE on toast tables. Although this does work safely given the current implementation, there seems no good reason to allow it. I refrained from changing that behavior in back branches, however. --- src/backend/executor/execMain.c | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index c477314efa..bbe67ed8bb 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -722,6 +722,45 @@ InitPlan(QueryDesc *queryDesc, int eflags) break; } + /* + * Check that relation is a legal target for marking. + * + * In most cases parser and/or planner should have noticed this + * already, but they don't cover all cases. + */ + if (relation) + { + switch (relation->rd_rel->relkind) + { + case RELKIND_RELATION: + /* OK */ + break; + case RELKIND_SEQUENCE: + /* Must disallow this because we don't vacuum sequences */ + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot lock rows in sequence \"%s\"", + RelationGetRelationName(relation)))); + break; + case RELKIND_TOASTVALUE: + /* This will be disallowed in 9.1, but for now OK */ + break; + case RELKIND_VIEW: + /* Should not get here */ + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot lock rows in view \"%s\"", + RelationGetRelationName(relation)))); + break; + default: + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot lock rows in relation \"%s\"", + RelationGetRelationName(relation)))); + break; + } + } + erm = (ExecRowMark *) palloc(sizeof(ExecRowMark)); erm->relation = relation; erm->rti = rc->rti;