Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a performance improvement when using JOIN vs a WHERE clause? [duplicate]

Tags:

sql

oracle

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;
like image 354
HardLeeWorking Avatar asked Jan 08 '16 12:01

HardLeeWorking


People also ask

Are joins more efficient than WHERE?

“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.

Does join improve performance?

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.

Is it faster to filter on join or WHERE clause?

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.

Does WHERE clause improve performance?

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.


1 Answers

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.

like image 70
Rahul Tripathi Avatar answered Sep 19 '22 03:09

Rahul Tripathi