-->
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: HQL queries performance
PostPosted: Fri Feb 15, 2013 11:39 am 
Newbie

Joined: Fri Feb 15, 2013 11:37 am
Posts: 1
I have a couple of HQL queryes that takes rather more time that they should. I am trying to improve the execution time by modifying the queries and I dont know how. Perhaps I am missing something. The first query:

Code:
SELECT linkResult.url AS url, linkResult.title AS title,
       (SELECT MIN(r.linkQuery.queryDate.date)
           FROM LinkResult r
             WHERE r.linkQuery.domain=linkQuery.domain
                AND r.url=linkResult.url) AS indexedDate
FROM CompetitiveEntity entity,
      IN(entity.domains) domain,
      LinkQuery linkQuery,
      IN(linkQuery.results) linkResult
   LEFT JOIN FETCH linkResult.url.hostname
     WHERE entity.id=2062
       AND (linkResult.url.hostname NOT MEMBER entity.domains)
       AND (linkQuery.domain=domain)
       AND (linkQuery.id=(SELECT MAX(lastQuery.id)
                    FROM LinkQuery lastQuery
                       WHERE lastQuery.domain=domain
                    AND SIZE(lastQuery.results) > 0 ) )
GROUP BY linkResult.url
ORDER BY linkResult.url


The second one:

Code:
SELECT subscription.term.id, subscription, termQueryPrev.provider.name,
       MIN(termResultPrev.position) as prevPosition, MIN(termResultCurrent.position) as currentPosition,
       MIN(cast(termResultCurrent.position as integer)) - MIN(cast(termResultPrev.position as integer)) as change
  FROM TermSubscription subscription, 
       TermQuery termQueryPrev,
       IN(termQueryPrev.results) termResultPrev,
       TermQuery termQueryCurrent,
       IN(termQueryCurrent.results) termResultCurrent
  WHERE subscription.account.id= :accountId 
   AND termQueryPrev.term=subscription.term
   AND termQueryCurrent.term=subscription.term
   AND termQueryCurrent.provider.id=termQueryPrev.provider.id
   AND termQueryPrev.queryDate.yearWeek = YEARWEEK(FROM_DAYS(TO_DAYS(current_date) - 7), 1)
   AND termQueryCurrent.queryDate.yearWeek = YEARWEEK(:endDate,1)
   AND termResultPrev.url.hostname   MEMBER subscription.account.domains
   AND termResultCurrent.url.hostname   MEMBER subscription.account.domains 
GROUP BY subscription.term.id, termQueryPrev.queryDate.yearWeek,termQueryPrev.provider.id
HAVING MIN(cast(termResultCurrent.position as integer)) != MIN(cast(termResultPrev.position as integer))
ORDER BY ABS(MIN(cast(termResultCurrent.position as integer)) - MIN(cast(termResultPrev.position as integer))) DESC


I stress the fact that I am looking for a better way to improve the current HQL query construction.
Thank you.


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.