通常这样写很方便:
SELECT *
FROM t1 # ... +many more tables
INNER JOIN t2 ON (t1.id = t2.col)
INNER JOIN t3 ON (t1.id = t3.col)
INNER JOIN t4 ON (t1.id = t4.col)
...
Run Code Online (Sandbox Code Playgroud)
作为带条件的交叉连接:
SELECT *
FROM t1, t2, t3, t4 # ... +many more tables
WHERE
t1.id = t2.col
AND t1.id = t3.col
AND t1.id = t4.col
# +include matches on columns of other tables
Run Code Online (Sandbox Code Playgroud)
但是,交叉连接的简单实现将比内部连接具有更高的时间复杂度。Postgres 是否将第二个查询优化为与第一个查询具有相同时间复杂度的查询?