pgsql: Prevent RLS filters on ctid from breaking WHERE CURRENT OF

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Prevent RLS filters on ctid from breaking WHERE CURRENT OF
Дата
Msg-id E1s4Oiu-0022Bx-T4@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Prevent RLS filters on ctid from breaking WHERE CURRENT OF <cursor>.

The executor only supports CurrentOfExpr as the sole tidqual of a
TidScan plan node.  tidpath.c failed to take any particular care about
that, but would just take the first ctid equality qual it could find
in the target relation's baserestrictinfo list.  Originally that was
fine because the grammar prevents any other WHERE conditions from
being combined with CURRENT OF <cursor>.  However, if the relation has
RLS visibility policies then those would get included in the list.
Should such a policy include a condition on ctid, we'd typically grab
the wrong qual and produce a malfunctioning plan.

To fix, introduce a simplistic priority ordering scheme for which ctid
equality qual to prefer.  Real-world cases involving more than one
such qual are so rare that it doesn't seem worth going to any great
trouble to choose one over another, so I didn't work very hard; but
this code could be extended in future if someone thinks differently.

It's extremely difficult to think of a reasonable use-case for an RLS
restriction involving ctid, and certainly we've heard no field reports
of this failure.  So this doesn't seem worthy of back-patching, but
in the name of cleanliness let's fix it going forward.

Patch by me, per report from Robert Haas.

Discussion: https://postgr.es/m/3914881.1715038270@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6572bd55b0a63fe234ec454e7a13f3a373864e9e

Modified Files
--------------
src/backend/optimizer/path/tidpath.c      | 88 ++++++++++++++++++++-----------
src/test/regress/expected/rowsecurity.out | 41 ++++++++++++++
src/test/regress/sql/rowsecurity.sql      | 19 +++++++
3 files changed, 118 insertions(+), 30 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: doc: Improve order of options on pgbench reference page
Следующее
От: Jeff Davis
Дата:
Сообщение: pgsql: Remove obsolete comment.