Changeset 7156


Ignore:
Timestamp:
May 24, 2016, 1:57:41 PM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #2009: PostgreSQL seems to be loading entire result set into memory

Adding jdbc.fetch_size configuration property to hibernate.cfg.xml. Hopefully Hibernate will pick it up wherever possible.

We are also picking it up in the BASE core API and use the same setting for queries were we bypass Hibernate.

It is verified to work for the raw data query in #2004 and http://baseplugins.thep.lu.se/ticket/887

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/config/dist/hibernate.cfg.xml

    r6468 r7156  
    3131    <!-- JDBC/SQL options -->
    3232    <property name="jdbc.batch_size">0</property>
     33    <property name="jdbc.fetch_size">1000</property>
    3334    <property name="show_sql">false</property>
    3435    <property name="connection.release_mode">after_transaction</property>
  • trunk/src/core/net/sf/basedb/core/AbstractSqlQuery.java

    r7075 r7156  
    215215      currentSql = mainSql;
    216216      ps = conn.prepareStatement(mainSql);
     217      ps.setFetchSize(HibernateUtil.getJdbcFetchSize());
     218     
    217219      int parameterIndex = 1;
    218220      if (rowSelection != null)
  • trunk/src/core/net/sf/basedb/core/HibernateUtil.java

    r7150 r7156  
    165165
    166166  private static boolean isInitialised = false;
     167 
     168  /**
     169    Number of rows to load at a time when iterating over
     170    a result set.
     171    @since 3.9
     172  */
     173  private static int jdbcFetchSize = 1000;
    167174
    168175  /**
     
    238245      sf = sfBuilder.build();
    239246
    240      
     247      if (sf.getSessionFactoryOptions().getJdbcFetchSize() != null)
     248      {
     249        jdbcFetchSize = sf.getSessionFactoryOptions().getJdbcFetchSize();
     250      }
    241251    }
    242252    catch (HibernateException | IOException ex)
     
    17771787    try
    17781788    {
    1779       return new EntityQueryWrapper(session.createQuery(hql));
     1789      Query q = session.createQuery(hql);
     1790      q.setFetchSize(getJdbcFetchSize());
     1791      return new EntityQueryWrapper(q);
    17801792    }
    17811793    catch (HibernateException ex)
     
    17951807    try
    17961808    {
    1797       return new EntityQueryWrapper(session.createQuery(hql));
     1809      Query q = session.createQuery(hql);
     1810      q.setFetchSize(getJdbcFetchSize());
     1811      return new EntityQueryWrapper(q);
    17981812    }
    17991813    catch (HibernateException ex)
     
    18141828    try
    18151829    {
    1816       return session.createSQLQuery(sql);
     1830      SQLQuery q = session.createSQLQuery(sql);
     1831      q.setFetchSize(getJdbcFetchSize());
     1832      return q;
    18171833    }
    18181834    catch (HibernateException ex)
     
    18331849    try
    18341850    {
    1835       return session.createSQLQuery(sql);
     1851      SQLQuery q = session.createSQLQuery(sql);
     1852      q.setFetchSize(getJdbcFetchSize());
     1853      return q;
    18361854    }
    18371855    catch (HibernateException ex)
     
    20332051  {
    20342052    return dbEngine;
     2053  }
     2054 
     2055  /**
     2056    The number of rows to load at a time when reading
     2057    from the database.
     2058    @since 3.9
     2059  */
     2060  public static int getJdbcFetchSize()
     2061  {
     2062    return jdbcFetchSize;
    20352063  }
    20362064 
  • trunk/src/core/net/sf/basedb/core/hibernate/SessionWrapper.java

    r7075 r7156  
    5151import org.hibernate.stat.SessionStatistics;
    5252
     53import net.sf.basedb.core.HibernateUtil;
     54
    5355/**
    5456  Wrapper around Hibernate sessions that includes a query cache.
     
    172174    {
    173175      q = session.createQuery(queryString);
     176      q.setFetchSize(HibernateUtil.getJdbcFetchSize());
    174177      cacheQuery(queryString, q);
    175178    }
     
    190193    {
    191194      q = session.createSQLQuery(queryString);
     195      q.setFetchSize(HibernateUtil.getJdbcFetchSize());
    192196    }
    193197    return (SQLQuery)q;
  • trunk/src/core/net/sf/basedb/core/hibernate/StatelessSessionWrapper.java

    r7075 r7156  
    3636import org.hibernate.procedure.ProcedureCall;
    3737
     38import net.sf.basedb.core.HibernateUtil;
     39
    3840/**
    3941  Wrapper around stateless Hibernate sessions that includes a query cache.
     
    147149    {
    148150      q = session.createQuery(queryString);
     151      q.setFetchSize(HibernateUtil.getJdbcFetchSize());
    149152      cacheQuery(queryString, q);
    150153    }
     
    165168    {
    166169      q = session.createSQLQuery(queryString);
     170      q.setFetchSize(HibernateUtil.getJdbcFetchSize());
    167171    }
    168172    return (SQLQuery)q;
Note: See TracChangeset for help on using the changeset viewer.