-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Millions of rows - pagination
PostPosted: Tue Jan 02, 2007 8:22 am 
Newbie

Joined: Tue Jan 02, 2007 8:13 am
Posts: 4
Hi,

I have 2 millions of rows in a table. Implemented paging using Hibernate Criteria feature. The response time getting worse when the page offset increases. See the below table

Page offset 0 3000 9000 12000 250K 500K 750K 1000k 1250k 1500k
Response time in seconds 34 34 34 34 39 305 310 315 386 384


I think this may not be the problem with Hibernate. Any idea on how to improve the response time for pages who’s offset is greater than half of the total rows?

Thanks
Venkat


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 9:04 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Please post your pagination code and what is your jdbc driver?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: Code
PostPosted: Wed Jan 03, 2007 8:38 am 
Newbie

Joined: Tue Jan 02, 2007 8:13 am
Posts: 4
Hi,



database driver name=Oracle JDBC driver
database driver version=9.2.0.5.0
database product version=Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

Number of rows presnet in the DB = 2,000,000

Here is the Code:

public List getPageDataUsingCriteria(String className,
Map<String, Object> matchingCriteria,
String sortCol, int sortOrder,
int pagelength, int pageOffset, String[] colList)
throws IErrorException
{
Criteria criteria = getSession().createCriteria(className);
boolean isSortOrderChangeReq = false;
Set keys = matchingCriteria.keySet();
for(Object key : keys)
{
String propKey = (String) key;
List<Object> propValue = (List<Object>) matchingCriteria.get(propKey);
criteria.add(Expression.in(propKey, propValue));
}

criteria.setProjection(Projections.rowCount());
Object object = criteria.uniqueResult();
int totalCount = ((Integer)object).intValue();
System.out.println("Total Number of Rows = "+totalCount);
if( colList != null && colList.length > 0)
{
ProjectionList proj = Projections.projectionList();
for( String column: colList)
{
proj.add(Projections.property(column));
}
criteria.setProjection(proj);
}

if(sortOrder == IConstants.ASC_ORDER)
{
criteria.addOrder(Order.asc(sortCol));
criteria.addOrder(Order.asc("id")); //Todo
}
else
{
criteria.addOrder(Order.desc(sortCol));
criteria.addOrder(Order.desc("id")); //Todo
}
criteria.setMaxResults(pagelength);
criteria.setFirstResult(pageOffset);

List<Object[]> pageData = criteria.list();
if(pageData == null)
{
return new ArrayList();
}

return pageData;
}

Thanks
Venkat


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 9:06 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Maybe try using a cursor instead of setFirstRes() setMaxRes(): http://www.hibernate.org/hib_docs/v3/re ... batch.html

Maybe also a look here: http://www.hibernate.org/314.html ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 9:26 am 
Newbie

Joined: Tue Jan 02, 2007 8:13 am
Posts: 4
Hi,

Thanks for your reply. I tried with scroll and cursor but response is very very slow when number of rows are in million. These two work fins if the number of rows are ~10000. I did some experiment and work for begining and ending pages but not the middle pages. See the below code

if( pageOffset > 100000)
{
isSortOrderChangeReq = isSortOrderChangeReq(totalCount,pageOffset);
System.out.println("Sort Order Change is required = "+isSortOrderChangeReq);
if( isSortOrderChangeReq )
{
System.out.println("Old Sort Order = "+sortOrder);
System.out.println("Old Page Offset = "+pageOffset);
sortOrder = (sortOrder == IConstants.ASC_ORDER)?
IConstants.DESC_ORDER:
IConstants.ASC_ORDER;
pageOffset = totalCount - (pageOffset+pagelength);
System.out.println("New Sort Order = "+sortOrder);
System.out.println("New Page Offset = "+pageOffset);
}
}

with this code last page is taking almost same time as first page but still middle pages are taking too long time to retrieve. Any other suggestion would be great

Thanks
Venkat


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.