Class AdaptiveFetchCache
- java.lang.Object
-
- org.postgresql.core.v3.adaptivefetch.AdaptiveFetchCache
-
public class AdaptiveFetchCache extends java.lang.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 Summary
Fields Modifier and Type Field Description private boolean
adaptiveFetch
private java.util.Map<java.lang.String,AdaptiveFetchCacheEntry>
adaptiveFetchInfoMap
private int
maximumAdaptiveFetchSize
private long
maximumResultBufferSize
private int
minimumAdaptiveFetchSize
-
Constructor Summary
Constructors Constructor Description AdaptiveFetchCache(long maximumResultBufferSize, java.util.Properties info)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNewQuery(boolean adaptiveFetch, Query query)
Add query to being cached and computing adaptive fetch size.private int
adjustFetchSize(int actualSize)
Set maximum and minimum constraints on given value.private int
adjustMaximumFetchSize(int actualSize)
Set maximum constraint on given value.private int
adjustMinimumFetchSize(int actualSize)
Set minimum constraint on given value.boolean
getAdaptiveFetch()
Get state of adaptive fetch.int
getFetchSizeForQuery(boolean adaptiveFetch, Query query)
Get adaptive fetch size for given query.void
removeQuery(boolean adaptiveFetch, Query query)
Remove query information from caching.void
setAdaptiveFetch(boolean adaptiveFetch)
Set state of adaptive fetch.void
updateQueryFetchSize(boolean adaptiveFetch, Query query, int maximumRowSizeBytes)
Update adaptive fetch size for given query.
-
-
-
Field Detail
-
adaptiveFetchInfoMap
private final java.util.Map<java.lang.String,AdaptiveFetchCacheEntry> adaptiveFetchInfoMap
-
adaptiveFetch
private boolean adaptiveFetch
-
minimumAdaptiveFetchSize
private int minimumAdaptiveFetchSize
-
maximumAdaptiveFetchSize
private int maximumAdaptiveFetchSize
-
maximumResultBufferSize
private long maximumResultBufferSize
-
-
Method Detail
-
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 queryquery
- 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 queryquery
- query to be updatedmaximumRowSizeBytes
- 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 queryquery
- 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 queryquery
- 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
-
-