[TL; DR] Нет разницы в EXPLAIN PLAN
для двух запросов;они оцениваются одинаково.
Данные испытаний :
CREATE TABLE employee ( firstname ) AS
SELECT CHR( 64 + level ) FROM DUAL CONNECT BY LEVEL <= 26;
Объяснить планы :
EXPLAIN PLAN FOR
select * from EMPLOYEE where FIRSTNAME = 'X' and rownum <5;
SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());
выходы:
| PLAN_TABLE_OUTPUT |
| :------------------------------------------------------------------------------ |
| Plan hash value: 3463100252 |
| |
| ------------------------------------------------------------------------------- |
| | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | |
| ------------------------------------------------------------------------------- |
| | 0 | SELECT STATEMENT | | 1 | 4 | 3 (0)| 00:00:01 | |
| |* 1 | COUNT STOPKEY | | | | | | |
| |* 2 | TABLE ACCESS FULL| EMPLOYEE | 1 | 4 | 3 (0)| 00:00:01 | |
| ------------------------------------------------------------------------------- |
| |
| Predicate Information (identified by operation id): |
| --------------------------------------------------- |
| |
| 1 - filter(ROWNUM<5) |
| 2 - filter("FIRSTNAME"='X') |
| |
| Note |
| ----- |
| - dynamic sampling used for this statement (level=2) |
и
EXPLAIN PLAN FOR
select * from EMPLOYEE where rownum <5 and FIRSTNAME = 'X';
SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());
выходы:
| PLAN_TABLE_OUTPUT |
| :------------------------------------------------------------------------------ |
| Plan hash value: 3463100252 |
| |
| ------------------------------------------------------------------------------- |
| | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | |
| ------------------------------------------------------------------------------- |
| | 0 | SELECT STATEMENT | | 1 | 4 | 3 (0)| 00:00:01 | |
| |* 1 | COUNT STOPKEY | | | | | | |
| |* 2 | TABLE ACCESS FULL| EMPLOYEE | 1 | 4 | 3 (0)| 00:00:01 | |
| ------------------------------------------------------------------------------- |
| |
| Predicate Information (identified by operation id): |
| --------------------------------------------------- |
| |
| 1 - filter(ROWNUM<5) |
| 2 - filter("FIRSTNAME"='X') |
| |
| Note |
| ----- |
| - dynamic sampling used for this statement (level=2) |
дБ <>fiddle здесь
Как вы можете видеть, движок Oracle Oracle генерирует одинаковые планы для обоих запросов и будет оценивать их одинаково;нет разницы с порядком выражений в предложении WHERE
.