Skip site navigation (1) Skip section navigation (2)

pgsql: Make FOR UPDATE/SHARE in the primary query not propagate into

From: tgl(at)postgresql(dot)org (Tom Lane)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make FOR UPDATE/SHARE in the primary query not propagate into
Date: 2009-10-27 17:11:18
Message-ID: 20091027171118.84D94753FB7@cvs.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
Log Message:
-----------
Make FOR UPDATE/SHARE in the primary query not propagate into WITH queries;
for example in
  WITH w AS (SELECT * FROM foo) SELECT * FROM w, bar ... FOR UPDATE
the FOR UPDATE will now affect bar but not foo.  This is more useful and
consistent than the original 8.4 behavior, which tried to propagate FOR UPDATE
into the WITH query but always failed due to assorted implementation
restrictions.  Even though we are in process of removing those restrictions,
it seems correct on philosophical grounds to not let the outer query's
FOR UPDATE affect the WITH query.

In passing, fix isLockedRel which frequently got things wrong in
nested-subquery cases: "FOR UPDATE OF foo" applies to an alias foo in the
current query level, not subqueries.  This has been broken for a long time,
but it doesn't seem worth back-patching further than 8.4 because the actual
consequences are minimal.  At worst the parser would sometimes get
RowShareLock on a relation when it should be AccessShareLock or vice versa.
That would only make a difference if someone were using ExclusiveLock
concurrently, which no standard operation does, and anyway FOR UPDATE
doesn't result in visible changes so it's not clear that the someone would
notice any problem.  Between that and the fact that FOR UPDATE barely works
with subqueries at all in existing releases, I'm not excited about worrying
about it.

Modified Files:
--------------
    pgsql/doc/src/sgml/ref:
        select.sgml (r1.126 -> r1.127)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/ref/select.sgml?r1=1.126&r2=1.127)
    pgsql/src/backend/parser:
        analyze.c (r1.393 -> r1.394)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/analyze.c?r1=1.393&r2=1.394)
        parse_clause.c (r1.192 -> r1.193)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_clause.c?r1=1.192&r2=1.193)
        parse_cte.c (r2.7 -> r2.8)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_cte.c?r1=2.7&r2=2.8)
        parse_expr.c (r1.245 -> r1.246)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_expr.c?r1=1.245&r2=1.246)
        parse_relation.c (r1.145 -> r1.146)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_relation.c?r1=1.145&r2=1.146)
    pgsql/src/backend/rewrite:
        rewriteHandler.c (r1.188 -> r1.189)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/rewrite/rewriteHandler.c?r1=1.188&r2=1.189)
    pgsql/src/include/parser:
        analyze.h (r1.41 -> r1.42)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/parser/analyze.h?r1=1.41&r2=1.42)
        parse_node.h (r1.64 -> r1.65)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/parser/parse_node.h?r1=1.64&r2=1.65)
        parse_relation.h (r1.65 -> r1.66)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/parser/parse_relation.h?r1=1.65&r2=1.66)

pgsql-committers by date

Next:From: Tom LaneDate: 2009-10-27 17:11:30
Subject: pgsql: Make FOR UPDATE/SHARE in the primary query not propagate into
Previous:From: Alvaro HerreraDate: 2009-10-27 14:04:26
Subject: Re: pgsql: Simplify a few makefile rules since install-sh can now install

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group