In this article, Part 2 of the JDBC Peformance Series, John Goodson shows us how to optimize system performance by retrieving data efficiently. He looks at the costs of retrieving long data, how to reduce the size of the data retrieved, choosing the right data types when designing your schema, and gives tips on working with Result Sets.
Read Performance Tips for the Data Tier (JDBC) Part II - Retrieving Only Required Data
-
JDBC Performance Series: Retrieving Only Required Data (36 messages)
- Posted by: Nitin Bharti
- Posted on: May 04 2004 20:21 EDT
Threaded Messages (36)
- JDBC Performance Series: Retrieving Only Required Data by han theman on May 05 2004 03:53 EDT
- Better tips here by Falk Bruegmann on May 05 2004 05:13 EDT
- Speak for yourself Han by Marty Farrell on May 05 2004 05:15 EDT
- Speak for yourself Han by han theman on May 05 2004 06:06 EDT
-
Speak for yourself Han by Web Master on May 05 2004 08:57 EDT
- Speak for yourself Han by Alex Moffat on May 05 2004 09:07 EDT
-
Would have been useful to some by Dominique Archambault on May 05 2004 09:50 EDT
- Would have been useful to some by ABC DEF on May 05 2004 09:57 EDT
-
Would have been useful to some by han theman on May 05 2004 10:47 EDT
- Would have been useful to some by Dominique Archambault on May 05 2004 11:46 EDT
- Would have been useful to some by Mark N on May 05 2004 11:53 EDT
-
laugh all you want- yes I do by Rolf Tollerud on May 05 2004 10:51 EDT
-
well-meaning impractical theoreticans by Gavin King on May 05 2004 11:25 EDT
-
impractical theoreticans still florish by Rolf Tollerud on May 05 2004 12:46 EDT
-
He is doing it again by Henrique Steckelberg on May 05 2004 01:40 EDT
-
? by Rolf Tollerud on May 05 2004 02:26 EDT
- ? by Henrique Steckelberg on May 05 2004 03:46 EDT
-
? by Rolf Tollerud on May 05 2004 02:26 EDT
-
Meek Rolf Troll...er...Tollerud by Paul-Michael Bauer on May 05 2004 03:06 EDT
-
Meek Rolf Troll...er...Tollerud by Rolf Tollerud on May 05 2004 03:57 EDT
- Meek Rolf Troll...er...Tollerud by Paul-Michael Bauer on May 05 2004 05:10 EDT
-
Meek Rolf Troll...er...Tollerud by Rolf Tollerud on May 05 2004 03:57 EDT
- impractical theoreticans still florish by Juozas Baliuka on May 06 2004 05:17 EDT
- impractical theoreticans still florish by Robert Lowe on May 08 2004 07:21 EDT
-
He is doing it again by Henrique Steckelberg on May 05 2004 01:40 EDT
-
well-meaning impractical theoreticans by DODO DODO on May 05 2004 12:49 EDT
-
well-meaning impractical theoreticans by Rolf Tollerud on May 05 2004 01:05 EDT
- well-meaning impractical theoreticans by Robert Lowe on May 08 2004 07:29 EDT
-
well-meaning impractical theoreticans by Gavin King on May 05 2004 01:15 EDT
-
well-meaning impractical theoreticans by DODO DODO on May 05 2004 01:40 EDT
-
anonymous cowards by Gavin King on May 05 2004 01:52 EDT
- anonymous cowards by Mike Spille on May 05 2004 02:38 EDT
-
anonymous cowards by Gavin King on May 05 2004 01:52 EDT
-
well-meaning impractical theoreticans by DODO DODO on May 05 2004 01:40 EDT
-
well-meaning impractical theoreticans by Rolf Tollerud on May 05 2004 01:05 EDT
-
impractical theoreticans still florish by Rolf Tollerud on May 05 2004 12:46 EDT
-
well-meaning impractical theoreticans by Gavin King on May 05 2004 11:25 EDT
- It's no joke by peter lin on May 05 2004 10:41 EDT
- Newbie Site.... by Gurkan Erdogdu on May 05 2004 05:20 EDT
- Newbie Site.... by Michael Klaene on May 05 2004 09:41 EDT
- JDBC Performance Series: Retrieving Only Required Data by Web Master on May 05 2004 08:53 EDT
- Part 1 was good by me havename on May 05 2004 11:23 EDT
- JDBC Performance Series: Retrieving Only Required Data by Christian Bauer on May 05 2004 05:28 EDT
- JDBC Performance Series: Retrieving Only Required Data by ABC DEF on May 05 2004 09:49 EDT
-
JDBC Performance Series: Retrieving Only Required Data[ Go to top ]
- Posted by: han theman
- Posted on: May 05 2004 03:53 EDT
- in response to Nitin Bharti
That was 2 pages of trivialities... Is TheServerSide.com becoming *the* newbie site? -
Better tips here[ Go to top ]
- Posted by: Falk Bruegmann
- Posted on: May 05 2004 05:13 EDT
- in response to han theman
http://www.javaperformancetuning.com/tips/index.shtml
has more meat and less fluff, IMHO (see JDBC section).
P.S.: I'm not affiliated with that site in any way. -
Speak for yourself Han[ Go to top ]
- Posted by: Marty Farrell
- Posted on: May 05 2004 05:15 EDT
- in response to han theman
I found this article enlightening and interesting. I, along with the other developers on my team had no idea that performing full table scans on multi-million row tables using keyset cursors might be impacting performance negatively, I mean who would have thunk it?
It will be difficult for us though to change our field data types from all BLOBS. Computers deal in binary all the time so its a real eye opener to find out that other data types may actually yield higher performance.
The tips in the article may also help some of the issues we were having with our UI, its not easy to show three million results in a listbox to a user you know. Hopefully with more refined searching we will now only have to show them one million instead.
Apparently there is also something called indexing which we read about in the truly visionary "Learn how to be a DB Guru in 24 min's" and are interested in learning more about, its supposed to make selects faster or something, any chance we can have an article on that? -
Speak for yourself Han[ Go to top ]
- Posted by: han theman
- Posted on: May 05 2004 06:06 EDT
- in response to Marty Farrell
... my team had no idea that performing full table scans on multi-million row tables using keyset cursors might be impacting performance negatively, I mean who would have thunk it?
I read that as pure irony and I'm laughing my ass off ;-) -
Speak for yourself Han[ Go to top ]
- Posted by: Web Master
- Posted on: May 05 2004 08:57 EDT
- in response to Marty Farrell
... my team had no idea that performing full table scans on multi-million row tables using keyset cursors might be impacting performance negatively, I mean who would have thunk it?
Then you should consider taking some basic programing courses. -
Speak for yourself Han[ Go to top ]
- Posted by: Alex Moffat
- Posted on: May 05 2004 09:07 EDT
- in response to Web Master
It was sarcasm. Apparently the start sarcasm and end sarcasm tags were omitted. -
Would have been useful to some[ Go to top ]
- Posted by: Dominique Archambault
- Posted on: May 05 2004 09:50 EDT
- in response to Marty Farrell
Laugh all you want, some are completely clueless when it comes to databases. My team actually had to rewrite a system because those simple tips had not been followed by the original developers. Some entities had names that were localized (English and French), and the only solution they found was to store those names in a serialized HashMap within a BLOB (key=Locale, value=String). A maintenance nightmare for DBAs. -
Would have been useful to some[ Go to top ]
- Posted by: ABC DEF
- Posted on: May 05 2004 09:57 EDT
- in response to Dominique Archambault
Any enterprise developer worth his or her salt should be experienced in data modeling, relational DBs, and SQL. -
Would have been useful to some[ Go to top ]
- Posted by: han theman
- Posted on: May 05 2004 10:47 EDT
- in response to Dominique Archambault
Laugh all you want, some are completely clueless when it comes to databases. My team actually had to rewrite a system because those simple tips had not been followed by the original developers.
You see, the above article was like telling a carpenter how to use a hammer. So your team isn't very experienced, it seems, because the article contains REALLY basic stuff.
I don't want TheServerSide to become an newbie level forum. I want it to be a slashdot'ish site for the J2EE community. Hardcore stuff. Interesting news.
That's what TheServerSide has been all about. Keep it that way. -
Would have been useful to some[ Go to top ]
- Posted by: Dominique Archambault
- Posted on: May 05 2004 11:46 EDT
- in response to han theman
I totally agree with you. I prefer articles that go much deeper. Still, the original developers showed themselves as professional and experienced, even if they were clueless in this case.
I must admit that we did laugh a bit at the old system we had been given. I just hope the original developers got better experience now. I wouldn't want to clean up their mess again. :)
The client that had to pay for both the original system and the rewrite found it less funny of course. But that's another story. -
Would have been useful to some[ Go to top ]
- Posted by: Mark N
- Posted on: May 05 2004 11:53 EDT
- in response to han theman
There are many organizations where the DB knowledge is separated from the coders. This is most unfortunate yet a reality. So if you don't like it or need it - Ignore it. I would have like to have seen it labeled newbee or refresher. But oh well.Laugh all you want, some are completely clueless when it comes to databases. My team actually had to rewrite a system because those simple tips had not been followed by the original developers.
You see, the above article was like telling a carpenter how to use a hammer. So your team isn't very experienced, it seems, because the article contains REALLY basic stuff.I don't want TheServerSide to become an newbie level forum. I want it to be a slashdot'ish site for the J2EE community. Hardcore stuff. Interesting news. That's what TheServerSide has been all about. Keep it that way.
How much interesting/hardcore news has there been lately? I think these articles are more of a result of a slowdown in that area. -
laugh all you want- yes I do[ Go to top ]
- Posted by: Rolf Tollerud
- Posted on: May 05 2004 10:51 EDT
- in response to Dominique Archambault
If there is anybody that needs a crash course in SQL then it is the EJB/OR guys from the "Big Java Application Servers" domain that for the most part does not have a clue.
Besides, if I were them, I would thread very carefully, and lie low for 2 and 3 years, after the of enourmous overuse of Java EJB.
The only thing that match the stupitidy of "well-meaning impractical theoreticans" is their arrogance. :)
REgards
Rolf Tollerud -
well-meaning impractical theoreticans[ Go to top ]
- Posted by: Gavin King
- Posted on: May 05 2004 11:25 EDT
- in response to Rolf Tollerud
If there is anybody that needs a crash course in SQL then it is the EJB/OR guys from the "Big Java Application Servers" domain that for the most part does not have a clue.Besides, if I were them, I would thread very carefully, and lie low for 2 and 3 years, after the of enourmous overuse of Java EJB.The only thing that match the stupitidy of "well-meaning impractical theoreticans" is their arrogance.
Rolf, in your last contribution to a thread on data access, you argued in favor of storing date and time information in VARCHAR columns. If possible, would you please take this opportunity to now share some more of your great data access tips with we arrogant, stupid and impractical EJB/OR guys who are in such need of a crash course in SQL :-) -
impractical theoreticans still florish[ Go to top ]
- Posted by: Rolf Tollerud
- Posted on: May 05 2004 12:46 EDT
- in response to Gavin King
Yes I remember that discussion. I was just meekly pointing out that if you have an application that are going to use different databases, some unknown, it may be a good idea to use a string format for dates, ie YYYY-MM-DD (ISO).
In the resulting discussion some argued that then it was not possible to do date manipulations in the database! (=putting application logic into the backend :).
Sigh. Why do I bother?
Regards
Rolf Tollerud -
He is doing it again[ Go to top ]
- Posted by: Henrique Steckelberg
- Posted on: May 05 2004 13:40 EDT
- in response to Rolf Tollerud
In the resulting discussion some argued that then it was not possible to do date manipulations in the database! (=putting application logic into the backend :).Sigh.
Oh, I remember that. It was me. I was just wondering how to do a "SELECT * FROM ATABLE WHERE ADATE > '10/10/2002' ORDER BY ADATE", using a VARCHAR2 ADATE field, nothing more. I wouldn't call that application logic, unless you consider outer joins and result ordering/filtering application logic too.Why do I bother? Regards Rolf Tollerud
Lots of people have asked that too.
Regards,
Henrique Steckelberg -
?[ Go to top ]
- Posted by: Rolf Tollerud
- Posted on: May 05 2004 14:26 EDT
- in response to Henrique Steckelberg
Henrique,
How to do,
"SELECT * FROM ATABLE WHERE ADATE > '10/10/2002' ORDER BY ADATE"
this way,
"SELECT * FROM ATABLE WHERE ADATE > '2002-10-10' ORDER BY ADATE"
Not too difficult, do you think?
Regards
Rolf Tollerud -
?[ Go to top ]
- Posted by: Henrique Steckelberg
- Posted on: May 05 2004 15:46 EDT
- in response to Rolf Tollerud
Henrique,How to do,"SELECT * FROM ATABLE WHERE ADATE > '10/10/2002' ORDER BY ADATE"this way, "SELECT * FROM ATABLE WHERE ADATE > '2002-10-10' ORDER BY ADATE"Not too difficult, do you think?RegardsRolf Tollerud
In the example you gave using distributed databases, this simple solution could lead to problems, like character sets differences, blank-padded or non-padded comparison semantics differences, and so on. Much easier and safer to rely on the JDBC driver and prepared statements.
Regards,
Henrique Steckelberg -
Meek Rolf Troll...er...Tollerud[ Go to top ]
- Posted by: Paul-Michael Bauer
- Posted on: May 05 2004 15:06 EDT
- in response to Rolf Tollerud
I was just meekly pointing out that...blah blah blah
Rolf? meek?
This I have to see.
Could you post a link to this discussion? (lol) -
Meek Rolf Troll...er...Tollerud[ Go to top ]
- Posted by: Rolf Tollerud
- Posted on: May 05 2004 15:57 EDT
- in response to Paul-Michael Bauer
You are completly unfair. If I choose a nickname it could aptly be
"modesto". -
Meek Rolf Troll...er...Tollerud[ Go to top ]
- Posted by: Paul-Michael Bauer
- Posted on: May 05 2004 17:10 EDT
- in response to Rolf Tollerud
<grin> -
impractical theoreticans still florish[ Go to top ]
- Posted by: Juozas Baliuka
- Posted on: May 06 2004 05:17 EDT
- in response to Rolf Tollerud
It must be better to use some native format than to break data types,
but there is no porability problems with data formats in practice too.
Ask coworker or google before to break data, all data access problems are very old and have not broken solution.Yes I remember that discussion. I was just meekly pointing out that if you have an application that are going to use different databases, some unknown, it may be a good idea to use a string format for dates, ie YYYY-MM-DD (ISO).In the resulting discussion some argued that then it was not possible to do date manipulations in the database! (=putting application logic into the backend :).Sigh. Why do I bother?RegardsRolf Tollerud
-
impractical theoreticans still florish[ Go to top ]
- Posted by: Robert Lowe
- Posted on: May 08 2004 07:21 EDT
- in response to Rolf Tollerud
Sigh. Why do I bother?
I have absolutely no idea Rolf. Perhaps you should stop? -
well-meaning impractical theoreticans[ Go to top ]
- Posted by: DODO DODO
- Posted on: May 05 2004 12:49 EDT
- in response to Gavin King
I think I read once(very fast reading) in your blog that you don't really know the difference between a hash join and a nested loop. Is it true? Because then Rolf might have a point.If there is anybody that needs a crash course in SQL then it is the EJB/OR guys from the "Big Java Application Servers" domain that for the most part does not have a clue.Besides, if I were them, I would thread very carefully, and lie low for 2 and 3 years, after the of enourmous overuse of Java EJB.The only thing that match the stupitidy of "well-meaning impractical theoreticans" is their arrogance.
Rolf, in your last contribution to a thread on data access, you argued in favor of storing date and time information in VARCHAR columns. If possible, would you please take this opportunity to now share some more of your great data access tips with we arrogant, stupid and impractical EJB/OR guys who are in such need of a crash course in SQL :-) -
well-meaning impractical theoreticans[ Go to top ]
- Posted by: Rolf Tollerud
- Posted on: May 05 2004 13:05 EDT
- in response to DODO DODO
It is not any slight performance gain that is the question, but how to avoid all grief and sorrow with all the different date formats in the world. Not to speak of all the bugs there are in the tools in the date department, including Java.
But maybe people in US don't see this as a problem because they do not have that many international sites?
Regards
Rolf Tollerud -
well-meaning impractical theoreticans[ Go to top ]
- Posted by: Robert Lowe
- Posted on: May 08 2004 07:29 EDT
- in response to Rolf Tollerud
But maybe people in US don't see this as a problem because they do not have that many international sites?
Hmm--I work for a Hong Kong-based company with clients from all around Asia (including China, Japan, Korea, Thailand), Europe, Africa and South America as well as the US. Altogether we have clients in dozens of countries, and support about two dozen languages. We work with Sybase, Oracle and SQL Server.
I have not once seen a bug related to native database date/time types, or the related JDBC classes. I've certainly never seen a need to use text types for date formats.
Guess I've just been lucky--after all, Rolf couldn't be talking out of his ass, could he? -
well-meaning impractical theoreticans[ Go to top ]
- Posted by: Gavin King
- Posted on: May 05 2004 13:15 EDT
- in response to DODO DODO
I think I read once(very fast reading) in your blog that you don't really know the difference between a hash join and a nested loop. Is it true? Because then Rolf might have a point.
I'm quite confident of my understanding of the difference between the three types of joins. Thanks for your concern. (Perhaps you benefit by brushing up on your English comprehension skills.) Next :-) -
well-meaning impractical theoreticans[ Go to top ]
- Posted by: DODO DODO
- Posted on: May 05 2004 13:40 EDT
- in response to Gavin King
Really?I think I read once(very fast reading) in your blog that you don't really know the difference between a hash join and a nested loop. Is it true? Because then Rolf might have a point.
I'm quite confident of my understanding of the difference between the three types of joins. Thanks for your concern. (Perhaps you benefit by brushing up on your English comprehension skills.) Next :-)
Isn't this from your blog? And it seems pretty recent, April 2004. To me, at the moment it looked like you just brushed up your technical skills. Shouldn't I be concerned?
It's true that english is not my first language, but the phrase 'Perhaps you benefit...' doesn't sound right, maybe it misses a would or should or at least a 'd.
Anyway, it's good to know that we have a new Leonardo around:-)))If you ever work with relational databases, you should go out and buy O'Reilly's SQL Tuning, by Dan Tow. The book is all about how to represent a SQL query in a graphical form and then, using some simple rules of thumb, determine an optimal execution plan for the query. Once you have found the optimal execution plan, you can add indexes, query hints, or use some other tricks to persuade your database to use this execution plan. Fantastic stuff. There is even sufficient introductory material for those of us (especially me) who know less than we should about the actual technical details of full table scans, index scans, nested loops joins, hash joins, etcetera to be able to start feeling confident reading and understanding execution plans. Unlike most database books out there, this book is not very platform-specific, though it does often refer specifically to Oracle, DB2 and SQL Server.
-
anonymous cowards[ Go to top ]
- Posted by: Gavin King
- Posted on: May 05 2004 13:52 EDT
- in response to DODO DODO
In English, "who know less than we should about the actual technical details" does not mean "do not know the difference between". This is basic reading comprehension skills. In that blog I am admitting to not being an expert DBA and not knowing so much about some details at the actual physical level of memory and disk access.
See, I'm much more interested in recommending a great - and very unique - book, than in boasting about my knowledge.
Now go away. Or at least have the balls to post with your real name. -
anonymous cowards[ Go to top ]
- Posted by: Mike Spille
- Posted on: May 05 2004 14:38 EDT
- in response to Gavin King
Now go away. Or at least have the balls to post with your real name.
Wow Gavin, that brush off was a lot quicker than usual, even for you. :-)
Working for JBoss must be a bit more stressful then Andy O lets on for you to have this level of insecurity.
-Mike -
It's no joke[ Go to top ]
- Posted by: peter lin
- Posted on: May 05 2004 10:41 EDT
- in response to Marty Farrell
I found this article enlightening and interesting. I, along with the other developers on my team had no idea that performing full table scans on multi-million row tables using keyset cursors might be impacting performance negatively, I mean who would have thunk it? It will be difficult for us though to change our field data types from all BLOBS. Computers deal in binary all the time so its a real eye opener to find out that other data types may actually yield higher performance.The tips in the article may also help some of the issues we were having with our UI, its not easy to show three million results in a listbox to a user you know. Hopefully with more refined searching we will now only have to show them one million instead.Apparently there is also something called indexing which we read about in the truly visionary "Learn how to be a DB Guru in 24 min's" and are interested in learning more about, its supposed to make selects faster or something, any chance we can have an article on that?
You know, if only that didn't happen I would laugh. I've seen that happen more than once and hear developers ask "why should I index the table?" or "You should never use views, they are slow." Of course I end up send out a bunch of articles about database performance from several vendors. But by then, the damage is already done and takes 3x more effort to fix. -
Newbie Site....[ Go to top ]
- Posted by: Gurkan Erdogdu
- Posted on: May 05 2004 05:20 EDT
- in response to han theman
Sometimes reading the easy things refresh the important points... -
Newbie Site....[ Go to top ]
- Posted by: Michael Klaene
- Posted on: May 05 2004 09:41 EDT
- in response to Gurkan Erdogdu
Sometimes reading the easy things refresh the important points...
Good point. Though many of the developers on this site are experienced, I'm sure there are plenty of newbies reading the boards too. No need to be a technology elitist. If after reading the 1st few paragraphs, you find it targeted to beginners, stop reading. It's that simple.
Mike -
JDBC Performance Series: Retrieving Only Required Data[ Go to top ]
- Posted by: Web Master
- Posted on: May 05 2004 08:53 EDT
- in response to han theman
That was 2 pages of trivialities... Is TheServerSide.com becoming *the* newbie site?
The first article in this serie really sucked. I was hoping that we were going to learn something with the next artciles but obviously I was wrog. What are we going to learn with the next article ? That we should close the connections ? -
Part 1 was good[ Go to top ]
- Posted by: me havename
- Posted on: May 05 2004 11:23 EDT
- in response to Web Master
I doubt many knew the subtle differences in using the metadata calls shown in Part 1. Part 1 was certainly better. It was definitely illuminating, at least to me. -
JDBC Performance Series: Retrieving Only Required Data[ Go to top ]
- Posted by: Christian Bauer
- Posted on: May 05 2004 05:28 EDT
- in response to Nitin Bharti
This is an excellent book, highly recommended:
http://www.amazon.com/exec/obidos/tg/detail/-/0596005733 -
JDBC Performance Series: Retrieving Only Required Data[ Go to top ]
- Posted by: ABC DEF
- Posted on: May 05 2004 09:49 EDT
- in response to Nitin Bharti
Not to belittle the author's commendable efforts, but I really think this is not the right place to publish this article. I mean you have to be totally clueless in "Server Side" development if this article actually taught you anything.
I agree with most of the comments above. TSS should concentrate on the really meaty stuff and stick to its nitch. There are billions of newbie Java sites out there. Let's not become the billion-and-one site. We've already seen how JDJ is compromising subtance and moving to the toddler market. "Server Side" implies the readership is intermediate-to-advanced or advanced.