Package org.h2.index

Class ViewIndex

All Implemented Interfaces:
SpatialIndex, HasSQL

public class ViewIndex extends Index implements SpatialIndex
This object represents a virtual index for a query. Actually it only represents a prepared SELECT statement.
  • Field Details

    • MAX_AGE_NANOS

      private static final long MAX_AGE_NANOS
    • view

      private final TableView view
    • querySQL

      private final String querySQL
    • originalParameters

      private final ArrayList<Parameter> originalParameters
    • recursive

      private boolean recursive
    • indexMasks

      private final int[] indexMasks
    • query

      private Query query
    • createSession

      private final SessionLocal createSession
    • evaluatedAt

      private final long evaluatedAt
      The time in nanoseconds when this index (and its cost) was calculated.
  • Constructor Details

    • ViewIndex

      public ViewIndex(TableView view, String querySQL, ArrayList<Parameter> originalParameters, boolean recursive)
      Constructor for the original index in TableView.
      Parameters:
      view - the table view
      querySQL - the query SQL
      originalParameters - the original parameters
      recursive - if the view is recursive
    • ViewIndex

      public ViewIndex(TableView view, ViewIndex index, SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder)
      Constructor for plan item generation. Over this index the query will be executed.
      Parameters:
      view - the table view
      index - the view index
      session - the session
      masks - the masks
      filters - table filters
      filter - current filter
      sortOrder - sort order
  • Method Details

    • getSession

      public SessionLocal getSession()
    • isExpired

      public boolean isExpired()
    • getPlanSQL

      public String getPlanSQL()
      Description copied from class: Index
      Get the message to show in a EXPLAIN statement.
      Overrides:
      getPlanSQL in class Index
      Returns:
      the plan
    • close

      public void close(SessionLocal session)
      Description copied from class: Index
      Close this index.
      Specified by:
      close in class Index
      Parameters:
      session - the session used to write data
    • add

      public void add(SessionLocal session, Row row)
      Description copied from class: Index
      Add a row to the index.
      Specified by:
      add in class Index
      Parameters:
      session - the session to use
      row - the row to add
    • remove

      public void remove(SessionLocal session, Row row)
      Description copied from class: Index
      Remove a row from the index.
      Specified by:
      remove in class Index
      Parameters:
      session - the session
      row - the row
    • getCost

      public double getCost(SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, AllColumnsForPlan allColumnsSet)
      Description copied from class: Index
      Estimate the cost to search for rows given the search mask. There is one element per column in the search mask. For possible search masks, see IndexCondition.
      Specified by:
      getCost in class Index
      Parameters:
      session - the session
      masks - per-column comparison bit masks, null means 'always false', see constants in IndexCondition
      filters - all joined table filters
      filter - the current table filter index
      sortOrder - the sort order
      allColumnsSet - the set of all columns
      Returns:
      the estimated cost
    • find

      public Cursor find(SessionLocal session, SearchRow first, SearchRow last)
      Description copied from class: Index
      Find a row or a list of rows and create a cursor to iterate over the result.
      Specified by:
      find in class Index
      Parameters:
      session - the session
      first - the first row, or null for no limit
      last - the last row, or null for no limit
      Returns:
      the cursor to iterate over the results
    • findByGeometry

      public Cursor findByGeometry(SessionLocal session, SearchRow first, SearchRow last, SearchRow intersection)
      Description copied from interface: SpatialIndex
      Find a row or a list of rows and create a cursor to iterate over the result.
      Specified by:
      findByGeometry in interface SpatialIndex
      Parameters:
      session - the session
      first - the lower bound
      last - the upper bound
      intersection - the geometry which values should intersect with, or null for anything
      Returns:
      the cursor to iterate over the results
    • findRecursive

      private Cursor findRecursive(SearchRow first, SearchRow last)
    • setupQueryParameters

      public void setupQueryParameters(SessionLocal session, SearchRow first, SearchRow last, SearchRow intersection)
      Set the query parameters.
      Parameters:
      session - the session
      first - the lower bound
      last - the upper bound
      intersection - the intersection
    • find

      private Cursor find(SessionLocal session, SearchRow first, SearchRow last, SearchRow intersection)
    • setParameter

      private static void setParameter(ArrayList<Parameter> paramList, int x, Value v)
    • getQuery

      public Query getQuery()
    • getQuery

      private Query getQuery(SessionLocal session, int[] masks)
    • remove

      public void remove(SessionLocal session)
      Description copied from class: Index
      Remove the index.
      Specified by:
      remove in class Index
      Parameters:
      session - the session
    • truncate

      public void truncate(SessionLocal session)
      Description copied from class: Index
      Remove all rows from the index.
      Specified by:
      truncate in class Index
      Parameters:
      session - the session
    • checkRename

      public void checkRename()
      Description copied from class: DbObject
      Check if renaming is allowed. Does nothing when allowed.
      Overrides:
      checkRename in class DbObject
    • needRebuild

      public boolean needRebuild()
      Description copied from class: Index
      Check if the index needs to be rebuilt. This method is called after opening an index.
      Specified by:
      needRebuild in class Index
      Returns:
      true if a rebuild is required.
    • setRecursive

      public void setRecursive(boolean value)
    • getRowCount

      public long getRowCount(SessionLocal session)
      Description copied from class: Index
      Get the row count of this table, for the given session.
      Specified by:
      getRowCount in class Index
      Parameters:
      session - the session
      Returns:
      the row count
    • getRowCountApproximation

      public long getRowCountApproximation(SessionLocal session)
      Description copied from class: Index
      Get the approximated row count for this table.
      Specified by:
      getRowCountApproximation in class Index
      Parameters:
      session - the session
      Returns:
      the approximated row count
    • isRecursive

      public boolean isRecursive()