• 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: 2112
16
  • 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: 2112
16
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic