Uploaded image for project: 'Hibernate ORM'
  1. HHH-9455

Hibernate triggers unnecessary select count query that imposes negative effect on performance.

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      org.hibernate.persister.collection.AbstractCollectionPersister.java:

      public void processQueuedOps(PersistentCollection collection, Serializable key, SessionImplementor session)
      throws HibernateException {
      if ( collection.hasQueuedOperations() )

      { int nextIndex = getSize( key, session ); doProcessQueuedOps( collection, key, nextIndex, session ); }

      }

      Please note the line:
      int nextIndex = getSize( key, session );

      It actually executes a query "select count xxx" which is expensive and has negative impact on performance.

      More importantly, in the method doProcessQueuedOps:

      @Deprecated
      protected void doProcessQueuedOps(PersistentCollection collection, Serializable key,
      int nextIndex, SessionImplementor session)
      throws HibernateException

      { doProcessQueuedOps( collection, key, session ); }

      The param nextIndex is not even used.

      It appears that the method
      doProcessQueuedOps(PersistentCollection collection, Serializable key,
      int nextIndex, SessionImplementor session)
      is already deprecated and is not supposed to be used any more.

      The method processQueuedOps should call
      doProcessQueuedOps(PersistentCollection collection, Serializable key, SessionImplementor session)
      and no need to invoke getSize method that is very expensive.

      In addition, in org.hibernate.persister.collection.OneToManyPersister.java,
      the following method also triggers unnecessary call getSize() that executes "select count.." query:

      protected void doProcessQueuedOps(PersistentCollection collection, Serializable id, SessionImplementor session)
      throws HibernateException

      { writeIndex( collection, collection.queuedAdditionIterator(), id, getSize( id, session ), session ); }

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: