Package org.h2.index
Class ViewIndex
- java.lang.Object
-
- org.h2.engine.DbObject
-
- org.h2.schema.SchemaObject
-
- org.h2.index.Index
-
- org.h2.index.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 Summary
Fields Modifier and Type Field Description private SessionLocal
createSession
private long
evaluatedAt
The time in nanoseconds when this index (and its cost) was calculated.private int[]
indexMasks
private static long
MAX_AGE_NANOS
private java.util.ArrayList<Parameter>
originalParameters
private Query
query
private java.lang.String
querySQL
private boolean
recursive
private TableView
view
-
Fields inherited from class org.h2.index.Index
columnIds, columns, indexColumns, indexType, table, uniqueColumnColumn
-
Fields inherited from class org.h2.engine.DbObject
AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USER
-
Fields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS
-
-
Constructor Summary
Constructors Constructor Description ViewIndex(TableView view, java.lang.String querySQL, java.util.ArrayList<Parameter> originalParameters, boolean recursive)
Constructor for the original index inTableView
.ViewIndex(TableView view, ViewIndex index, SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder)
Constructor for plan item generation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(SessionLocal session, Row row)
Add a row to the index.void
checkRename()
Check if renaming is allowed.void
close(SessionLocal session)
Close this index.Cursor
find(SessionLocal session, SearchRow first, SearchRow last)
Find a row or a list of rows and create a cursor to iterate over the result.private Cursor
find(SessionLocal session, SearchRow first, SearchRow last, SearchRow intersection)
Cursor
findByGeometry(SessionLocal session, SearchRow first, SearchRow last, SearchRow intersection)
Find a row or a list of rows and create a cursor to iterate over the result.private Cursor
findRecursive(SearchRow first, SearchRow last)
double
getCost(SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, AllColumnsForPlan allColumnsSet)
Estimate the cost to search for rows given the search mask.java.lang.String
getPlanSQL()
Get the message to show in a EXPLAIN statement.Query
getQuery()
private Query
getQuery(SessionLocal session, int[] masks)
long
getRowCount(SessionLocal session)
Get the row count of this table, for the given session.long
getRowCountApproximation(SessionLocal session)
Get the approximated row count for this table.SessionLocal
getSession()
boolean
isExpired()
boolean
isRecursive()
boolean
needRebuild()
Check if the index needs to be rebuilt.void
remove(SessionLocal session)
Remove the index.void
remove(SessionLocal session, Row row)
Remove a row from the index.private static void
setParameter(java.util.ArrayList<Parameter> paramList, int x, Value v)
void
setRecursive(boolean value)
void
setupQueryParameters(SessionLocal session, SearchRow first, SearchRow last, SearchRow intersection)
Set the query parameters.void
truncate(SessionLocal session)
Remove all rows from the index.-
Methods inherited from class org.h2.index.Index
canFindNext, canGetFirstOrLast, canScan, checkIndexColumnTypes, compareRows, findFirstOrLast, findNext, getColumnIndex, getColumns, getCostRangeIndex, getCreateSQL, getCreateSQLForCopy, getDiskSpaceUsed, getDuplicateKeyException, getDuplicatePrimaryKeyMessage, getIndexColumns, getIndexType, getRow, getRowFactory, getTable, getType, getUniqueColumnCount, getUniqueRowFactory, isFindUsingFullTableScan, isFirstColumn, isHidden, isRowIdIndex, mayHaveNullDuplicates, removeChildrenAndResources, update
-
Methods inherited from class org.h2.schema.SchemaObject
getSchema, getSQL, getSQL
-
Methods inherited from class org.h2.engine.DbObject
getChildren, getComment, getCreateSQLForMeta, getDatabase, getDropSQL, getId, getModificationId, getName, invalidate, isTemporary, isValid, rename, setComment, setModified, setObjectName, setTemporary, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
-
-
-
Field Detail
-
MAX_AGE_NANOS
private static final long MAX_AGE_NANOS
-
view
private final TableView view
-
querySQL
private final java.lang.String querySQL
-
originalParameters
private final java.util.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 Detail
-
ViewIndex
public ViewIndex(TableView view, java.lang.String querySQL, java.util.ArrayList<Parameter> originalParameters, boolean recursive)
Constructor for the original index inTableView
.- Parameters:
view
- the table viewquerySQL
- the query SQLoriginalParameters
- the original parametersrecursive
- 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 viewindex
- the view indexsession
- the sessionmasks
- the masksfilters
- table filtersfilter
- current filtersortOrder
- sort order
-
-
Method Detail
-
getSession
public SessionLocal getSession()
-
isExpired
public boolean isExpired()
-
getPlanSQL
public java.lang.String getPlanSQL()
Description copied from class:Index
Get the message to show in a EXPLAIN statement.- Overrides:
getPlanSQL
in classIndex
- Returns:
- the plan
-
close
public void close(SessionLocal session)
Description copied from class:Index
Close this index.
-
add
public void add(SessionLocal session, Row row)
Description copied from class:Index
Add a row to the index.
-
remove
public void remove(SessionLocal session, Row row)
Description copied from class:Index
Remove a row from the index.
-
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 classIndex
- Parameters:
session
- the sessionmasks
- per-column comparison bit masks, null means 'always false', see constants in IndexConditionfilters
- all joined table filtersfilter
- the current table filter indexsortOrder
- the sort orderallColumnsSet
- 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.
-
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 interfaceSpatialIndex
- Parameters:
session
- the sessionfirst
- the lower boundlast
- the upper boundintersection
- the geometry which values should intersect with, or null for anything- Returns:
- the cursor to iterate over the results
-
setupQueryParameters
public void setupQueryParameters(SessionLocal session, SearchRow first, SearchRow last, SearchRow intersection)
Set the query parameters.- Parameters:
session
- the sessionfirst
- the lower boundlast
- the upper boundintersection
- the intersection
-
find
private Cursor find(SessionLocal session, SearchRow first, SearchRow last, SearchRow intersection)
-
setParameter
private static void setParameter(java.util.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.
-
truncate
public void truncate(SessionLocal session)
Description copied from class:Index
Remove all rows from the index.
-
checkRename
public void checkRename()
Description copied from class:DbObject
Check if renaming is allowed. Does nothing when allowed.- Overrides:
checkRename
in classDbObject
-
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 classIndex
- 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 classIndex
- 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 classIndex
- Parameters:
session
- the session- Returns:
- the approximated row count
-
isRecursive
public boolean isRecursive()
-
-