pgaudit.git / summary / log / commit / refs
commit ca4a75d25a153580f3fca65eebfbe80ad05db58d
Author: Kubo Takehiro <kubo@jiubao.org>
Commit: GitHub <noreply@github.com>
Date: Fri May 22 06:36:22 2026 +0000
Use es_total_processed instead of es_processed to count statement rows. (#290)
This is simpler and allows the ExecutorRun_hook to be removed, while returning the same results.
Reviewed by David Steele (@dwsteele)
pgaudit.c | 37 +++----------------------------------
1 file changed, 3 insertions(+), 34 deletions(-)
diff --git a/pgaudit.c b/pgaudit.c
index ac0b235..d10387d 100644
--- a/pgaudit.c
+++ b/pgaudit.c
@@ -1404,8 +1404,6 @@ static ExecutorCheckPerms_hook_type next_ExecutorCheckPerms_hook = NULL;
static ProcessUtility_hook_type next_ProcessUtility_hook = NULL;
static object_access_hook_type next_object_access_hook = NULL;
static ExecutorStart_hook_type next_ExecutorStart_hook = NULL;
-/* The following hook functions are required to get rows */
-static ExecutorRun_hook_type next_ExecutorRun_hook = NULL;
static ExecutorEnd_hook_type next_ExecutorEnd_hook = NULL;
/*
@@ -1548,34 +1546,6 @@ pgaudit_ExecutorCheckPerms_hook(List *rangeTabls,
return true;
}
-/*
- * Hook ExecutorRun to get rows processed by the current statement.
- */
-static void
-pgaudit_ExecutorRun_hook(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
-{
- AuditEventStackItem *stackItem = NULL;
-
- /* Call the previous hook or standard function */
- if (next_ExecutorRun_hook)
- next_ExecutorRun_hook(queryDesc, direction, count);
- else
- standard_ExecutorRun(queryDesc, direction, count);
-
- if (auditLogRows && !internalStatement && !IsParallelWorker())
- {
- /* Find an item from the stack by the query memory context */
- stackItem = stack_find_context(queryDesc->estate->es_query_cxt);
-
- /* Accumulate the number of rows processed */
- if (stackItem != NULL)
- {
- STACK_NOT_EMPTY();
- stackItem->auditEvent.rows += queryDesc->estate->es_processed;
- }
- }
-}
-
/*
* Hook ExecutorEnd to get rows processed by the current statement.
*/
@@ -1594,6 +1564,9 @@ pgaudit_ExecutorEnd_hook(QueryDesc *queryDesc)
{
STACK_NOT_EMPTY();
+ /* Get rows processed */
+ stackItem->auditEvent.rows = queryDesc->estate->es_total_processed;
+
/* Reset auditEventStack to use in log_select_dml() */
auditEventStackFull = auditEventStack;
auditEventStack = stackItem;
@@ -2345,10 +2318,6 @@ _PG_init(void)
next_object_access_hook = object_access_hook;
object_access_hook = pgaudit_object_access_hook;
- /* The following hook functions are required to get rows */
- next_ExecutorRun_hook = ExecutorRun_hook;
- ExecutorRun_hook = pgaudit_ExecutorRun_hook;
-
next_ExecutorEnd_hook = ExecutorEnd_hook;
ExecutorEnd_hook = pgaudit_ExecutorEnd_hook;
[parent: b297f4e2b606]