where 句の順序は重要ではありません。ANSI JOIN 構文は読みやすさを向上させますが、パフォーマンスには影響しません。ポイントを証明するには:
create table t1 (a number, x number);
create table t2 (a number, b number);
insert into t1 (a, x) select level, mod(level,100) from dual connect by level <= 100000;
insert into t2 (a, b) select level, mod(level,10) from dual connect by level <= 100000;
exec dbms_stats.gather_table_stats(user,'t1');
exec dbms_stats.gather_table_stats(user,'t2');
set autotrace trace explain
4 つのクエリすべて
select t1.a, t2.b from t1, t2 where t1.a=t2.b and t1.x > 5 and t2.b > 5;
select t1.a, t2.b from t1, t2 where t1.a=t2.b and t2.b > 5 and t1.x > 5;
select t1.a, t2.b from t1, t2 where t1.x > 5 and t2.b > 5 and t1.a=t2.b;
select t1.a, t2.b from t1 join t2 on t1.a=t2.b where t1.x > 5 and t2.b > 5;
まったく同じクエリプランを生成する
Plan hash value: 282751716
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 44444 | 434K| 88 (7)| 00:00:02 |
|* 1 | HASH JOIN | | 44444 | 434K| 88 (7)| 00:00:02 |
|* 2 | TABLE ACCESS FULL| T2 | 44444 | 130K| 42 (5)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| T1 | 94946 | 649K| 44 (5)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("T1"."A"="T2"."B")
2 - filter("T2"."B">5)
3 - filter("T1"."X">5 AND "T1"."A">5)