• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Connection _very_ slow

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so, after many confused hours, i finally got jdbc:postgresql working. But the first thing i noticed was that it took a very long time to download the results of my query... and furthermore, it didnt help that i left out SELECTing the columns which are usually the largest...
Does anyone have any tips for optimizations? should i query for the whole table at once? does jdbc have to do any connection-stuff each time i run a query?
[This message has been edited by Jesper Ottosson (edited April 08, 2000).]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I know little about optimizing SQL, and nothing at all about postgresql in particular. But offhand: keep the number of different connections to the minimum you can get away with. Often you can just create a single connection once, and then keep re-using the same connection for different queries. The only reasons I've ever had for multiple connections are if you need to be daling with more than one query or resultset at a time, or more than one database. Dunno if you're creating multiple connections, but if you are it can eat up a lot of time.
Also, try using PreparedStatements rather than Statements if you're running the same type of query many times with different inputs. You save on the time the DB spends interpreting your SQL and figuring out how to optimize it. Dunno how much effect this has, but I'd think it would be noticeable at least.
Should you query for the whole table at once? Umm, I guess it depends how much of the table you need. (And is anyone else trying to access the table while you've got it locked, assuming you have some sort of locking?) I usually try to select all the rows I know I will need into one big ResultSet, and loop through it to process each row as necessary. If there are other statements to execute as well, that's when you need another connection, as your first connection is still holding the results if your earlier query. I've always assumed (but never really tested) that this is faster than selecting each row individually. But if the table is particularly huge then memory restrictions could prevent this, or other users needing to access the table may restrict you to one row at a time. And I'm sure there are other considerations I haven't encountered.
If you're already minimizing the number of connections and using PreparedStatements, you may want to post some code to show what exactly you're doing. I personally will be out of town shortly for a week or so, but I'm sure others will have suggestions. Good luck.
[This message has been edited by Jim Yingst (edited April 08, 2000).]
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic