Class BasicIndexManager

  • All Implemented Interfaces:
    IndexManager

    public class BasicIndexManager
    extends java.lang.Object
    implements IndexManager
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.apache.logging.log4j.Logger logger
      A logging object for reporting anything interesting that happens.
      private java.util.HashMap<java.lang.String,​IndexInfo> openIndexes  
      private StorageManager storageManager
      The index manager uses the storage manager a lot, so it caches a reference to the storage manager at initialization.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      IndexInfo addIndexToTable​(TableInfo tableInfo, IndexColumnRefs indexColRefs)  
      void analyzeIndex​(IndexInfo indexInfo)  
      void closeIndex​(IndexInfo indexInfo)  
      void createIndex​(IndexInfo indexInfo, java.lang.String indexName)
      Creates a new index file with the index name, table name, and column list specified in the passed-in IndexInfo object.
      void createUnnamedIndex​(IndexInfo indexInfo)  
      void dropIndex​(TableInfo tableInfo, java.lang.String indexName)  
      private java.lang.String getIndexFileName​(java.lang.String tableName, java.lang.String indexName)
      This method takes a table name and an index name, and returns a filename string that specifies where the index's data is stored.
      java.lang.String getUnnamedIndexPrefix​(IndexInfo indexInfo)
      This function generates the prefix of a name for an index with no actual name specified.
      boolean indexExists​(java.lang.String tableName, java.lang.String indexName)  
      void loadIndexInfo​(IndexInfo idxFileInfo)
      This method reads in the schema and other critical information for the specified table.
      IndexInfo openIndex​(TableInfo tableInfo, java.lang.String indexName)
      This method opens the data file corresponding to the specified index name and reads in the index's details.
      void optimizeIndex​(IndexInfo idxFileInfo)
      This method performs whatever optimization is suitable for the specific kind of index that is implemented.
      private void populateIndex​(TableInfo srcTableInfo, IndexInfo newIndexInfo)  
      void saveIndexInfo​(IndexInfo indexInfo)
      This method initializes a newly created index file, using the details specified in the passed-in IndexInfo object.
      java.util.List<java.lang.String> verifyIndex​(IndexInfo idxFileInfo)
      This function allows an index to be verified for proper structure and contents.
      • Methods inherited from class java.lang.Object

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

      • logger

        private static org.apache.logging.log4j.Logger logger
        A logging object for reporting anything interesting that happens.
      • storageManager

        private StorageManager storageManager
        The index manager uses the storage manager a lot, so it caches a reference to the storage manager at initialization.
      • openIndexes

        private java.util.HashMap<java.lang.String,​IndexInfo> openIndexes
    • Constructor Detail

      • BasicIndexManager

        public BasicIndexManager​(StorageManager storageManager)
        Initializes the heap-file table manager. This class shouldn't be initialized directly, since the storage manager will initialize it when necessary.
        Parameters:
        storageManager - the storage manager that is using this table manager
        Throws:
        java.lang.IllegalArgumentException - if storageManager is null
    • Method Detail

      • getIndexFileName

        private java.lang.String getIndexFileName​(java.lang.String tableName,
                                                  java.lang.String indexName)
        This method takes a table name and an index name, and returns a filename string that specifies where the index's data is stored.
        Parameters:
        tableName - the name of the table that the index is on
        indexName - the name of the index to get the filename of
        Returns:
        the name of the file that holds the index's data
      • indexExists

        public boolean indexExists​(java.lang.String tableName,
                                   java.lang.String indexName)
        Specified by:
        indexExists in interface IndexManager
      • populateIndex

        private void populateIndex​(TableInfo srcTableInfo,
                                   IndexInfo newIndexInfo)
      • createIndex

        public void createIndex​(IndexInfo indexInfo,
                                java.lang.String indexName)
        Creates a new index file with the index name, table name, and column list specified in the passed-in IndexInfo object. Additional details such as the data file and the index manager are stored into the passed-in IndexInfo object upon successful creation of the new index.
        Specified by:
        createIndex in interface IndexManager
        Parameters:
        indexInfo - This object is an in/out parameter. It is used to specify the name and details of the new index being created. When the index is successfully created, the object is updated with the actual file that the index is stored in.
        indexName - The name of the index created by the CREATE INDEX cmd. If there is no idxName, use the createUnnamedIndex method instead.
      • openIndex

        public IndexInfo openIndex​(TableInfo tableInfo,
                                   java.lang.String indexName)
        This method opens the data file corresponding to the specified index name and reads in the index's details. If the index is already open then the cached data is simply returned.
        Specified by:
        openIndex in interface IndexManager
        Parameters:
        tableInfo - the table that the index is defined on
        indexName - the name of the index to open. Indexes are not referenced directly except by CREATE/ALTER/DROP INDEX statements, so these index names are stored in the table schema files, and are generally opened when the optimizer needs to know what indexes are available.
        Returns:
        an object representing the details of the open index
      • getUnnamedIndexPrefix

        public java.lang.String getUnnamedIndexPrefix​(IndexInfo indexInfo)
        This function generates the prefix of a name for an index with no actual name specified. Since indexes and other constraints don't necessarily require names to be specified, we need some way to generate these names.
        Parameters:
        indexInfo - the information describing the index to be named
        Returns:
        a string containing a prefix to use for naming the index.
      • saveIndexInfo

        public void saveIndexInfo​(IndexInfo indexInfo)
        Description copied from interface: IndexManager
        This method initializes a newly created index file, using the details specified in the passed-in IndexInfo object.
        Specified by:
        saveIndexInfo in interface IndexManager
        Parameters:
        indexInfo - This object is an in/out parameter. It is used to specify the name and details of the new index being created. When the index is successfully created, the object is updated with the actual file that the index's data is stored in.
      • loadIndexInfo

        public void loadIndexInfo​(IndexInfo idxFileInfo)
        This method reads in the schema and other critical information for the specified table.
        Specified by:
        loadIndexInfo in interface IndexManager
        Parameters:
        idxFileInfo - the index information object to populate. When this is passed in, it only contains the index's name, the name of the table the index is specified on, and the opened database file to read the data from.
      • verifyIndex

        public java.util.List<java.lang.String> verifyIndex​(IndexInfo idxFileInfo)
        Description copied from interface: IndexManager
        This function allows an index to be verified for proper structure and contents.
        Specified by:
        verifyIndex in interface IndexManager
        Parameters:
        idxFileInfo - the index to verify
      • optimizeIndex

        public void optimizeIndex​(IndexInfo idxFileInfo)
        Description copied from interface: IndexManager
        This method performs whatever optimization is suitable for the specific kind of index that is implemented. For example, if the logical and physical ordering of pages is widely different, this method can resolve that kind of issue.
        Specified by:
        optimizeIndex in interface IndexManager
        Parameters:
        idxFileInfo - the index to optimize