// oracle · query planner

optimizer_mode

Optimizer goal: total throughput (ALL_ROWS) or fastest first rows.

預設
ALL_ROWS
Range
ALL_ROWS, FIRST_ROWS_1, FIRST_ROWS_10, FIRST_ROWS_100, FIRST_ROWS_1000, FIRST_ROWS
Restart needed
否
Default checked on
Oracle AI Database 26ai / 23ai

其作用

FIRST_ROWS_n optimizes for returning the first n rows quickly (n = 1, 10, 100, 1000), which favors nested loops and index access.

預設值

ALL_ROWS. ALL_ROWS (Oracle 23ai/26ai).

Check the current value

SHOW PARAMETER optimizer_mode

SELECT name, value, isdefault, issys_modifiable, isses_modifiable, ispdb_modifiable
FROM v$parameter
WHERE name = 'optimizer_mode';

Change it

ALTER SESSION SET optimizer_mode = FIRST_ROWS_10;   -- this session

ALTER SYSTEM SET optimizer_mode = FIRST_ROWS_10 SCOPE=BOTH;

No restart: ALTER SYSTEM with SCOPE=BOTH applies immediately and is saved in the SPFILE. A session can also change its own value with ALTER SESSION. It can be set inside a PDB (ISPDB_MODIFIABLE = TRUE).

When to change it

Per session for interactive applications that show the first page of results; leave the instance on ALL_ROWS.

What can go wrong

Instance-wide FIRST_ROWS can make batch and reporting plans much slower.

Questions about optimizer_mode

What is the default value of optimizer_mode in Oracle?

ALL_ROWS. ALL_ROWS (Oracle 23ai/26ai).

Does changing optimizer_mode require a restart?

No. No restart: ALTER SYSTEM with SCOPE=BOTH applies immediately and is saved in the SPFILE. A session can also change its own value with ALTER SESSION. It can be set inside a PDB (ISPDB_MODIFIABLE = TRUE).

When should I change optimizer_mode?

Per session for interactive applications that show the first page of results; leave the instance on ALL_ROWS.

Back to all Oracle settings, or check the Oracle manual for every option.

// one client for every engine

Check optimizer_mode on your own server

SQLly runs the query above against Oracle and the other engines in this reference, from one desktop app on macOS, Windows and Linux.