Skip to content

Oracle explain plan support - #3080

Open
jtduffy wants to merge 3 commits into
mainfrom
oracle-explain
Open

Oracle explain plan support#3080
jtduffy wants to merge 3 commits into
mainfrom
oracle-explain

Conversation

@jtduffy

@jtduffy jtduffy commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Resolves #3031

This adds explain plan support to Oracle 11g+ when utilizing the jdbc-ojdbc7-12.1.0.2 or jdbc-ojdbc8-21.1.0.0 instrumentation modules.

Oracle's explain plans don't follow the flow that Postgres, etc do. Instead...

  • Run the query to generate the plan: EXPLAIN PLAN SET STATEMENT_ID = '<id>' FOR <sql>. The generated plan is written to the PLAN_TABLE table.
  • Run the query SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE') to extract the explain plan rows
  • Parse the explain plan output into human readable text

An example of a final Oracle explain plan as added as an attribute to a SQLTracer...

Plan hash value: 3210784694                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                            
  -------------------------------------------------------------------------------------------------------                                                                                                                                                 
  | Id  | Operation                             | Name          | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                   
  -------------------------------------------------------------------------------------------------------                                                                                                                                                   
  |   0 | SELECT STATEMENT                      |               |     1 |    78 |     3  (34)| 00:00:01 |                                                                                                                                                   
  |   1 |  SORT ORDER BY                        |               |     1 |    78 |     3  (34)| 00:00:01 |                                                                                                                                                   
  |   2 |   NESTED LOOPS OUTER                  |               |     1 |    78 |     2   (0)| 00:00:01 |                                                                                                                                                   
  |   3 |    TABLE ACCESS BY INDEX ROWID        | OWNERS        |     1 |    55 |     1   (0)| 00:00:01 |                                                                                                                                                   
  |*  4 |     INDEX UNIQUE SCAN                 | SYS_C008660   |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                   
  |   5 |    TABLE ACCESS BY INDEX ROWID BATCHED| PETS          |     1 |    23 |     1   (0)| 00:00:01 |                                                                                                                                                   
  |*  6 |     INDEX RANGE SCAN                  | PETS_OWNER_ID |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                   
  -------------------------------------------------------------------------------------------------------                                                                                                                                                   

  Predicate Information (identified by operation id):                                                                                                                                                                                                       
  ---------------------------------------------------                                                                                                                                                                                                       
     4 - access("O1_0"."ID"=:1)                                                                                                                                                                                                                             
     6 - access("P1_0"."OWNER_ID"(+)=:1)

This required some changes to the DatabaseVendor interface.

  • Added the isExplainPlanFollowupQueryRequired method that will return true if a followup query is required for the explain plan rows
  • Added the getFollowupExplainPlanSql method that will return the SQL required to run if a followup query is required

The logic in the ExplainPlanExecutor has been updated to support the followup query flow, if required.

Added additional tests for the new followup query methods.

@codecov-commenter

codecov-commenter commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.86%. Comparing base (2884d1c) to head (59c7a4b).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
...lic/agent/bridge/datastore/JdbcDatabaseVendor.java 33.33% 2 Missing ⚠️
...database/PreparedStatementExplainPlanExecutor.java 71.42% 2 Missing ⚠️
...lic/agent/bridge/datastore/ExplainPlanSqlInfo.java 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3080      +/-   ##
============================================
- Coverage     70.93%   70.86%   -0.08%     
- Complexity    10687    10711      +24     
============================================
  Files           871      874       +3     
  Lines         43010    43160     +150     
  Branches       6506     6527      +21     
============================================
+ Hits          30511    30584      +73     
- Misses         9555     9616      +61     
- Partials       2944     2960      +16     

☔ 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.

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

Labels

None yet

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

Explain Support for Oracle DB

3 participants