Class TableDescriptor

  • All Implemented Interfaces:
    Dependable, Dependent, Provider

    public class TableDescriptor
    extends UniqueSQLObjectDescriptor
    implements Provider, Dependent
    This class represents a table descriptor. The external interface to this class is:

    1. external interface
    2. public String getSchemaName();
    3. public String getQualifiedName();
    4. public int getTableType();
    5. public long getHeapConglomerateId() throws StandardException;
    6. public int getNumberOfColumns();
    7. public FormatableBitSet getReferencedColumnMap();
    8. public void setReferencedColumnMap(FormatableBitSet referencedColumnMap);
    9. public int getMaxColumnID() throws StandardException;
    10. public void setUUID(UUID uuid);
    11. public char getLockGranularity();
    12. public void setTableName(String newTableName);
    13. public void setLockGranularity(char lockGranularity);
    14. public ExecRow getEmptyExecRow( ContextManager cm) throws StandardException;
    15. public boolean tableNameEquals(String otherSchemaName, String otherTableName);
    16. public ReferencedKeyConstraintDescriptor getPrimaryKey() throws StandardException;
    17. public void removeConglomerateDescriptor(ConglomerateDescriptor cd) throws StandardException;
    18. public void removeConstraintDescriptor(ConstraintDescriptor cd) throws StandardException;
    19. public void getAffectedIndexes(...) throws StandardException;
    20. public void getAllRelevantTriggers(...) throws StandardException;
    21. public void getAllRelevantConstraints(...) throws StandardException
    22. public ColumnDescriptorList getColumnDescriptorList();
    23. public String[] getColumnNamesArray();
    24. public long[] getAutoincIncrementArray();
    25. public ColumnDescriptor getColumnDescriptor(String columnName);
    26. public ColumnDescriptor getColumnDescriptor(int columnNumber);
    27. public ConglomerateDescriptor[] getConglomerateDescriptors() throws StandardException;
    28. public ConglomerateDescriptor getConglomerateDescriptor(long conglomerateNumber) throws StandardException;
    29. public ConglomerateDescriptor getConglomerateDescriptor(UUID conglomerateUUID) throws StandardException;
    30. public IndexLister getIndexLister() throws StandardException;
    31. public ViewDescriptor getViewDescriptor();
    32. public boolean tableHasAutoincrement();
    33. public boolean statisticsExist(ConglomerateDescriptor cd) throws StandardException;
    34. public double selectivityForConglomerate(...)throws StandardException;

    • Field Detail

      • GLOBAL_TEMPORARY_TABLE_TYPE

        public static final int GLOBAL_TEMPORARY_TABLE_TYPE
        See Also:
        Constant Field Values
      • TABLE_LOCK_GRANULARITY

        public static final char TABLE_LOCK_GRANULARITY
        See Also:
        Constant Field Values
      • DEFAULT_LOCK_GRANULARITY

        public static final char DEFAULT_LOCK_GRANULARITY
        See Also:
        Constant Field Values
      • ISTATS_CREATE_THRESHOLD

        public static final int ISTATS_CREATE_THRESHOLD
      • ISTATS_ABSDIFF_THRESHOLD

        public static final int ISTATS_ABSDIFF_THRESHOLD
      • ISTATS_LNDIFF_THRESHOLD

        public static final double ISTATS_LNDIFF_THRESHOLD
      • lockGranularity

        private char lockGranularity
      • onCommitDeleteRows

        private boolean onCommitDeleteRows
      • onRollbackDeleteRows

        private boolean onRollbackDeleteRows
      • indexStatsUpToDate

        private boolean indexStatsUpToDate
      • indexStatsUpdateReason

        private java.lang.String indexStatsUpdateReason
      • tableName

        java.lang.String tableName
      • tableType

        int tableType
      • heapConglomNumber

        private volatile long heapConglomNumber

        The id of the heap conglomerate for the table described by this instance. The value -1 means it's uninitialized, in which case it will be initialized lazily when getHeapConglomerateId() is called.

        It is declared volatile to ensure that concurrent callers of getHeapConglomerateId() while heapConglomNumber is uninitialized, will either see the value -1 or the fully initialized conglomerate number, and never see a partially initialized value (as was the case in DERBY-5358 because reads/writes of a long field are not guaranteed to be atomic unless the field is declared volatile).

      • statisticsDescriptorList

        private java.util.List<StatisticsDescriptor> statisticsDescriptorList
        A list of statistics pertaining to this table--
    • Constructor Detail

      • TableDescriptor

        public TableDescriptor​(DataDictionary dataDictionary,
                               java.lang.String tableName,
                               SchemaDescriptor schema,
                               int tableType,
                               boolean onCommitDeleteRows,
                               boolean onRollbackDeleteRows)
        Constructor for a TableDescriptor (this is for a temporary table).
        Parameters:
        dataDictionary - The data dictionary that this descriptor lives in
        tableName - The name of the temporary table
        schema - The schema descriptor for this table.
        tableType - An integer identifier for the type of the table : declared global temporary table
        onCommitDeleteRows - If true, on commit delete rows else on commit preserve rows of temporary table.
        onRollbackDeleteRows - If true, on rollback, delete rows from temp tables which were logically modified. true is the only supported value
      • TableDescriptor

        public TableDescriptor​(DataDictionary dataDictionary,
                               java.lang.String tableName,
                               SchemaDescriptor schema,
                               int tableType,
                               char lockGranularity)
        Constructor for a TableDescriptor.
        Parameters:
        dataDictionary - The data dictionary that this descriptor lives in
        tableName - The name of the table
        schema - The schema descriptor for this table.
        tableType - An integer identifier for the type of the table (base table, view, etc.)
        lockGranularity - The lock granularity.
    • Method Detail

      • referencedColumnMapPut

        private void referencedColumnMapPut​(FormatableBitSet newReferencedColumnMap)
      • getSchemaName

        public java.lang.String getSchemaName()
        Gets the name of the schema the table lives in.
        Returns:
        A String containing the name of the schema the table lives in.
      • getName

        public java.lang.String getName()
        Gets the name of the table.
        Specified by:
        getName in class UniqueSQLObjectDescriptor
        Returns:
        A String containing the name of the table.
      • setTableName

        public void setTableName​(java.lang.String newTableName)
        Sets the the table name in case of rename table. This is used only by rename table
        Parameters:
        newTableName - The new table name.
      • getQualifiedName

        public java.lang.String getQualifiedName()
        Gets the full, qualified name of the table.
        Returns:
        A String containing the name of the table.
      • getTableType

        public int getTableType()
        Gets an identifier telling what type of table this is (base table, declared global temporary table, view, etc.)
        Returns:
        An identifier telling what type of table this is.
      • getHeapConglomerateId

        public long getHeapConglomerateId()
                                   throws StandardException
        Gets the id for the heap conglomerate of the table. There may also be keyed conglomerates, these are stored separately in the conglomerates table.
        Returns:
        the id of the heap conglomerate for the table.
        Throws:
        StandardException - Thrown on error
      • getNumberOfColumns

        public int getNumberOfColumns()
        Gets the number of columns in the table.
        Returns:
        the number of columns in the table.
      • getReferencedColumnMap

        public FormatableBitSet getReferencedColumnMap()
        Get the referenced column map of the table.
        Returns:
        the referencedColumnMap of the table.
      • setReferencedColumnMap

        public void setReferencedColumnMap​(FormatableBitSet referencedColumnMap)
        Set the referenced column map of the table.
        Parameters:
        referencedColumnMap - FormatableBitSet of referenced columns.
      • makeColumnMap

        public FormatableBitSet makeColumnMap​(ColumnDescriptorList cdl)
        Given a list of columns in the table, construct a bit map of those columns' ids.
        Parameters:
        cdl - list of columns whose positions we want to record in the bit map
      • getMaxColumnID

        public int getMaxColumnID()
                           throws StandardException
        Gets the highest column id in the table. For now this is the same as the number of columns. However, in the future, after we implement ALTER TABLE DROP COLUMN, this correspondence won't hold any longer.
        Returns:
        the highest column ID in the table
        Throws:
        StandardException - Thrown on error
      • setUUID

        public void setUUID​(UUID oid)
        Sets the UUID of the table
        Parameters:
        oid - The UUID of the table to be set in the descriptor
      • getLockGranularity

        public char getLockGranularity()
        Gets the lock granularity for the table.
        Returns:
        A char representing the lock granularity for the table.
      • setLockGranularity

        public void setLockGranularity​(char lockGranularity)
        Sets the lock granularity for the table to the specified value.
        Parameters:
        lockGranularity - The new lockGranularity.
      • isOnRollbackDeleteRows

        public boolean isOnRollbackDeleteRows()
        Gets the on rollback behavior for the declared global temporary table.
        Returns:
        A boolean representing the on rollback behavior for the declared global temporary table.
      • isOnCommitDeleteRows

        public boolean isOnCommitDeleteRows()
        Gets the on commit behavior for the declared global temporary table.
        Returns:
        A boolean representing the on commit behavior for the declared global temporary table.
      • resetHeapConglomNumber

        public void resetHeapConglomNumber()
        Sets the heapConglomNumber to -1 for temporary table since the table was dropped and recreated at the commit time and hence its conglomerate id has changed. This is used for temporary table descriptors only
      • getColumnCollationIds

        public int[] getColumnCollationIds()
                                    throws StandardException
        Return an array of collation ids for this table.

        Return an array of collation ids, one for each column in the columnDescriptorList. This is useful for passing collation id info down to store, for instance in createConglomerate(). This is only expected to get called during ddl, so object allocation is ok.

        Throws:
        StandardException - Standard exception policy.
      • getConglomerateDescriptorList

        public ConglomerateDescriptorList getConglomerateDescriptorList()
        Gets the conglomerate descriptor list
        Returns:
        The conglomerate descriptor list for this table descriptor
      • getViewDescriptor

        public ViewDescriptor getViewDescriptor()
        Gets the view descriptor for this TableDescriptor.
        Returns:
        ViewDescriptor The ViewDescriptor, if any.
      • setViewDescriptor

        public void setViewDescriptor​(ViewDescriptor viewDescriptor)
        Set (cache) the view descriptor for this TableDescriptor
        Parameters:
        viewDescriptor - The view descriptor to cache.
      • isPersistent

        public boolean isPersistent()
        Is this provider persistent? A stored dependency will be required if both the dependent and provider are persistent.
        Specified by:
        isPersistent in interface Dependable
        Overrides:
        isPersistent in class TupleDescriptor
        Returns:
        boolean Whether or not this provider is persistent.
      • isSynonymDescriptor

        public boolean isSynonymDescriptor()
        Is this descriptor represents a synonym?
        Returns:
        boolean Whether or not this represents a synonym
      • getQualifiedNumberOfIndexes

        public int getQualifiedNumberOfIndexes​(int minColCount,
                                               boolean nonUniqeTrumpsColCount)
        Returns the number of indexes matching the criteria.
        Parameters:
        minColCount - the minimum number of ordered columns in the indexes we want to count
        nonUniqeTrumpsColCount - if true a non-unique index will be included in the count even if it has less than minColCount ordered columns
        Returns:
        Number of matching indexes.
        See Also:
        getTotalNumberOfIndexes()
      • getAllRelevantTriggers

        public void getAllRelevantTriggers​(int statementType,
                                           int[] changedColumnIds,
                                           TriggerDescriptorList relevantTriggers)
                                    throws StandardException
        Builds a list of all triggers which are relevant to a given statement type, given a list of updated columns.
        Parameters:
        statementType - defined in StatementType
        changedColumnIds - array of changed columns
        relevantTriggers - IN/OUT. Passed in as an empty list. Filled in as we go.
        Throws:
        StandardException - Thrown on error
      • getAllRelevantConstraints

        public void getAllRelevantConstraints​(int statementType,
                                              int[] changedColumnIds,
                                              boolean[] needsDeferredProcessing,
                                              ConstraintDescriptorList relevantConstraints)
                                       throws StandardException
        Gets all of the relevant constraints for a statement, given its statement type and its list of updated columns.
        Parameters:
        statementType - As defined in StatementType.
        changedColumnIds - If null, all columns being changed, otherwise array of 1-based column ids for columns being changed
        needsDeferredProcessing - IN/OUT. true if the statement already needs deferred processing. set while evaluating this routine if a trigger or constraint requires deferred processing
        relevantConstraints - IN/OUT. Empty list is passed in. We hang constraints on it as we go.
        Throws:
        StandardException - Thrown on error
      • getObjectName

        public java.lang.String getObjectName()
        Return the name of this Provider. (Useful for errors.)
        Specified by:
        getObjectName in interface Dependable
        Returns:
        String The name of this provider.
      • getObjectID

        public UUID getObjectID()
        Get the provider's UUID
        Specified by:
        getObjectID in interface Dependable
        Returns:
        String The provider's UUID
      • getClassType

        public java.lang.String getClassType()
        Get the provider's type.
        Specified by:
        getClassType in interface Dependable
        Returns:
        String The provider's type.
      • toString

        public java.lang.String toString()
        Prints the contents of the TableDescriptor
        Overrides:
        toString in class java.lang.Object
        Returns:
        The contents as a String
      • getColumnDescriptorList

        public ColumnDescriptorList getColumnDescriptorList()
        Gets the column descriptor list
        Returns:
        The column descriptor list for this table descriptor
      • getGeneratedColumns

        public ColumnDescriptorList getGeneratedColumns()
        Gets the list of columns defined by generation clauses.
      • getColumnIDs

        public int[] getColumnIDs​(java.lang.String[] names)
        Turn an array of column names into the corresponding 1-based column positions.
      • setConstraintDescriptorList

        public void setConstraintDescriptorList​(ConstraintDescriptorList newCDL)
        Sets the constraint descriptor list
        Parameters:
        newCDL - The new constraint descriptor list for this table descriptor
      • emptyConstraintDescriptorList

        public void emptyConstraintDescriptorList()
                                           throws StandardException
        Empty the constraint descriptor list
        Throws:
        StandardException - Thrown on failure
      • setTriggerDescriptorList

        public void setTriggerDescriptorList​(TriggerDescriptorList newCDL)
        Sets the trigger descriptor list
        Parameters:
        newCDL - The new trigger descriptor list for this table descriptor
      • emptyTriggerDescriptorList

        public void emptyTriggerDescriptorList()
                                        throws StandardException
        Empty the trigger descriptor list
        Throws:
        StandardException - Thrown on failure
      • tableNameEquals

        public boolean tableNameEquals​(java.lang.String otherTableName,
                                       java.lang.String otherSchemaName)
        Compare the tables descriptors based on the names. Null schema names match.
        Parameters:
        otherTableName - the other table name
        otherSchemaName - the other schema name
        Returns:
        boolean Whether or not the 2 TableNames are equal.
      • removeConstraintDescriptor

        public void removeConstraintDescriptor​(ConstraintDescriptor cd)
                                        throws StandardException
        Remove this descriptor. Warning, removes by using object reference, not uuid.
        Parameters:
        cd - constraint descriptor
        Throws:
        StandardException - on error
      • getColumnDescriptor

        public ColumnDescriptor getColumnDescriptor​(java.lang.String columnName)
        Get the descriptor for a column in the table, either by the column name or by its ordinal position (column number). Returns NULL for columns that do not exist.
        Parameters:
        columnName - A String containing the name of the column
        Returns:
        A ColumnDescriptor describing the column
      • getColumnDescriptor

        public ColumnDescriptor getColumnDescriptor​(int columnNumber)
        Parameters:
        columnNumber - The ordinal (1-based) position of the column in the table
        Returns:
        A ColumnDescriptor describing the column
      • getConglomerateDescriptors

        public ConglomerateDescriptor[] getConglomerateDescriptors()
        Gets a ConglomerateDescriptor[] to loop through all the conglomerate descriptors for the table.
        Returns:
        A ConglomerateDescriptor[] for looping through the table's conglomerates
      • getConglomerateDescriptor

        public ConglomerateDescriptor getConglomerateDescriptor​(long conglomerateNumber)
                                                         throws StandardException
        Gets a conglomerate descriptor for the given table and conglomerate number.
        Parameters:
        conglomerateNumber - The conglomerate number we're interested in
        Returns:
        A ConglomerateDescriptor describing the requested conglomerate. Returns NULL if no such conglomerate.
        Throws:
        StandardException - Thrown on failure
      • getConglomerateDescriptors

        public ConglomerateDescriptor[] getConglomerateDescriptors​(long conglomerateNumber)
                                                            throws StandardException
        Gets array of conglomerate descriptors for the given table and conglomerate number. More than one descriptors if duplicate indexes share one conglomerate.
        Parameters:
        conglomerateNumber - The conglomerate number we're interested in
        Returns:
        Array of ConglomerateDescriptors with the requested conglomerate number. Returns size 0 array if no such conglomerate.
        Throws:
        StandardException - Thrown on failure
      • getConglomerateDescriptor

        public ConglomerateDescriptor getConglomerateDescriptor​(UUID conglomerateUUID)
                                                         throws StandardException
        Gets a conglomerate descriptor for the given table and conglomerate UUID String.
        Parameters:
        conglomerateUUID - The UUID for the conglomerate we're interested in
        Returns:
        A ConglomerateDescriptor describing the requested conglomerate. Returns NULL if no such conglomerate.
        Throws:
        StandardException - Thrown on failure
      • getConglomerateDescriptors

        public ConglomerateDescriptor[] getConglomerateDescriptors​(UUID conglomerateUUID)
                                                            throws StandardException
        Gets array of conglomerate descriptors for the given table and conglomerate UUID. More than one descriptors if duplicate indexes share one conglomerate.
        Parameters:
        conglomerateUUID - The conglomerate UUID we're interested in
        Returns:
        Array of ConglomerateDescriptors with the requested conglomerate UUID. Returns size 0 array if no such conglomerate.
        Throws:
        StandardException - Thrown on failure
      • getIndexLister

        public IndexLister getIndexLister()
                                   throws StandardException
        Gets an object which lists out all the index row generators on a table together with their conglomerate ids.
        Returns:
        An object to list out the index row generators.
        Throws:
        StandardException - Thrown on failure
      • tableHasAutoincrement

        public boolean tableHasAutoincrement()
        Does the table have an auto-increment column or not?
        Returns:
        TRUE if the table has at least one auto-increment column, false otherwise
      • getColumnNamesArray

        public java.lang.String[] getColumnNamesArray()
        Gets an array of column names.
        Returns:
        An array, filled with the column names in the table.
      • getAutoincIncrementArray

        public long[] getAutoincIncrementArray()
        gets an array of increment values for autoincrement columns in the target table. If column is not an autoincrement column, then increment value is 0. If table has no autoincrement columns, returns NULL.
        Returns:
        array containing the increment values of autoincrement columns.
      • markForIndexStatsUpdate

        public void markForIndexStatsUpdate​(long tableRowCountEstimate)
                                     throws StandardException
        Marks the cardinality statistics for the indexes associated with this table for update if they are considered stale, or for creation if they don't exist, and if it is considered useful to update/create them.
        Parameters:
        tableRowCountEstimate - row count estimate for this table
        Throws:
        StandardException - if obtaining index statistics fails
      • getAndClearIndexStatsIsUpToDate

        public boolean getAndClearIndexStatsIsUpToDate()
        Tells if the index statistics for the indexes associated with this table are consideres up-to-date, and clears the state.
        Returns:
        true if the statistics are considered up-to-date, false if not.
      • getIndexStatsUpdateReason

        public java.lang.String getIndexStatsUpdateReason()
        Returns the update criteria telling why the statistics are considered stale.

        This method is used for debugging.

        Returns:
        A string describing the update criteria that were met.
      • statisticsExist

        public boolean statisticsExist​(ConglomerateDescriptor cd)
                                throws StandardException
        Are there statistics for this particular conglomerate.
        Parameters:
        cd - Conglomerate/Index for which we want to check if statistics exist. cd can be null in which case user wants to know if there are any statistics at all on the table.
        Throws:
        StandardException
      • selectivityForConglomerate

        public double selectivityForConglomerate​(ConglomerateDescriptor cd,
                                                 int numKeys)
                                          throws StandardException
        For this conglomerate (index), return the selectivity of the first numKeys. This basically returns the reciprocal of the number of unique values in the leading numKey columns of the index. It is assumed that statistics exist for the conglomerate if this function is called. However, no locks are held to prevent the statistics from being dropped, so the method also handles the case of missing statistics by using a heuristic to estimate the selectivity.
        Parameters:
        cd - ConglomerateDescriptor (Index) whose cardinality we are interested in.
        numKeys - Number of leading columns of the index for which cardinality is desired.
        Throws:
        StandardException
      • isValid

        public boolean isValid()
        Check that all of the dependent's dependencies are valid.
        Specified by:
        isValid in interface Dependent
        Returns:
        true if the dependent is currently valid
      • makeInvalid

        public void makeInvalid​(int action,
                                LanguageConnectionContext lcc)
                         throws StandardException
        Mark the dependent as invalid (due to at least one of its dependencies being invalid). Always an error for a table -- should never have gotten here.
        Specified by:
        makeInvalid in interface Dependent
        Parameters:
        action - The action causing the invalidation
        lcc - The LanguageConnectionContext
        Throws:
        StandardException - thrown if called in sanity mode
      • makeSequenceName

        public static java.lang.String makeSequenceName​(UUID tableID)
        Make the name of an identity sequence generator from a table ID
      • getContextOrNull

        private static Context getContextOrNull​(java.lang.String contextID)
        Privileged lookup of a Context. Must be private so that user code can't call this entry point.