In Oracle Database 19c, use DBMS_XPLAN.DISPLAY_CURSOR to see the plan of a cursor that actually executed. Collect row-source statistics for the statement, then request ALLSTATS LAST and compare estimated rows with observed rows for the same operation. EXPLAIN PLAN does not show runtime row counts.
Untested: This example uses SQL*Plus and Oracle Database 19c on Linux. Use a test session in the PDB that contains the sample table. Do not rerun expensive production SQL just to collect plan statistics.
Before you start
The example assumes you are connected as the owner of a small test table named orders_demo with an order_status column. Ask the DBA to confirm you can execute DBMS_XPLAN and have the documented SELECT or READ access to V$SQL, V$SQL_PLAN, V$SESSION, and V$SQL_PLAN_STATISTICS_ALL. Use scoped access rather than granting broad privileges just for this exercise. See how to connect with SQL*Plus if you need a client setup.
1. Run and fetch the example query
The GATHER_PLAN_STATISTICS hint asks Oracle to collect runtime statistics for this statement. Fetch all rows, then run the next step in the same SQL*Plus session without issuing other SQL in between.
SELECT /*+ GATHER_PLAN_STATISTICS */ order_status
FROM orders_demo
WHERE order_status = 'OPEN';
2. Display the cursor plan
SELECT plan_table_output
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(format => 'ALLSTATS LAST'));
When you omit the SQL ID, the function uses the last cursor executed by the session. Confirm that the SQL text shown is the statement you intended. When investigating a different cursor, supply both its SQL ID and its child cursor number. LAST requests statistics for that cursor’s last execution, not a history of executions or a guarantee that the counts belong to your session if other sessions share the cursor.
3. Compare the rows at each operation
| Column | What to check |
|---|---|
| E-Rows | The optimizer’s estimated output rows per start for the operation. |
| A-Rows | Total output rows observed for that operation in the reported execution. |
| Starts | How often the operation started. In this serial example, if it started multiple times, compare average observed rows per start with the estimate. |
Start with an active operation near the leaves that shows a large discrepancy. Read its predicates and check whether the estimate is affected by the data distribution, missing or stale statistics, or correlated filters. A discrepancy is a lead to investigate, not proof that a new index will help.
Troubleshoot missing or misleading statistics
- No A-Rows: Check that statistics were collected for the execution you are inspecting, that you fetched the complete result, and that you selected the right child cursor.
ALLSTATS LASTdisplays available statistics; it does not collect them retroactively. - Unexpected SQL text: A client may issue SQL between your query and the display call. Use the known SQL ID and child number instead of the last-cursor shortcut.
- Cursor unavailable:
DISPLAY_CURSORreads cached cursors. This method cannot retrieve a cursor that has aged out or one cached only on another instance. - Operation did not start: Do not interpret zero starts as a row estimate error for that operation.
This walkthrough reads the cursor cache; it does not use AWR or SQL Monitoring. For broader diagnosis, see Oracle performance optimization.
Further reading
As an Amazon Associate I earn from qualifying purchases.
Christian Antognini’s Troubleshooting Oracle Performance (Amazon affiliate link) covers execution plans and how to investigate slow SQL. This edition predates Oracle Database 19c; use the Oracle references below for release-specific syntax and privileges.
