Skip to content

Commit

Permalink
add support for new columns in PG17
Browse files Browse the repository at this point in the history
  • Loading branch information
troycoll committed Feb 26, 2025
1 parent 795b2d7 commit 499edde
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions packages/cli/src/commands/pg/outliers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,36 @@ export default class Outliers extends Command {
CASE WHEN length(query) <= 40 THEN query ELSE substr(query, 0, 39) || '…' END
` : 'query'

let totalExecTimeField = ''
if (version && Number.parseInt(version, 10) >= 13) {
return heredoc`
totalExecTimeField = 'total_exec_time'
} else {
totalExecTimeField = 'total_time'
}

let blkReadTimeField = ''
let blkWriteTimeField = ''
if (version && Number.parseInt(version, 10) >= 17) {
blkReadTimeField = 'shared_blk_read_time'
blkWriteTimeField = 'shared_blk_write_time'
} else {
blkReadTimeField = 'blk_read_time'
blkWriteTimeField = 'blk_write_time'
}

return heredoc`
SELECT
interval '1 millisecond' * total_exec_time AS total_exec_time,
to_char((total_exec_time/sum(total_exec_time) OVER()) * 100, 'FM90D0') || '%' AS prop_exec_time,
interval '1 millisecond' * ${totalExecTimeField} AS total_exec_time,
to_char((${totalExecTimeField}/sum(${totalExecTimeField}) OVER()) * 100, 'FM90D0') || '%' AS prop_exec_time,
to_char(calls, 'FM999G999G999G990') AS ncalls,
interval '1 millisecond' * (blk_read_time + blk_write_time) AS sync_io_time,
interval '1 millisecond' * (${blkReadTimeField} + ${blkWriteTimeField}) AS sync_io_time,
${truncatedQueryString} AS query
FROM pg_stat_statements
WHERE userid = (
SELECT usesysid FROM pg_user WHERE usename = current_user LIMIT 1
)
ORDER BY total_exec_time DESC
ORDER BY ${totalExecTimeField} DESC
LIMIT ${limit};
`
}

return heredoc`
SELECT
interval '1 millisecond' * total_time AS total_exec_time,
to_char((total_time/sum(total_time) OVER()) * 100, 'FM90D0') || '%' AS prop_exec_time,
to_char(calls, 'FM999G999G999G990') AS ncalls,
interval '1 millisecond' * (blk_read_time + blk_write_time) AS sync_io_time,
${truncatedQueryString} AS query
FROM pg_stat_statements
WHERE userid = (
SELECT usesysid FROM pg_user WHERE usename = current_user LIMIT 1
)
ORDER BY total_time DESC
LIMIT ${limit};
`
}
}

0 comments on commit 499edde

Please sign in to comment.