Is there a performance difference (or any other reason) to use a JOIN instead of a WHERE clause as per the code examples below:
ex1.
select *
from table_1, table_2
where table_1.id=table_2.id;
ex2.
select *
from table_1
join table_2 on
table_1.id = table_2.id;
“Is there a performance difference between putting the JOIN conditions in the ON clause or the WHERE clause in MySQL?” No, there's no difference. The following queries are algebraically equivalent inside MySQL and will have the same execution plan.
Basically, join order DOES matter because if we can join two tables that will reduce the number of rows needed to be processed by subsequent steps, then our performance will improve.
I ran some tests and the results show that it is actually very close, but the WHERE clause is actually slightly faster! =) I absolutely agree that it makes more sense to apply the filter on the WHERE clause, I was just curious as to the performance implications.
A where clause will generally increase the performance of the database. Generally, it is more expensive to return data and filter in the application. The database can optimize the query, using indexes and partitions. The database may be running in parallel, executing the query in parallel.
You can refer: Bad habits to kick : using old-style JOINs(The link is for SQL Server but most of the points are valid for Oracle as well). Comma seperated JOINS are now discouraged. You should use the second format of JOINS as it is more readable and also it is highly recommended and widely used nowadays. And as far as performance is concerned there is no difference between the two syntax. Also the first format of JOINS (ie, the comma seperated) is pre - 1992 standard SQL join syntax.
Also in case of Oracle, when you had to use LEFT JOINS OR RIGHT JOINS then you had to use the old style of using (+) which was used to identify the table that is being outer joined to. So it was confusing and makes the query less readable. So the use of explicit JOINS(version 2 in your case) makes it more easier to understand and much readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With