つまり、次のスキーマがある場合:
create table tableA(
A_id number not null primary key
);
create table tableB(
B_id number not null primary key,
A_id number not null references tableA(A_id),
B_data text not null
);
create table tableC(
C_id number not null primary key,
A_id number not null references tableA(A_id),
C_data text not null
);
B_data
ここで説明されている関係を取得して使用したい場合、次の間にC_data
違いはありますか?
select
b.B_data,
c.C_data
from
tableB b
inner join tableC c
on b.A_id = c.A_id;
と:
select
b.B_data,
c.C_data
from
tableB b
inner join tableA a
on b.A_id = a.A_id
inner join tableC c
on a.A_id = c.A_id;
ほとんどのデータベースはどちらのクエリも同じになるように最適化すると思いますが、外部キーの制約により、tableA
経由での結合がtableA
はるかに効率的になる場合がありますか?これらのクエリが異なる結果を生成する可能性がある場合はありますか?