Most Efficient Join

This is a discussion on Most Efficient Join within the MySQL Database forums, part of the Database Forums category; Hi all, I have a user table and an object table (for project and properties at the moment). I can ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-12-2006
amykimber@gmail.com
 
Posts: n/a
Default Most Efficient Join

Hi all,

I have a user table and an object table (for project and properties at
the moment). I can get a list of all my Project Objects with the user
that created them by doing this...

select * from tbl_object join tbl_user on tbl_user.user_id =
tbl_object.created_by where object_type = 1 #1 being project type

Lovely.

Now, technically a User is also an object (as is just about everything
else in our application), but how efficient is it to have 'everything'
in the one table and keep joining that to itself?

select * from tbl_object tbl_object_project
join tbl_object tbl_object_user on tbl_object_user.value =
tbl_object_project.created_by
and tbl_object_user.object_type = 5 #user type
where tbl_object_project = 1 #1 being project type

Part of me thinks that a user is an object and should be in the object
table, and another part thinks it is just too clunky to keep joining
tbl_object to tbl_object.

What are you thoughts? Which is considered "technically" correct? Has
anyone been down this road before? And, probably the most important
question - which method is the most efficient?

Eventually there will be a lot of data in the db, so efficiency will
become more important.

Many thanks,

Amy

Reply With Quote
  #2 (permalink)  
Old 09-12-2006
Jerry Stuckle
 
Posts: n/a
Default Re: Most Efficient Join

amykimber@gmail.com wrote:
> Hi all,
>
> I have a user table and an object table (for project and properties at
> the moment). I can get a list of all my Project Objects with the user
> that created them by doing this...
>
> select * from tbl_object join tbl_user on tbl_user.user_id =
> tbl_object.created_by where object_type = 1 #1 being project type
>
> Lovely.
>
> Now, technically a User is also an object (as is just about everything
> else in our application), but how efficient is it to have 'everything'
> in the one table and keep joining that to itself?
>
> select * from tbl_object tbl_object_project
> join tbl_object tbl_object_user on tbl_object_user.value =
> tbl_object_project.created_by
> and tbl_object_user.object_type = 5 #user type
> where tbl_object_project = 1 #1 being project type
>
> Part of me thinks that a user is an object and should be in the object
> table, and another part thinks it is just too clunky to keep joining
> tbl_object to tbl_object.
>
> What are you thoughts? Which is considered "technically" correct? Has
> anyone been down this road before? And, probably the most important
> question - which method is the most efficient?
>
> Eventually there will be a lot of data in the db, so efficiency will
> become more important.
>
> Many thanks,
>
> Amy
>


Amy,

Well, when you get right down to it, everything in the world is an
"object". But that doesn't mean you should keep automobiles in the same
table as tuna. IOW, you can abstract something too much. You need to
look at the attributes of each object.

Without more information on what your "objects" are, it's difficult to
tell whether things should be in the same table or not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:03 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0