Skip to content

Commit

Permalink
Fix level tracking for older PG versions once again
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Jun 13, 2024
1 parent 7a5add3 commit 8eddd50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pg_stat_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,8 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
* To be absolutely certain we don't mess up the nesting level,
* evaluate the bump_level condition just once.
*/

#if PG_VERSION_NUM >= 170000
bool bump_level =
!IsA(parsetree, ExecuteStmt) &&
!IsA(parsetree, PrepareStmt) &&
Expand All @@ -1243,6 +1245,7 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,

PG_TRY();
{
#endif
#if PG_VERSION_NUM >= 140000
if (prev_ProcessUtility)
prev_ProcessUtility(pstmt, queryString,
Expand Down Expand Up @@ -1279,6 +1282,7 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
dest,
completionTag);
#endif
#if PG_VERSION_NUM >= 170000
if (bump_level)
nesting_level--;
}
Expand All @@ -1289,6 +1293,7 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
PG_RE_THROW();
}
PG_END_TRY();
#endif
}
}

Expand Down
12 changes: 6 additions & 6 deletions regression/expected/level_tracking_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ SELECT toplevel, calls, query FROM pg_stat_monitor
ORDER BY query COLLATE "C", toplevel;
toplevel | calls | query
----------+-------+--------------------------------
t | 1 | DELETE FROM stats_track_tab
t | 2 | DELETE FROM stats_track_tab
t | 1 | SELECT $1::TEXT
t | 1 | SELECT pg_stat_monitor_reset()
(2 rows)
(3 rows)

-- DO block - all-level tracking without utility.
SET pg_stat_monitor.pgsm_track = 'all';
Expand All @@ -122,11 +123,10 @@ SELECT toplevel, calls, query FROM pg_stat_monitor
ORDER BY query COLLATE "C", toplevel;
toplevel | calls | query
----------+-------+--------------------------------
f | 1 | DELETE FROM stats_track_tab
t | 1 | DELETE FROM stats_track_tab
f | 1 | SELECT $1::TEXT
t | 2 | DELETE FROM stats_track_tab
t | 1 | SELECT $1::TEXT
t | 1 | SELECT pg_stat_monitor_reset()
(4 rows)
(3 rows)

-- PL/pgSQL function - top-level tracking.
SET pg_stat_monitor.pgsm_track = 'top';
Expand Down

0 comments on commit 8eddd50

Please sign in to comment.