dbTalk Databases Forums  

Which is more performance-friendly: JOIN ON or JOIN USING?

comp.databases.postgresql comp.databases.postgresql


Discuss Which is more performance-friendly: JOIN ON or JOIN USING? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pedro
 
Posts: n/a

Default Which is more performance-friendly: JOIN ON or JOIN USING? - 10-27-2010 , 11:08 AM






Friends at the PostgreSQL group:

After a long search* I could not find an answer for the following
question yet:

Which is more performance-friendly: JOIN ON or JOIN USING?

* The word USING is too much used and it ends up in a flood of endless
not-related results.

Thank you in advance for your help.

Kind regards,
Pedro.

Reply With Quote
  #2  
Old   
Matthew Woodcraft
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 10-27-2010 , 01:04 PM






Pedro <pedrokarneiro (AT) gmail (DOT) com> wrote:
Quote:
Which is more performance-friendly: JOIN ON or JOIN USING?
There's no difference in performance. They're just two different ways
of writing the same thing.

-M-

Reply With Quote
  #3  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 10-27-2010 , 01:20 PM



On Wed, 27 Oct 2010 09:08:20 -0700, Pedro wrote:


Quote:
Which is more performance-friendly: JOIN ON or JOIN USING?
Definitely "JOIN ON". The "JOIN USING" needs more typing and I am a
terrible typist.



--
http://mgogala.freehostia.com

Reply With Quote
  #4  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 10-27-2010 , 02:41 PM



On 2010-10-27 20:20, Mladen Gogala wrote:
Quote:
On Wed, 27 Oct 2010 09:08:20 -0700, Pedro wrote:


Which is more performance-friendly: JOIN ON or JOIN USING?

Definitely "JOIN ON". The "JOIN USING" needs more typing and I am a
terrible typist.
What is the average length of the column name(s) that you use in the on
clause ;-)

/Lennart

Reply With Quote
  #5  
Old   
Pedro
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 10-28-2010 , 07:08 AM



On 27 out, 15:41, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com>
wrote:
Quote:
On 2010-10-27 20:20, Mladen Gogala wrote:

On Wed, 27 Oct 2010 09:08:20 -0700, Pedro wrote:

Which is more performance-friendly: JOIN ON or JOIN USING?

Definitely "JOIN ON". The "JOIN USING" needs more typing and I am a
terrible typist.

What is the average length of the column name(s) that you use in the on
clause ;-)

/Lennart
Thank you guys for the fun.
Anyway this is serious for the community that need to set some
standards for the simplicity and benefit of all those that deal with
mission critical and giant databases.
Despite both JOIN ON and JOIN USING are found in ANSI SQL 92, their
executions are performed differently from one another. In my oppinion
there is some metadata query behind the scenes for JOIN USING, but I
will have to proof it.
Back to the lab.
Cheers.

Reply With Quote
  #6  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 10-28-2010 , 09:48 AM



On Thu, 28 Oct 2010 05:08:52 -0700, Pedro wrote:

Quote:
Thank you guys for the fun.
Anyway this is serious for the community that need to set some standards
for the simplicity and benefit of all those that deal with mission
critical and giant databases. Despite both JOIN ON and JOIN USING are
found in ANSI SQL 92, their executions are performed differently from
one another.
How so? That is not my experience. Can you present two plans that are
different? I even tested with the following queries:

select e.ename,e.job,e.sal,d.dname,d.loc
from emp e join dept d using (deptno)
order by e.deptno

and

select e.ename,e.job,e.sal,d.dname,d.loc
from emp e join dept d on (e.deptno=d.deptno)
order by e.deptno

The plans were exactly the same:
QUERY
PLAN
--------------------------------------------------------------------------------------------------------------
Merge Join (cost=2.49..2.71 rows=14 width=28) (actual time=0.032..0.041
rows=14 loops=1)
Merge Cond: (d.deptno = e.deptno)
-> Sort (cost=1.08..1.09 rows=4 width=18) (actual time=0.013..0.013
rows=4 loops=1)
Sort Key: d.deptno
Sort Method: quicksort Memory: 25kB
-> Seq Scan on dept d (cost=0.00..1.04 rows=4 width=18)
(actual time=0.003..0.005 rows=4 loops=1)
-> Sort (cost=1.41..1.44 rows=14 width=12) (actual time=0.017..0.020
rows=14 loops=1)
Sort Key: e.deptno
Sort Method: quicksort Memory: 25kB
-> Seq Scan on emp e (cost=0.00..1.14 rows=14 width=12)
(actual time=0.002..0.009 rows=14 loops=1)
Total runtime: 0.082 ms
(11 rows)

QUERY
PLAN
--------------------------------------------------------------------------------------------------------------
Merge Join (cost=2.49..2.71 rows=14 width=28) (actual time=0.031..0.042
rows=14 loops=1)
Merge Cond: (d.deptno = e.deptno)
-> Sort (cost=1.08..1.09 rows=4 width=18) (actual time=0.012..0.012
rows=4 loops=1)
Sort Key: d.deptno
Sort Method: quicksort Memory: 25kB
-> Seq Scan on dept d (cost=0.00..1.04 rows=4 width=18)
(actual time=0.003..0.006 rows=4 loops=1)
-> Sort (cost=1.41..1.44 rows=14 width=12) (actual time=0.017..0.019
rows=14 loops=1)
Sort Key: e.deptno
Sort Method: quicksort Memory: 25kB
-> Seq Scan on emp e (cost=0.00..1.14 rows=14 width=12)
(actual time=0.002..0.006 rows=14 loops=1)
Total runtime: 0.078 ms
(11 rows)


If you have an example of differing plans, I would be very keen to learn
about it. In other words, if you want a serious discussion, please
provide some background information.



--
http://mgogala.freehostia.com

Reply With Quote
  #7  
Old   
Jasen Betts
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 11-02-2010 , 04:22 AM



On 2010-10-27, Pedro <pedrokarneiro (AT) gmail (DOT) com> wrote:
Quote:
Friends at the PostgreSQL group:

After a long search* I could not find an answer for the following
question yet:

Which is more performance-friendly: JOIN ON or JOIN USING?

* The word USING is too much used and it ends up in a flood of endless
not-related results.

Thank you in advance for your help.
"Join on" is faster because the docs sat that "join using" is translated
into "join on". That translation is an extra step
But probably not _measurably_ faster.


otoh: "using" may get you fewer columns in the result set, so that could
be faster if the result set is large and bandwidth not.

--
ɹǝpun uʍop ɯoɹɟ sƃuıʇǝǝɹ⅁

Reply With Quote
  #8  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 11-02-2010 , 08:36 AM



On 2010-11-02 11:22, Jasen Betts wrote:
[...]
Quote:
otoh: "using" may get you fewer columns in the result set, so that could
be faster if the result set is large and bandwidth not.

How does the join clause affect the number of columns in the result?

/Lennart

Reply With Quote
  #9  
Old   
Pedro
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 11-02-2010 , 09:50 PM



On 2 nov, 10:36, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com>
wrote:
Quote:
On 2010-11-02 11:22, Jasen Betts wrote:
[...]



otoh: "using" may get you fewer columns in the result set, so that could
be faster if the result set is large and bandwidth not.

How does the join clause affect the number of columns in the result?

/Lennart
Friends, thank you for the useful information.

Reply With Quote
  #10  
Old   
Jasen Betts
 
Posts: n/a

Default Re: Which is more performance-friendly: JOIN ON or JOIN USING? - 11-06-2010 , 10:35 PM



On 2010-11-02, Lennart Jonsson <erik.lennart.jonsson (AT) gmail (DOT) com> wrote:
Quote:
On 2010-11-02 11:22, Jasen Betts wrote:
[...]

otoh: "using" may get you fewer columns in the result set, so that could
be faster if the result set is large and bandwidth not.

How does the join clause affect the number of columns in the result?
The column(s) joined on only appear(s) once if the request was "select * ..."

--
ɹǝpun uʍop ɯoɹɟ sƃuıʇǝǝɹ⅁

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.