【发布时间】:2009-07-29 11:48:20
【问题描述】:
我的意思是,如果我有以下架构:
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 的连接效率更高?是否存在这些查询可能产生不同结果的情况?
【问题讨论】:
标签: sql join inner-join