Class GridH2Table

  • All Implemented Interfaces:
    org.h2.engine.DbObject, org.h2.schema.SchemaObject

    public class GridH2Table
    extends org.h2.table.TableBase
    H2 Table implementation.
    • Constructor Detail

      • GridH2Table

        public GridH2Table​(org.h2.command.ddl.CreateTableData createTblData,
                           GridH2RowDescriptor desc,
                           H2TableDescriptor tblDesc,
                           GridCacheContextInfo<?,​?> cacheInfo)
        Creates table.
        Parameters:
        createTblData - Table description.
        desc - Row descriptor.
        tblDesc - Indexes factory.
        cacheInfo - Cache context info.
    • Method Detail

      • addSystemIndex

        public void addSystemIndex​(org.h2.index.Index idx)
      • isPartitioned

        public boolean isPartitioned()
        Returns:
        true If this is a partitioned table.
      • getAffinityKeyColumn

        @Nullable
        public @Nullable org.h2.table.IndexColumn getAffinityKeyColumn()
        Returns:
        Affinity key column or null if not available.
      • getExplicitAffinityKeyColumn

        @Nullable
        public @Nullable org.h2.table.IndexColumn getExplicitAffinityKeyColumn()
        Returns:
        Explicit affinity key column or null if not available (skip _KEY column or it's alias).
      • isColumnForPartitionPruning

        public boolean isColumnForPartitionPruning​(org.h2.table.Column col)
        Check whether passed column can be used for partition pruning.
        Parameters:
        col - Column.
        Returns:
        True if affinity key column.
      • isColumnForPartitionPruningStrict

        public boolean isColumnForPartitionPruningStrict​(org.h2.table.Column col)
        Check whether passed column could be used for partition transfer during partition pruning on joined tables and for external affinity calculation (e.g. on thin clients).

        Note that it is different from isColumnForPartitionPruning(Column) method in that not every column which qualifies for partition pruning can be used by thin clients or join partition pruning logic.

        Consider the following schema:

         CREATE TABLE dept (id PRIMARY KEY);
         CREATE TABLE emp (id, dept_id AFFINITY KEY, PRIMARY KEY(id, dept_id));
         
        For expression-based partition pruning on "emp" table on the server side we may use both "_KEY" and "dept_id" columns, as passing them through standard affinity workflow will yield the same result: dept_id -> part _KEY -> dept_id -> part

        But we cannot use "_KEY" on thin client side, as it doesn't know how to extract affinity key field properly. Neither we can perform partition transfer in JOINs when "_KEY" is used.

        This is OK as data is collocated, so we can merge partitions extracted from both tables:

         SELECT * FROM dept d INNER JOIN emp e ON d.id = e.dept_id WHERE e.dept_id=? AND d.id=?
         
        But this is not OK as joined data is not collocated, and tables form distinct collocation groups:
         SELECT * FROM dept d INNER JOIN emp e ON d.id = e._KEY WHERE e.dept_id=? AND d.id=?
         
        NB: The last query is not logically correct and will produce empty result. However, it is correct from SQL perspective, so we should make incorrect assumptions about partitions as it may make situation even worse.
        Parameters:
        col - Column.
        Returns:
        True if column could be used for partition extraction on both server and client sides and for partition transfer in joins.
      • isCustomAffinityMapper

        public boolean isCustomAffinityMapper()
        Returns:
        Whether custom affintiy mapper is used.
      • getDiskSpaceUsed

        public long getDiskSpaceUsed()
        Specified by:
        getDiskSpaceUsed in class org.h2.table.Table
      • tableDescriptor

        public H2TableDescriptor tableDescriptor()
        Returns:
        Table descriptor.
      • cacheName

        public String cacheName()
        Returns:
        Cache name.
      • cacheId

        public int cacheId()
        Returns:
        Cache ID.
      • tableStatistics

        public ObjectStatistics tableStatistics()
        Get actual table statistics if exists.
        Returns:
        Table statistics or null if there is no statistics available.
      • cacheContext

        @Nullable
        public @Nullable GridCacheContext cacheContext()
        Returns:
        Cache context.
      • lock

        public boolean lock​(org.h2.engine.Session ses,
                            boolean exclusive,
                            boolean force)
        Specified by:
        lock in class org.h2.table.Table
      • unlock

        public void unlock​(org.h2.engine.Session ses)
        Specified by:
        unlock in class org.h2.table.Table
      • identifier

        public QueryTable identifier()
        Returns:
        Table identifier.
      • identifierString

        public String identifierString()
        Returns:
        Table identifier as string.
      • close

        public void close​(org.h2.engine.Session ses)
        Specified by:
        close in class org.h2.table.Table
      • removeChildrenAndResources

        public void removeChildrenAndResources​(org.h2.engine.Session ses)
        Specified by:
        removeChildrenAndResources in interface org.h2.engine.DbObject
        Overrides:
        removeChildrenAndResources in class org.h2.table.Table
      • destroy

        public void destroy()
        Destroy the table.
      • update

        public void update​(CacheDataRow row,
                           @Nullable
                           @Nullable CacheDataRow prevRow)
        Updates table for given key. If value is null then row with given key will be removed from table, otherwise value and expiration time will be updated or new row will be added.
        Parameters:
        row - Row to be updated.
        prevRow - Previous row.
        Throws:
        IgniteCheckedException - If failed.
      • remove

        public void remove​(CacheDataRow row)
        Remove row.
        Parameters:
        row - Row.
      • markRebuildFromHashInProgress

        public void markRebuildFromHashInProgress​(boolean value)
        Mark or unmark index rebuild state.
      • rebuildFromHashInProgress

        public boolean rebuildFromHashInProgress()
      • addIndex

        public org.h2.index.Index addIndex​(org.h2.engine.Session ses,
                                           String idxName,
                                           int idxId,
                                           org.h2.table.IndexColumn[] cols,
                                           org.h2.index.IndexType idxType,
                                           boolean create,
                                           String idxComment)
        Specified by:
        addIndex in class org.h2.table.Table
      • proposeUserIndex

        public void proposeUserIndex​(org.h2.index.Index idx)
                              throws IgniteCheckedException
        Add index that is in an intermediate state and is still being built, thus is not used in queries until it is promoted.
        Parameters:
        idx - Index to add.
        Throws:
        IgniteCheckedException - If failed.
      • rollbackUserIndex

        public void rollbackUserIndex​(String idxName)
        Remove user index without promoting it.
        Parameters:
        idxName - Index name.
      • removeIndex

        public void removeIndex​(org.h2.index.Index h2Idx)
        Overrides:
        removeIndex in class org.h2.table.Table
      • removeRow

        public void removeRow​(org.h2.engine.Session ses,
                              org.h2.result.Row row)
        Specified by:
        removeRow in class org.h2.table.Table
      • truncate

        public void truncate​(org.h2.engine.Session ses)
        Specified by:
        truncate in class org.h2.table.Table
      • addRow

        public void addRow​(org.h2.engine.Session ses,
                           org.h2.result.Row row)
        Specified by:
        addRow in class org.h2.table.Table
      • checkSupportAlter

        public void checkSupportAlter()
        Specified by:
        checkSupportAlter in class org.h2.table.Table
      • getTableType

        public org.h2.table.TableType getTableType()
        Specified by:
        getTableType in class org.h2.table.Table
      • getScanIndex

        public org.h2.index.Index getScanIndex​(org.h2.engine.Session ses)
        Specified by:
        getScanIndex in class org.h2.table.Table
      • getUniqueIndex

        public org.h2.index.Index getUniqueIndex()
        Specified by:
        getUniqueIndex in class org.h2.table.Table
      • getIndexes

        public ArrayList<org.h2.index.Index> getIndexes()
        Specified by:
        getIndexes in class org.h2.table.Table
      • isLockedExclusively

        public boolean isLockedExclusively()
        Specified by:
        isLockedExclusively in class org.h2.table.Table
      • isLockedExclusivelyBy

        public boolean isLockedExclusivelyBy​(org.h2.engine.Session ses)
        Overrides:
        isLockedExclusivelyBy in class org.h2.table.Table
      • getMaxDataModificationId

        public long getMaxDataModificationId()
        Specified by:
        getMaxDataModificationId in class org.h2.table.Table
      • isDeterministic

        public boolean isDeterministic()
        Specified by:
        isDeterministic in class org.h2.table.Table
      • canGetRowCount

        public boolean canGetRowCount()
        Specified by:
        canGetRowCount in class org.h2.table.Table
      • canDrop

        public boolean canDrop()
        Specified by:
        canDrop in class org.h2.table.Table
      • getRowCount

        public long getRowCount​(@Nullable
                                @Nullable org.h2.engine.Session ses)
        Specified by:
        getRowCount in class org.h2.table.Table
      • getRowCountApproximation

        public long getRowCountApproximation()
        Specified by:
        getRowCountApproximation in class org.h2.table.Table
      • checkRename

        public void checkRename()
        Specified by:
        checkRename in interface org.h2.engine.DbObject
        Specified by:
        checkRename in class org.h2.engine.DbObjectBase
      • indexColumn

        public org.h2.table.IndexColumn indexColumn​(int col,
                                                    int sorting)
        Creates index column for table.
        Parameters:
        col - Column index.
        sorting - Sorting order SortOrder
        Returns:
        Created index column.
      • addColumns

        public void addColumns​(List<QueryField> cols)
        Add new columns to this table.
        Parameters:
        cols - Columns to add.
      • dropColumns

        public void dropColumns​(List<String> cols)
        Drop columns.
        Parameters:
        cols - Columns.
      • setColumns

        protected void setColumns​(org.h2.table.Column[] columns)
        Overrides:
        setColumns in class org.h2.table.Table
      • getColumns

        public org.h2.table.Column[] getColumns()
        Overrides:
        getColumns in class org.h2.table.Table
      • insertHack

        public static void insertHack​(boolean val)
        Set insert hack flag.
        Parameters:
        val - Value.
      • insertHackRequired

        public static boolean insertHackRequired​(String sql)
        Check whether insert hack is required. This is true in case statement contains "INSERT INTO ... VALUES".
        Parameters:
        sql - SQL statement.
        Returns:
        True if target combination is found.
      • unlockTables

        public static void unlockTables​(org.h2.engine.Session s)
        Parameters:
        s - H2 session.
      • readLockTables

        public static void readLockTables​(org.h2.engine.Session s)
        Parameters:
        s - H2 session.
      • checkTablesVersions

        public static void checkTablesVersions​(org.h2.engine.Session s)
        Parameters:
        s - H2 session.