Class IndexUtils


  • public class IndexUtils
    extends java.lang.Object
    This class provides a number of very useful utility operations that make it easier to create and work with indexes.
    • Constructor Summary

      Constructors 
      Constructor Description
      IndexUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static PageTuple findTupleInIndex​(Tuple key, TupleFile idxTupleFile)
      Given an index tuple-file and a search key, this method attempts to find the first tuple in the index that matches the search key.
      static Schema makeIndexSchema​(Schema tableSchema, ColumnRefs indexDesc)
      This method takes the schema of a table, and a description of an index, and it builds the schema that the index should have.
      static TupleLiteral makeTableSearchKey​(ColumnRefs columnRefs, Tuple tuple, boolean findExactTuple)
      This helper function creates a TupleLiteral that holds the key-values necessary for probing, storing or deleting a tuple in a table's index.
      static java.util.List<java.lang.String> verifyIndex​(TupleFile tableTupleFile, TupleFile indexTupleFile)
      This method performs a basic but important verification, that every tuple in a table is referenced once by the table's index, and no index entry has a tuple-reference to a non-existent tuple.
      • Methods inherited from class java.lang.Object

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

      • IndexUtils

        public IndexUtils()
    • Method Detail

      • makeIndexSchema

        public static Schema makeIndexSchema​(Schema tableSchema,
                                             ColumnRefs indexDesc)
        This method takes the schema of a table, and a description of an index, and it builds the schema that the index should have. This includes all of the columns referenced by the index in the order that the index references them, and it also includes a #TUPLE_PTR column so the index can reference columns in the table.
        Parameters:
        tableSchema - the schema of the table that the index is for
        indexDesc - a specification of the index
        Returns:
        the schema of the index
      • makeTableSearchKey

        public static TupleLiteral makeTableSearchKey​(ColumnRefs columnRefs,
                                                      Tuple tuple,
                                                      boolean findExactTuple)

        This helper function creates a TupleLiteral that holds the key-values necessary for probing, storing or deleting a tuple in a table's index. Note that this operation only works for a tuple that has the same schema as the index's owning table; it is not a general operation for creating search-keys on a particular index.

        This method can be used to find a specific tuple in a table by including a file-pointer to the tuple in the table. (For example, this is necessary when a tuple is being deleted from a table, so that the index can be updated to reflect the removal of that specific tuple.) This functionality requires that the tuple's class implement Tuple.getExternalReference().

        If this specific feature is not required, any kind of Tuple can be passed as an argument, as long as it has the same schema as the table that owns the index.

        Parameters:
        columnRefs - the columns that the index is built on
        tuple - the tuple from the original table, that the key will be created from.
        findExactTuple - if true, this method will include the tuple's file-pointer so that the exact tuple can be found in the index.
        Returns:
        a tuple-literal that can be used for storing, looking up, or deleting the specific tuple ptup.
      • findTupleInIndex

        public static PageTuple findTupleInIndex​(Tuple key,
                                                 TupleFile idxTupleFile)
        Given an index tuple-file and a search key, this method attempts to find the first tuple in the index that matches the search key.
        Parameters:
        key - the search-key value to probe the index with
        idxTupleFile - the index to probe with the search-key
        Returns:
        the first matching tuple in the index, or null if no matching tuple could be found
      • verifyIndex

        public static java.util.List<java.lang.String> verifyIndex​(TupleFile tableTupleFile,
                                                                   TupleFile indexTupleFile)
        This method performs a basic but important verification, that every tuple in a table is referenced once by the table's index, and no index entry has a tuple-reference to a non-existent tuple. This functionality is of course greatly supplemented by tuple-file formats that implement the TupleFile.verify() method, which does complete verification of the internal structure of a particular kind of tuple file.
        Parameters:
        tableTupleFile - the tuple file holding the table data
        indexTupleFile - the tuple file holding the index data
        Returns:
        A list of string error messages identified during the verification scan. This list will be empty if there are no errors.