Class ExtentEstimator

java.lang.Object
org.apache.sis.internal.sql.postgis.ExtentEstimator

final class ExtentEstimator extends Object
Estimation of the extent of geometries in a given table or column using statistics if available. Uses the PostGIS ST_EstimatedExtent(…) function to get a rough estimation of column extent. If ST_EstimatedExtent(…) gave no result and it was the first attempt on the specified table, then this class executes ANALYZE and tries again to get the extent. This strategy works well when requesting envelope on newly created tables.

Design notes

We do not use the most accurate ST_Extent function because it is costly on large tables. At the time of writing this class (December 2021), ST_Extent does not use column index.
Since:
1.2
Version:
1.2
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final SQLBuilder
    A temporary buffer with helper methods for building the SQL statement.
    private final Column[]
    All columns in the table (including non-geometry columns).
    private final Database
    The database containing the table for which to estimate the extent.
    The union of all extents found, or null if none.
    private org.opengis.referencing.operation.TransformException
    Errors that occurred during envelope transformations, or null if none.
    private final TableReference
    The table for which to get the extent.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExtentEstimator(Database database, TableReference table, Column[] columns)
    Creates a new extent estimator for the specified table.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) GeneralEnvelope
    estimate(Statement statement, boolean recall)
    Estimates the extent in the specified columns using PostgreSQL statistics.
    private void
    query(Statement statement)
    Estimates the extent in the specified columns using current statistics.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • database

      private final Database database
      The database containing the table for which to estimate the extent.
    • table

      private final TableReference table
      The table for which to get the extent.
    • columns

      private final Column[] columns
      All columns in the table (including non-geometry columns). This is a reference to an internal array; do not modify.
    • builder

      private final SQLBuilder builder
      A temporary buffer with helper methods for building the SQL statement.
    • envelope

      private GeneralEnvelope envelope
      The union of all extents found, or null if none.
    • error

      private org.opengis.referencing.operation.TransformException error
      Errors that occurred during envelope transformations, or null if none.
  • Constructor Details

    • ExtentEstimator

      ExtentEstimator(Database database, TableReference table, Column[] columns)
      Creates a new extent estimator for the specified table.
  • Method Details

    • estimate

      GeneralEnvelope estimate(Statement statement, boolean recall) throws SQLException
      Estimates the extent in the specified columns using PostgreSQL statistics. If there are no statistics available, then this method executes ANALYZE and tries again.
      Parameters:
      statement - statement to use for executing queries. Shall be closed by caller.
      recall - if it is at least the second time that this method is invoked for the table.
      Returns:
      an estimation of the union of extents in given columns, or null if unknown.
      Throws:
      SQLException
    • query

      private void query(Statement statement) throws SQLException
      Estimates the extent in the specified columns using current statistics. If there are no statistics available, then this method returns null.
      Parameters:
      statement - statement to use for executing queries. Shall be closed by caller.
      Throws:
      SQLException