Unix Technical Forum

A performance question in select statement

This is a discussion on A performance question in select statement within the MySQL forums, part of the Database Server Software category; --> In response to my last question, Captain Paralytic send a diferente select statement to me. My own select was ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:24 AM
rics
 
Posts: n/a
Default A performance question in select statement

In response to my last question, Captain Paralytic send a diferente
select statement to me. My own select was like this:


SELECT u.id, u.usuario, g.grupo
FROM usuarios u, grupos g, usuarios_grupos ug
WHERE u.id = ug.usuario_id AND g.id = ug.grupo_id


The select of Captain Paralytic was like this:


SELECT u.id, u.usuario, g.grupo
FROM usuarios_grupos ug
JOIN usuarios u ON ug.usuario_id = u.id
JOIN grupos g ON ug.grupo_id = g.id


They return exactly the same results, so my question now is: Is there
any performance issue that I'm missing, or the two statements are
pretty much the same? Is all about syntax only? Which aproach is
better??? Why???

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:24 AM
Captain Paralytic
 
Posts: n/a
Default Re: A performance question in select statement

On 15 Mar, 14:40, "rics" <ricardo.ce...@gmail.com> wrote:
> In response to my last question, Captain Paralytic send a diferente
> select statement to me. My own select was like this:
>
> SELECT u.id, u.usuario, g.grupo
> FROM usuarios u, grupos g, usuarios_grupos ug
> WHERE u.id = ug.usuario_id AND g.id = ug.grupo_id
>
> The select of Captain Paralytic was like this:
>
> SELECT u.id, u.usuario, g.grupo
> FROM usuarios_grupos ug
> JOIN usuarios u ON ug.usuario_id = u.id
> JOIN grupos g ON ug.grupo_id = g.id
>
> They return exactly the same results, so my question now is: Is there
> any performance issue that I'm missing, or the two statements are
> pretty much the same? Is all about syntax only? Which aproach is
> better??? Why???


If you do an explain on the 2 selects you will find that in this case
they are likely to be identical.

My proposed query was more obvious in its intentions. Also, my one can
easily be altered to use LEFT JOINs should the need arrive.

I used to write all joins as you had and asked a similar question to
this one on this very newsgroup. I have now spent so long using the
JOIN syntax that I find it hard to figure out at a glance what the
other syntax is doing.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:13 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com