users@glassfish.java.net

JPQL Query suspiciously slow

From: <glassfish_at_javadesktop.org>
Date: Wed, 12 Sep 2007 02:31:19 PDT

Hi!

I wrote a simple JPQL query a little optimized for speed:

final Query q = em.createQuery("SELECT DISTINCT session FROM InboundEventSession session JOIN FETCH session.events ");
                q.setMaxResults(10000);
                final long start = System.currentTimeMillis();
                final List<InboundEventSession> sessions = q.getResultList();
                final long stop = System.currentTimeMillis();
                LOG.info("Loaded sessions: " + sessions.size() + " Time: " + ((stop - start) / 1000));

This fragment takes [b]460 seconds.[/b]

I switch toplink essentials logging to FINE and used the generated query in SQuirreL (btw, the generated query looks quite fine):

SELECT DISTINCT t0.ID, t0.COMPARISONSESSION, t0.PROJECTID, t0.STATE, t0.CID, t0.VERSION, t0.TSTAMP, t1.ID, t1.VALUE, t1.PID, t1.VERSION, t1.TSTAMP, t1.EVENTTYPE, t1.INBOUNDEVENTSESSION_ID, t1.PARENTEVENT_ID FROM core_InboundSession t0, core_BusinessEvent t1 WHERE (t1.INBOUNDEVENTSESSION_ID = t0.ID)


Query 1 of 1 elapsed time (seconds) - Total: 5.206, SQL query: [b]1.772[/b], Building output: 3.434



Why is the JPQL Query [b]260 times slower[/b]?

What can I do to speed it up?

Thanks
ste'confused'han
[Message sent by forum member 'iceandfire' (iceandfire)]

http://forums.java.net/jive/thread.jspa?messageID=235014