Class AdaptiveFetchCache

java.lang.Object
org.postgresql.core.v3.adaptivefetch.AdaptiveFetchCache

public class AdaptiveFetchCache extends Object
The main purpose of this class is to handle adaptive fetching process. Adaptive fetching is used to compute fetch size to fully use size defined by maxResultBuffer. Computing is made by dividing maxResultBuffer size by max row result size noticed so far. Each query have separate adaptive fetch size computed, but same queries have it shared. If adaptive fetch is turned on, first fetch is going to be made with defaultRowFetchSize, next fetching of resultSet will be made with computed adaptive fetch size. If adaptive fetch is turned on during fetching, then first fetching made by ResultSet will be made with defaultRowFetchSize, next will use computed adaptive fetch size. Property adaptiveFetch need properties defaultRowFetchSize and maxResultBuffer to work.
  • Field Details

    • adaptiveFetchInfoMap

      private final Map<String,AdaptiveFetchCacheEntry> adaptiveFetchInfoMap
    • adaptiveFetch

      private boolean adaptiveFetch
    • minimumAdaptiveFetchSize

      private int minimumAdaptiveFetchSize
    • maximumAdaptiveFetchSize

      private int maximumAdaptiveFetchSize
    • maximumResultBufferSize

      private long maximumResultBufferSize
  • Constructor Details

  • Method Details

    • addNewQuery

      public void addNewQuery(boolean adaptiveFetch, Query query)
      Add query to being cached and computing adaptive fetch size.
      Parameters:
      adaptiveFetch - state of adaptive fetch, which should be used during adding query
      query - query to be cached
    • updateQueryFetchSize

      public void updateQueryFetchSize(boolean adaptiveFetch, Query query, int maximumRowSizeBytes)
      Update adaptive fetch size for given query.
      Parameters:
      adaptiveFetch - state of adaptive fetch, which should be used during updating fetch size for query
      query - query to be updated
      maximumRowSizeBytes - max row size used during updating information about adaptive fetch size for given query
    • getFetchSizeForQuery

      public int getFetchSizeForQuery(boolean adaptiveFetch, Query query)
      Get adaptive fetch size for given query.
      Parameters:
      adaptiveFetch - state of adaptive fetch, which should be used during getting fetch size for query
      query - query to which we want get adaptive fetch size
      Returns:
      adaptive fetch size for query or -1 if size doesn't exist/adaptive fetch state is false
    • removeQuery

      public void removeQuery(boolean adaptiveFetch, Query query)
      Remove query information from caching.
      Parameters:
      adaptiveFetch - state of adaptive fetch, which should be used during removing fetch size for query
      query - query to be removed from caching
    • adjustFetchSize

      private int adjustFetchSize(int actualSize)
      Set maximum and minimum constraints on given value.
      Parameters:
      actualSize - value which should be the computed fetch size
      Returns:
      value which meet the constraints
    • adjustMinimumFetchSize

      private int adjustMinimumFetchSize(int actualSize)
      Set minimum constraint on given value.
      Parameters:
      actualSize - value which should be the computed fetch size
      Returns:
      value which meet the minimum constraint
    • adjustMaximumFetchSize

      private int adjustMaximumFetchSize(int actualSize)
      Set maximum constraint on given value.
      Parameters:
      actualSize - value which should be the computed fetch size
      Returns:
      value which meet the maximum constraint
    • getAdaptiveFetch

      public boolean getAdaptiveFetch()
      Get state of adaptive fetch.
      Returns:
      state of adaptive fetch
    • setAdaptiveFetch

      public void setAdaptiveFetch(boolean adaptiveFetch)
      Set state of adaptive fetch.
      Parameters:
      adaptiveFetch - desired state of adaptive fetch