0 Replies Latest reply on Mar 5, 2003 6:52 PM by Luiz-Otavio Zorzella

    Iterating a CMR collection generates extremelly unoptimized

    Luiz-Otavio Zorzella Newbie

      Hi,

      I noticed that, while iterating over a CMR-generated Collection and "getting" any attribute, as I approach the end of the Collection, it gets faster. By looking at the DEBUG logs, it seems to me that jboss will make a SELECT query passing as parameter, instead of one pk field, multiple OR'ed fields -- as many as there are objects left in the collection.

      E.g., this is the SELECT statement I got from server.log, from a trivial code (excerpt at the end):

      2003-03-05 15:31:21,045 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.LogicalIFBean] Executing SQL: SELECT guid,name, opStatus, localIp, remoteIp, isCommitted, pairGuid, RemoteNode_guid_fk, LocalNode_guid_fk FROM LogicalIFs WHERE (guid=?) OR (guid=?) OR (guid=?) OR (guid=?) OR (guid=?) OR (guid=?) OR (guid=?) OR (guid=?) OR (guid=?) OR (guid=?)

      This is one of the last iterations (when there are only 10 elements left in the Collection). Note that there are 10 "OR (guid=?)" conditions. As we move back in the log, we would see more and more " OR (guid=?)" in this statement, which is, I'm pretty sure, the reason it is slower... The code excerpt follows:

      ************

      Collection logicalIFs = LogicalIFBeanUtil.getLocalHome().findAll();
      Iterator it = logicalIFs.iterator ();

      while (it.hasNext ()) {
      LogicalIF lif = (LogicalIF) it.next ();
      String temp = lif.getName ();
      System.out.println (temp);
      }

      ***********

      Am I missing something here or is this a bug?

      Zorzella