aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/analyze.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-03-15 18:41:47 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2015-03-15 18:41:47 -0400
commit7b8b8a43317e9e59eca8b511b714a0ab7da5f1cb (patch)
tree3a487b80bbc6d874fc72f556298d7e29680a4005 /src/backend/parser/analyze.c
parent9fac5fd741ec17ae24dde6b8e82064f13c148ddf (diff)
downloadpostgresql-7b8b8a43317e9e59eca8b511b714a0ab7da5f1cb.tar.gz
postgresql-7b8b8a43317e9e59eca8b511b714a0ab7da5f1cb.zip
Improve representation of PlanRowMark.
This patch fixes two inadequacies of the PlanRowMark representation. First, that the original LockingClauseStrength isn't stored (and cannot be inferred for foreign tables, which always get ROW_MARK_COPY). Since some PlanRowMarks are created out of whole cloth and don't actually have an ancestral RowMarkClause, this requires adding a dummy LCS_NONE value to enum LockingClauseStrength, which is fairly annoying but the alternatives seem worse. This fix allows getting rid of the use of get_parse_rowmark() in FDWs (as per the discussion around commits 462bd95705a0c23b and 8ec8760fc87ecde0), and it simplifies some things elsewhere. Second, that the representation assumed that all child tables in an inheritance hierarchy would use the same RowMarkType. That's true today but will soon not be true. We add an "allMarkTypes" field that identifies the union of mark types used in all a parent table's children, and use that where appropriate (currently, only in preprocess_targetlist()). In passing fix a couple of minor infelicities left over from the SKIP LOCKED patch, notably that _outPlanRowMark still thought waitPolicy is a bool. Catversion bump is required because the numeric values of enum LockingClauseStrength can appear in on-disk rules. Extracted from a much larger patch to support foreign table inheritance; it seemed worth breaking this out, since it's a separable concern. Shigeru Hanada and Etsuro Fujita, somewhat modified by me
Diffstat (limited to 'src/backend/parser/analyze.c')
-rw-r--r--src/backend/parser/analyze.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index a68f2e8bb14..4a5a5205391 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -2254,11 +2254,18 @@ transformCreateTableAsStmt(ParseState *pstate, CreateTableAsStmt *stmt)
}
-char *
+/*
+ * Produce a string representation of a LockClauseStrength value.
+ * This should only be applied to valid values (not LCS_NONE).
+ */
+const char *
LCS_asString(LockClauseStrength strength)
{
switch (strength)
{
+ case LCS_NONE:
+ Assert(false);
+ break;
case LCS_FORKEYSHARE:
return "FOR KEY SHARE";
case LCS_FORSHARE:
@@ -2279,6 +2286,8 @@ LCS_asString(LockClauseStrength strength)
void
CheckSelectLocking(Query *qry, LockClauseStrength strength)
{
+ Assert(strength != LCS_NONE); /* else caller error */
+
if (qry->setOperations)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -2498,6 +2507,8 @@ applyLockingClause(Query *qry, Index rtindex,
{
RowMarkClause *rc;
+ Assert(strength != LCS_NONE); /* else caller error */
+
/* If it's an explicit clause, make sure hasForUpdate gets set */
if (!pushedDown)
qry->hasForUpdate = true;
@@ -2506,20 +2517,21 @@ applyLockingClause(Query *qry, Index rtindex,
if ((rc = get_parse_rowmark(qry, rtindex)) != NULL)
{
/*
- * If the same RTE is specified for more than one locking strength,
- * treat is as the strongest. (Reasonable, since you can't take both
- * a shared and exclusive lock at the same time; it'll end up being
- * exclusive anyway.)
+ * If the same RTE is specified with more than one locking strength,
+ * use the strongest. (Reasonable, since you can't take both a shared
+ * and exclusive lock at the same time; it'll end up being exclusive
+ * anyway.)
*
- * Similarly, if the same RTE is specified with more than one lock wait
- * policy, consider that NOWAIT wins over SKIP LOCKED, which in turn
- * wins over waiting for the lock (the default). This is a bit more
- * debatable but raising an error doesn't seem helpful. (Consider for
- * instance SELECT FOR UPDATE NOWAIT from a view that internally
+ * Similarly, if the same RTE is specified with more than one lock
+ * wait policy, consider that NOWAIT wins over SKIP LOCKED, which in
+ * turn wins over waiting for the lock (the default). This is a bit
+ * more debatable but raising an error doesn't seem helpful. (Consider
+ * for instance SELECT FOR UPDATE NOWAIT from a view that internally
* contains a plain FOR UPDATE spec.) Having NOWAIT win over SKIP
* LOCKED is reasonable since the former throws an error in case of
- * coming across a locked tuple, which may be undesirable in some cases
- * but it seems better than silently returning inconsistent results.
+ * coming across a locked tuple, which may be undesirable in some
+ * cases but it seems better than silently returning inconsistent
+ * results.
*
* And of course pushedDown becomes false if any clause is explicit.
*/