Skip to content

Move code from ExecutorCheckPerms into ExecutorStart#789

Merged
jeltz merged 1 commit into
percona:mainfrom
jeltz:rm-executor-check-perms
Jul 14, 2026
Merged

Move code from ExecutorCheckPerms into ExecutorStart#789
jeltz merged 1 commit into
percona:mainfrom
jeltz:rm-executor-check-perms

Conversation

@jeltz

@jeltz jeltz commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

The data we get in the ExecutorCheckPerms hook is also available in the QueryDesc object we get in the other executor hooks so doing the relation name lookup in a separate hook only makes the code more complicated for no gain.

It might make even more sense to move this lookup to the ExecutorEnd hook but that risks changing the behavior as we cannot do catalog lookups when the transaction has been rolled back. It is unclear if we need to support that, but that kind of change should be its own commit.

PG-0

@jeltz jeltz changed the title Move code from the ExecutorCheckPerms into ExecutorStart Move code from ExecutorCheckPerms into ExecutorStart Jul 14, 2026
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.04%. Comparing base (16107e3) to head (53b3df0).

Files with missing lines Patch % Lines
src/pg_stat_monitor.c 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #789      +/-   ##
==========================================
+ Coverage   87.93%   88.04%   +0.10%     
==========================================
  Files           3        3              
  Lines        1318     1313       -5     
  Branches      186      185       -1     
==========================================
- Hits         1159     1156       -3     
+ Misses         77       76       -1     
+ Partials       82       81       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The data we get in the ExecutorCheckPerms hook is also available in the
QueryDesc object we get in the other executor hooks so doing the
relation name lookup in a separate hook only makes the code more
complicated for no gain.

It might make even more sense to move this lookup to the ExecutorEnd
hook but that risks changing the behavior as we cannot do catalog
lookups when the transaction has been rolled back. It is unclear if we
need to support that, but that kind of change should be its own commit.
@jeltz jeltz force-pushed the rm-executor-check-perms branch from b668dc9 to 53b3df0 Compare July 14, 2026 13:23
@jeltz jeltz merged commit 015df29 into percona:main Jul 14, 2026
28 checks passed

@dutow dutow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduced a bug (or two, depending on how count it): the utility path doesn't update relations and num_relations

-- Observed results for the trailing COPY:
--   base (main)     : {public.logtbl}          (correct — COPY's own table)
--   patched (pr789) : {public.sensitive_audit} (WRONG — from the prior errored query)
CREATE EXTENSION IF NOT EXISTS pg_stat_monitor;
CREATE TABLE sensitive_audit(id int);
INSERT INTO sensitive_audit VALUES (1);
CREATE TABLE logtbl(id int);
SELECT pg_stat_monitor_reset();

-- Tracked query touching sensitive_audit, errors during ExecutorRun:
SELECT id, 1/(id-1) FROM sensitive_audit;   -- division by zero
-- Unrelated utility statement stored via the ProcessUtility path:
COPY logtbl TO '/tmp/pgsm_stale.csv' CSV;

SELECT substring(query for 45) AS query, relations
FROM pg_stat_monitor
WHERE query ILIKE '%COPY logtbl%' OR query ILIKE '%sensitive%'
ORDER BY query;

and

-- Observed results:
--                                      base (main)                 patched (pr789)
--   SELECT ... FROM parent             {public.parent}             {public.parent}   (unchanged)
--   INSERT INTO child (has FK)         {}  (clobbered/empty)       {public.child}    (FIXED)
--   UPDATE child (has FK)              {}  (clobbered/empty)       {public.child}    (FIXED)
--   COPY parent TO ...                 {public.parent}             {}                (REGRESSION)

CREATE EXTENSION IF NOT EXISTS pg_stat_monitor;
CREATE TABLE parent(id int primary key);
CREATE TABLE child(id int primary key, pid int references parent(id));
INSERT INTO parent VALUES (1),(2),(3);
SELECT pg_stat_monitor_reset();

SELECT * FROM parent WHERE id = 1;
INSERT INTO child VALUES (10, 1);
COPY parent TO '/tmp/pgsm_copy_test.csv' CSV;
UPDATE child SET pid = 2 WHERE id = 10;

SELECT substring(query for 42) AS query, relations
FROM pg_stat_monitor
WHERE query NOT ILIKE '%pg_stat_monitor%' AND query NOT ILIKE '%CREATE%'
ORDER BY query;

Comment thread src/pg_stat_monitor.c
}

/*
* Save names of relations involved in the qeury.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants