Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Max ID when database has huge data

 
Nisha lakshminaraya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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?
 
Dave Tolls
Ranch Hand
Posts: 2365
25
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Hand
Posts: 2365
25
  • Mark post as helpful
  • send pies
  • 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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!