Skip to content

Commit

Permalink
v0.3 with starts
Browse files Browse the repository at this point in the history
  • Loading branch information
tanelpoder committed Jan 4, 2025
1 parent 4e24975 commit df1b4b0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sqlflame.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
-- Note that you'll have to replace HOST OPEN with HOST START in the
-- end of this file if you're using sqlplus client on Windows
--
-- Author: Tanel Poder - https://blog.tanelpoder.com
-- Author: Tanel Poder - https://tanelpoder.com
--
-- Examples: https://tanelpoder.com/posts/visualizing-sql-plan-execution-time-with-flamegraphs/
-- https://tanelpoder.com/posts/visualizing-sql-plan-execution-time-with-flamegraphs-starts/
--
-- Other: This is an early version mostly meant as a proof of concept for
-- illustrating that a modern RDBMS SQL execution plan profile
Expand All @@ -35,14 +38,14 @@
SET HEADING OFF LINESIZE 32767 PAGESIZE 0 TRIMSPOOL ON TRIMOUT ON LONG 9999999 VERIFY OFF LONGCHUNKSIZE 100000 FEEDBACK OFF APPINFO OFF

PROMPT
PROMPT -- SQLFlame 0.2 by Tanel Poder ( https://blog.tanelpoder.com )
PROMPT -- SQLFlame 0.3 by Tanel Poder ( https://tanelpoder.com )

SET TERMOUT OFF

WITH sq AS (
SELECT /*+ MATERIALIZE */
sp.id, sp.parent_id, sp.operation, sp.options
, sp.object_owner, sp.object_name, ss.last_elapsed_time, ss.elapsed_time
, sp.object_owner, sp.object_name, ss.last_elapsed_time, ss.elapsed_time, ss.last_starts
FROM v$sql_plan_statistics_all ss INNER JOIN
v$sql_plan sp
ON (
Expand All @@ -61,15 +64,15 @@ WITH sq AS (
GROUP BY par.id, par.elapsed_time
), combined AS (
SELECT sq.id, sq.parent_id, sq.operation, sq.options
, sq.object_owner, sq.object_name, sq.last_elapsed_time, sq.elapsed_time
, sq.object_owner, sq.object_name, sq.last_elapsed_time, sq.elapsed_time, sq.last_starts
, NVL(deltas.self_elapsed_time, sq.elapsed_time) self_elapsed_time
FROM
sq, deltas
WHERE
sq.id = deltas.id
)
SELECT
'0 - SELECT STATEMENT'||TRIM(SYS_CONNECT_BY_PATH(id||' - '||operation||NVL2(options,' '||options,NULL)||NVL2(object_owner||object_name, ' ['||object_owner||'.'||object_name||']', NULL), ';'))||' '||TRIM(ROUND(self_elapsed_time/1000))
'0 - SELECT STATEMENT'||TRIM(SYS_CONNECT_BY_PATH(id||' - '||operation||NVL2(options,' '||options,NULL)||NVL2(object_owner||object_name, ' ['||object_owner||'.'||object_name||']', NULL)||' starts='||last_starts, ';'))||' '||TRIM(ROUND(self_elapsed_time/1000))
FROM
combined
CONNECT BY
Expand Down

0 comments on commit df1b4b0

Please sign in to comment.