Skip to content

Commit c117838

Browse files
committed
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.
1 parent b26d8fd commit c117838

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/backend/executor/execMain.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,45 @@ InitPlan(QueryDesc *queryDesc, int eflags)
722722
break;
723723
}
724724

725+
/*
726+
* Check that relation is a legal target for marking.
727+
*
728+
* In most cases parser and/or planner should have noticed this
729+
* already, but they don't cover all cases.
730+
*/
731+
if (relation)
732+
{
733+
switch (relation->rd_rel->relkind)
734+
{
735+
case RELKIND_RELATION:
736+
/* OK */
737+
break;
738+
case RELKIND_SEQUENCE:
739+
/* Must disallow this because we don't vacuum sequences */
740+
ereport(ERROR,
741+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
742+
errmsg("cannot lock rows in sequence \"%s\"",
743+
RelationGetRelationName(relation))));
744+
break;
745+
case RELKIND_TOASTVALUE:
746+
/* This will be disallowed in 9.1, but for now OK */
747+
break;
748+
case RELKIND_VIEW:
749+
/* Should not get here */
750+
ereport(ERROR,
751+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
752+
errmsg("cannot lock rows in view \"%s\"",
753+
RelationGetRelationName(relation))));
754+
break;
755+
default:
756+
ereport(ERROR,
757+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
758+
errmsg("cannot lock rows in relation \"%s\"",
759+
RelationGetRelationName(relation))));
760+
break;
761+
}
762+
}
763+
725764
erm = (ExecRowMark *) palloc(sizeof(ExecRowMark));
726765
erm->relation = relation;
727766
erm->rti = rc->rti;

0 commit comments

Comments
 (0)