나는 다음과 같은 스키마가 있다면, 의미하는 것 : 내가 B_data
과 여기에 설명 된 관계를 사용하여 C_data
를 검색하고 싶다면는 SQL 내부의 테이블 조인 '건너 뛰기'
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
);
을, 어떤 차이 사이가 다음
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;
내가 SUS 대부분의 데이터베이스는 쿼리가 동일하게 최적화 될 것이지만, tableA
에 대한 외래 키 제약은 tableA
을 통해 훨씬 효율적으로 합류 할 수 있습니까? 이 쿼리가 다른 결과를 낼 수있는 경우가 있습니까?