Обсуждение: pgsql: Create an RTE field to record the query's lock mode for eachrel

Поиск
Список
Период
Сортировка

pgsql: Create an RTE field to record the query's lock mode for eachrel

От
Tom Lane
Дата:
Create an RTE field to record the query's lock mode for each relation.

Add RangeTblEntry.rellockmode, which records the appropriate lock mode for
each RTE_RELATION rangetable entry (either AccessShareLock, RowShareLock,
or RowExclusiveLock depending on the RTE's role in the query).

This patch creates the field and makes all creators of RTE nodes fill it
in reasonably, but for the moment nothing much is done with it.  The plan
is to replace assorted post-parser logic that re-determines the right
lockmode to use with simple uses of rte->rellockmode.  For now, just add
Asserts in each of those places that the rellockmode matches what they are
computing today.  (In some cases the match isn't perfect, so the Asserts
are weaker than you might expect; but this seems OK, as per discussion.)

This passes check-world for me, but it seems worth pushing in this state
to see if the buildfarm finds any problems in cases I failed to test.

catversion bump due to change of stored rules.

Amit Langote, reviewed by David Rowley and Jesper Pedersen,
and whacked around a bit more by me

Discussion: https://postgr.es/m/468c85d9-540e-66a2-1dde-fec2b741e688@lab.ntt.co.jp

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fdba460a26af919c0b366755d119f384706e670a

Modified Files
--------------
src/backend/catalog/dependency.c                 |  1 +
src/backend/catalog/heap.c                       |  1 +
src/backend/commands/copy.c                      |  9 +++---
src/backend/commands/createas.c                  |  1 +
src/backend/commands/policy.c                    | 23 +++++++++-----
src/backend/commands/tablecmds.c                 |  3 +-
src/backend/commands/trigger.c                   |  2 ++
src/backend/commands/view.c                      |  4 ++-
src/backend/executor/execMain.c                  | 11 +++++++
src/backend/executor/execUtils.c                 | 20 +++++++++---
src/backend/nodes/copyfuncs.c                    |  1 +
src/backend/nodes/equalfuncs.c                   |  1 +
src/backend/nodes/outfuncs.c                     |  1 +
src/backend/nodes/readfuncs.c                    |  1 +
src/backend/optimizer/plan/planner.c             |  2 ++
src/backend/parser/analyze.c                     |  1 +
src/backend/parser/parse_clause.c                |  1 +
src/backend/parser/parse_relation.c              | 28 +++++++++++++++--
src/backend/parser/parse_utilcmd.c               |  9 +++++-
src/backend/replication/logical/tablesync.c      |  3 +-
src/backend/replication/logical/worker.c         |  1 +
src/backend/rewrite/rewriteHandler.c             | 39 ++++++++++++++++++------
src/backend/utils/adt/ri_triggers.c              |  2 ++
src/backend/utils/adt/ruleutils.c                |  3 ++
src/backend/utils/cache/plancache.c              |  6 +++-
src/include/catalog/catversion.h                 |  2 +-
src/include/nodes/parsenodes.h                   | 12 ++++++++
src/include/parser/parse_relation.h              |  1 +
src/test/modules/test_rls_hooks/test_rls_hooks.c |  8 ++---
29 files changed, 159 insertions(+), 38 deletions(-)


Re: pgsql: Create an RTE field to record the query's lock mode foreach rel

От
Andres Freund
Дата:
On 2018-09-30 17:55:57 +0000, Tom Lane wrote:
> Create an RTE field to record the query's lock mode for each relation.

> Details
> -------
> https://git.postgresql.org/pg/commitdiff/fdba460a26af919c0b366755d119f384706e670a

This triggers a new warning for me, when building without asserts:

/home/andres/src/postgresql/src/backend/executor/execMain.c: In function ‘InitPlan’:
/home/andres/src/postgresql/src/backend/executor/execMain.c:963:12: warning: variable ‘rellockmode’ set but not used
[-Wunused-but-set-variable]
   LOCKMODE rellockmode;
            ^~~~~~~~~~~

Greetings,

Andres Freund


Re: pgsql: Create an RTE field to record the query's lock mode for each rel

От
Tom Lane
Дата:
Andres Freund <andres@anarazel.de> writes:
> On 2018-09-30 17:55:57 +0000, Tom Lane wrote:
>> Create an RTE field to record the query's lock mode for each relation.

> This triggers a new warning for me, when building without asserts:

> /home/andres/src/postgresql/src/backend/executor/execMain.c: In function ‘InitPlan’:
> /home/andres/src/postgresql/src/backend/executor/execMain.c:963:12: warning: variable ‘rellockmode’ set but not used
[-Wunused-but-set-variable]
>    LOCKMODE rellockmode;
>             ^~~~~~~~~~~

Yeah, I knew it would do that.  I didn't think it was worth working
around, because that issue will go away in the next phase of the
patch (probably tomorrow).

            regards, tom lane