Inner join vs Where

2018-12-31 09:34发布

Is there a difference in performance (in oracle) between

Select * from Table1 T1 
Inner Join Table2 T2 On T1.ID = T2.ID

And

Select * from Table1 T1, Table2 T2 
Where T1.ID = T2.ID

?

18条回答
旧人旧事旧时光
2楼-- · 2018-12-31 09:35

It is true that, functionally, both queries should be processed the same way. However, experience has shown that if you are selecting from views that use the new join syntax, it is important to structure your queries using it as well. Oracle's optimizer can get confused if a view uses a "join" statement, but a query accessing the view uses the traditional method of joining in the "where" clause.

查看更多
宁负流年不负卿
3楼-- · 2018-12-31 09:37

The performance should be identical, but I would suggest using the join-version due to improved clarity when it comes to outer joins.

Also unintentional cartesian products can be avoided using the join-version.

A third effect is an easier to read SQL with a simpler WHERE-condition.

查看更多
残风、尘缘若梦
4楼-- · 2018-12-31 09:37

Functionally they are the same as has been said. I agree though that doing the join is better for describing exactly what you want to do. Plenty of times I've thought I knew how I wanted to query something until I started doing the joins and realized I wanted to do a different query than the original one in my head.

查看更多
时光乱了年华
5楼-- · 2018-12-31 09:39

In a scenario where tables are in 3rd normal form, joins between tables shouldn't change. I.e. join CUSTOMERS and PAYMENTS should always remain the same.

However we must distinguish joins from filters. Joins are about relationships and filters are about partitioning a whole.

SQL-92 syntax encourages us to separate both concepts and it's preferred over old syntax that put both, joins and filters, on WHERE clause which is more cumbersome.

查看更多
ら面具成の殇う
6楼-- · 2018-12-31 09:40

[For a bonus point...]

Using the JOIN syntax allows you to more easily comment out the join as its all included on one line. This can be useful if you are debugging a complex query

As everyone else says, they are functionally the same, however the JOIN is more clear of a statement of intent. It therefore may help the query optimiser either in current oracle versions in certain cases (I have no idea if it does), it may help the query optimiser in future versions of Oracle (no-one has any idea), or it may help if you change database supplier.

查看更多
旧人旧事旧时光
7楼-- · 2018-12-31 09:40

They're both inner joins that do the same thing, one simply uses the newer ANSI syntax.

查看更多
登录 后发表回答