• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get Max ID when database has huge data

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have huge database where database size is 3 million records in one table when i try to get max id from it, I am getting out of memory error.

What is the efficient way to retrieve the MAX ID without loading the memory so much?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you getting the max id from the database?
A single simple query on the id column should be quick and involve hardly any memory.
 
Nisha lakshminaraya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya its single query like folloinwg :

session = openHibernateSession();
Criteria criteria = session.createCriteria(TableName.class);
criteria.add(Restrictions.eq("ID1", 1));
criteria.add(Restrictions.eq("ID2", 1));
criteria.add(Restrictions.eq("ID3", 349));
criteria.setProjection(Projections.max("creationtimestamp"));
long endDateInEpoch = (Long) criteria.uniqueResult();
endDate = new Date(endDateInEpoch*1000);
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not getting the maximum ID from a table.
It's getting a maximum timestamp, for certain criteria.

At first glance that by itself won't cause you to run out of memory.
 
reply
    Bookmark Topic Watch Topic
  • New Topic