-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Best practice querying
PostPosted: Fri Jun 02, 2006 2:58 pm 
Newbie

Joined: Fri Jun 02, 2006 2:34 pm
Posts: 2
Hi, I'm rather new to hibernate (i know how to use it, but no deeper understandings of the mechanics) and have run into a problem.

I have the problem that I'm not sure what gives the best performance of either retrieving whole objects/tables from the database or only retrieving the specific columns that are required for a specific piece of functionality.

I keep telling myself that if the columns in a table are used in different functionalities, then it might be better performance-wise to retrieve whole objects/tables, since it will only be retrieved once from the database and following queries will be fetched from the cache. Whereas seperate queries will be executed if I retrieve different columns from the same table.

So, are there any guidelines as to what is best practice when querying for data?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 4:02 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
Quote:
So, are there any guidelines as to what is best practice when querying for data?

Doesn't it depend on your application?

Say you have two related objects A and B. If when A is retrieved and used, B is almost always used with it, then it makes sense to retrieve both in one shot, but if B is not used so often, then it makes sense to lazy-load it.

Don't worry so much about performance optimization until you have to. It's a waste of your time and the bottleneck usually isn't where you think it is. :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 03, 2006 3:42 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

Can you give more specific details than giving us generic details.

It would helps us to help you out whether optimization is required or not.

I would like to differ with the other poster
Beauty of a programmer is when you write a clean and performance oriented code which keeps you application faster and easy to maintain.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 04, 2006 12:40 pm 
Newbie

Joined: Fri Jun 02, 2006 2:34 pm
Posts: 2
Hi again, I'll try to be a bit more specific then ;-)

Here's a snapshot of a table in the database(mysql), which is used on a website:

Image

Where text columns can be up to 65656 chars and "owner" is a FK

These are some of the scenarios where data needs to be retrieved:

1. all columns

2. teamid, teamname, division

3. bio

4. logo

5. teamname, logo, rating, division

6. teamname, rating

7. teamid, teamname, logo, divison, owner

8. teamid, reroll, ff, asscoach, cheer, apo, wizard

9. teamid, teamname, race, rating, treasury, owner

10. teamname

As to the frequency of them i cannot say since I don't have any statistics at hand.
I hope it can help clear up some confusion =)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 12:57 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

After looking through the table. I can figure out that you do quite lot of operations based on a single table.

To Optimize:
1) Lazy Load the Associations.
2) If your table value will not be modified frequently then you load the full object/table and then can get the values from the cache.
3) If your table is updated so often, then you can get values of specific column, It increases your performance.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.