pgsql: Rework query relation permission checking - Mailing list pgsql-committers

From Alvaro Herrera
Subject pgsql: Rework query relation permission checking
Date
Msg-id E1p2Zjj-002FW0-QP@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Rework query relation permission checking

Currently, information about the permissions to be checked on relations
mentioned in a query is stored in their range table entries.  So the
executor must scan the entire range table looking for relations that
need to have permissions checked.  This can make the permission checking
part of the executor initialization needlessly expensive when many
inheritance children are present in the range range.  While the
permissions need not be checked on the individual child relations, the
executor still must visit every range table entry to filter them out.

This commit moves the permission checking information out of the range
table entries into a new plan node called RTEPermissionInfo.  Every
top-level (inheritance "root") RTE_RELATION entry in the range table
gets one and a list of those is maintained alongside the range table.
This new list is initialized by the parser when initializing the range
table.  The rewriter can add more entries to it as rules/views are
expanded.  Finally, the planner combines the lists of the individual
subqueries into one flat list that is passed to the executor for
checking.

To make it quick to find the RTEPermissionInfo entry belonging to a
given relation, RangeTblEntry gets a new Index field 'perminfoindex'
that stores the corresponding RTEPermissionInfo's index in the query's
list of the latter.

ExecutorCheckPerms_hook has gained another List * argument; the
signature is now:
typedef bool (*ExecutorCheckPerms_hook_type) (List *rangeTable,
                                              List *rtePermInfos,
                                              bool ereport_on_violation);
The first argument is no longer used by any in-core uses of the hook,
but we leave it in place because there may be other implementations that
do.  Implementations should likely scan the rtePermInfos list to
determine which operations to allow or deny.

Author: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/CA+HiwqGjJDmUhDSfv-U2qhKJjt9ST7Xh9JXC_irsAQ1TAUsJYg@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c              |  17 +-
contrib/sepgsql/dml.c                            |  42 +++--
contrib/sepgsql/hooks.c                          |   6 +-
contrib/sepgsql/sepgsql.h                        |   3 +-
src/backend/commands/copy.c                      |  23 +--
src/backend/commands/copyfrom.c                  |  11 +-
src/backend/commands/view.c                      |  33 +++-
src/backend/executor/execMain.c                  | 117 ++++++-------
src/backend/executor/execParallel.c              |   1 +
src/backend/executor/execUtils.c                 | 134 ++++++++++-----
src/backend/nodes/outfuncs.c                     |   6 +-
src/backend/nodes/readfuncs.c                    |   6 +-
src/backend/optimizer/plan/planner.c             |   6 +
src/backend/optimizer/plan/setrefs.c             |  73 ++++++--
src/backend/optimizer/plan/subselect.c           |   8 +-
src/backend/optimizer/prep/prepjointree.c        |  21 +--
src/backend/optimizer/util/inherit.c             | 173 ++++++++++++++-----
src/backend/optimizer/util/relnode.c             |  21 ++-
src/backend/parser/analyze.c                     |  68 +++++---
src/backend/parser/parse_clause.c                |   9 +-
src/backend/parser/parse_merge.c                 |   9 +-
src/backend/parser/parse_relation.c              | 178 +++++++++++---------
src/backend/parser/parse_target.c                |  18 +-
src/backend/parser/parse_utilcmd.c               |   6 +-
src/backend/replication/logical/worker.c         |  11 +-
src/backend/rewrite/rewriteDefine.c              |  27 +--
src/backend/rewrite/rewriteHandler.c             | 205 ++++++++++++-----------
src/backend/rewrite/rewriteManip.c               |  33 ++++
src/backend/rewrite/rowsecurity.c                |  25 ++-
src/backend/utils/adt/ri_triggers.c              |  19 ++-
src/backend/utils/cache/relcache.c               |   4 +-
src/include/catalog/catversion.h                 |   2 +-
src/include/commands/copyfrom_internal.h         |   3 +-
src/include/executor/executor.h                  |  10 +-
src/include/nodes/execnodes.h                    |   3 +-
src/include/nodes/parsenodes.h                   |  94 +++++++----
src/include/nodes/pathnodes.h                    |   3 +
src/include/nodes/plannodes.h                    |   3 +
src/include/optimizer/inherit.h                  |   2 +
src/include/parser/parse_node.h                  |   9 +-
src/include/parser/parse_relation.h              |   4 +
src/include/rewrite/rewriteHandler.h             |   1 +
src/include/rewrite/rewriteManip.h               |   2 +
src/test/modules/test_oat_hooks/test_oat_hooks.c |   6 +-
src/test/regress/expected/rules.out              |  14 ++
src/test/regress/sql/rules.sql                   |  15 ++
src/tools/pgindent/typedefs.list                 |   2 +
47 files changed, 953 insertions(+), 533 deletions(-)


pgsql-committers by date:

Previous
From: David Rowley
Date:
Subject: pgsql: Fix 32-bit build dangling pointer issue in WindowAgg
Next
From: Andres Freund
Date:
Subject: pgsql: meson: Basic cygwin support