-->
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.  [ 1 post ] 
Author Message
 Post subject: Question about SQLQuery performance
PostPosted: Thu Nov 25, 2010 8:11 am 
Newbie

Joined: Thu Nov 25, 2010 7:50 am
Posts: 1
I'm devoping an app that accesses an embedded database (Apache Derby right now). It is single user and desktop.

A certain functionality of the application requirmes to read a _lot_ of data from a certain table (think millions).

So, for that particular part, we decided to get a bit dirtier, and go into SQL.

The table in question just has three columns: a FK that also acts as "column", another integer that acts as the "row" (and when mapped to Hibernate also acts as the list-index) and the actual column that contains the data (type float).

The problem is, I'm getting a HUGE performance loss when I try to do things proper and use named parameters.

Code:

Long id = 1;
int orderLow = 0;
int orderHigh = 5000; //These three columns usually are passed to the function as parameters
SQLQuery query = mySession.createSQLQuery("SELECT cdata from data where columnnumber = :cn AND rownumber >= :ol AND rownumber < :oh ORDER BY rownumber");

query.setParameter("cn", id, StandardBasicTypes.LONG);
query.setParameter("oh", orderHigh, StandardBasicTypes.INTEGER);
query.setParameter("ol", orderLow, StandardBasicTypes.INTEGER);

query.addScalar("cdata", StandardBasicTypes.FLOAT);

query.list();



this takes around 3 seconds to execute... which obviously isn't right. On the other hand...

Code:
StringBuilder sb = new StringBuilder("SELECT cdata from data where columnnumber = ");
sb.append(id);
sb.append(" AND rownumber >=");
sb.append(orderLow);
sb.append(" AND rownumber <");
sb.append(orderHigh);
sb.append(" ORDER BY rownumber);

SQlQuery query= mySession.createSQLQuery(sb.toString());
query.addScalar("cdata", StandardBasicTypes.FLOAT);

query.list();


(I know this is a bad practice. Just using it for comparision porposes).

This takes between 0.02 and 0.04 seconds to execute. Which is quite closer to the actual performance I'm getting with other clients connecting to the same database.

So... any ideas? I'm seriously confused as to what this is happening.


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

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.