row source 통계와 함께 실제 실행 계획 조회(ALLSTATS LAST)
Oracle성능명령어
-- 1) Collect row source statistics (for this query only):
SET SERVEROUTPUT OFF
SELECT /*+ gather_plan_statistics */ customer_id, SUM(amount)
FROM customer_app.sales
WHERE created_at >= DATE '2026-06-01'
GROUP BY customer_id;
-- or for the whole session: ALTER SESSION SET statistics_level = ALL;
-- 2) Plan of the last cursor run in the same session (E-Rows vs A-Rows):
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(
sql_id => NULL,
cursor_child_no => NULL,
format => 'ALLSTATS LAST +PEEKED_BINDS +OUTLINE'));
-- 3) A cursor from another session / from earlier:
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('<sql_id>', NULL, 'ALLSTATS LAST +PEEKED_BINDS'));하는 일
EXPLAIN PLAN은 추정치다. 이 방법은 실제로 실행된 계획을 단계별 Starts, E-Rows(추정), A-Rows(실제), A-Time, Buffers, 메모리 사용량과 함께 보여 준다. 카디널리티 오추정이 시작되는 단계를 찾는 가장 직접적인 방법이다.
사용 시점
단일 느린 SQL 튜닝, 통계/히스토그램 필요성 증명, 힌트나 인덱스 변경 효과 측정 시.
주의
라이선스가 필요 없다. SET SERVEROUTPUT ON 상태에서는 sql_id=>NULL이 DBMS_OUTPUT 호출을 마지막 커서로 보여 주므로 먼저 OFF로 설정한다. statistics_level=ALL을 시스템 전체에 활성화하지 않는다. 눈에 띄는 CPU 오버헤드가 생긴다. 힌트는 SQL 텍스트를 바꾸므로 새 sql_id가 된다. 사용자는 V$SQL_PLAN_STATISTICS_ALL에 대한 읽기 권한(SELECT_CATALOG_ROLE)이 필요하다.