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.
  • Constructor Details

  • Method Details

    • addNewQuery

      public void addNewQuery(boolean adaptiveFetch, @NonNull 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, @NonNull 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, @NonNull 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, @NonNull 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
    • 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